PageRenderTime 13ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/llvm/library/values/llvm_global_value.e

http://github.com/tybor/Liberty
Specman e | 204 lines | 125 code | 31 blank | 48 comment | 0 complexity | de7eb26b7b454c7e08affc8774dd4c84 MD5 | raw file
  1deferred class LLVM_GLOBAL_VALUE
  2-- Global values (GlobalVariables or Functions) are the only LLVM
  3-- values that are visible in the bodies of all Functions.
  4-- Because they are visible at global scope, they are also
  5-- subject to linking with other globals defined in different
  6-- translation units. To control the linking process,
  7-- GlobalValues know their linkage rules. Specifically,
  8-- GlobalValues know whether they have internal or external
  9-- linkage, as defined by the LinkageTypes enumeration.
 10
 11-- If a GlobalValue has internal linkage (equivalent to being
 12-- static in C), it is not visible to code outside the current
 13-- translation unit, and does not participate in linking. If it
 14-- has external linkage, it is visible to external code, and does
 15-- participate in linking. In addition to linkage information,
 16-- GlobalValues keep track of which Module they are currently
 17-- part of.
 18
 19-- Because GlobalValues are memory objects, they are always
 20-- referred to by their address. As such, the Type of a global is
 21-- always a pointer to its contents. It is important to remember
 22-- this when using the GetElementPtrInst instruction because this
 23-- pointer must be dereferenced first. For example, if you have a
 24-- GlobalVariable (a subclass of GlobalValue) that is an array of
 25-- 24 ints, type [24 x i32], then the GlobalVariable is a pointer
 26-- to that array. Although the address of the first element of
 27-- this array and the value of the GlobalVariable are the same,
 28-- they have different types. The GlobalVariable's type is [24 x
 29-- i32]. The first element's type is i32. Because of this,
 30-- accessing a global value requires you to dereference the
 31-- pointer with GetElementPtrInst first, then its elements can be
 32-- accessed. This is explained in the LLVM Language Reference
 33-- Manual.
 34
 35inherit LLVM_CONSTANT
 36feature {ANY} -- Queries
 37   parent: LLVM_MODULE
 38      do
 39create Result.from_external_pointer(llvmget_global_parent(handle))
 40      ensure Result/=Void
 41      end
 42
 43   is_declaration: BOOLEAN
 44      do
 45         Result:=llvmis_declaration(handle).to_boolean
 46      end
 47
 48   section: FIXED_STRING
 49         -- TODO: should be created with from_external
 50      do
 51create Result.from_external_copy(llvmget_section(handle))
 52      ensure Result/=Void
 53      end
 54
 55
 56   visibility: LLVMVISIBILITY_ENUM
 57      do
 58         Result.change_value(llvmget_visibility(handle))
 59      end
 60
 61
 62   alignment: NATURAL_32
 63      do
 64         Result:=llvmget_alignment(handle)
 65      end
 66
 67   linkage: LLVMLINKAGE_ENUM
 68      do
 69         Result.change_value
 70         (llvmget_linkage(handle))
 71      end
 72
 73feature {ANY} -- Commands
 74   set_section (a_section: ABSTRACT_STRING)
 75         --
 76      require
 77         non_void: a_section/=Void
 78         non_empty: not a_section.is_empty
 79      do
 80         llvmset_section(handle,a_section.to_external)
 81      ensure set: a_section.is_equal(section)
 82      end
 83
 84   set_visibility (a_visibility: LLVMVISIBILITY_ENUM)
 85      do
 86         llvmset_visibility(handle,a_visibility.value)
 87      ensure set: visibility=a_visibility
 88      end
 89
 90   set_alignment (a_number_of_bytes: NATURAL_32)
 91      do
 92         llvmset_alignment(handle, a_number_of_bytes)
 93      end
 94
 95feature {ANY} -- Linkage commands
 96   set_linkage (a_value: LLVMLINKAGE_ENUM)
 97         --
 98      do
 99         llvmset_linkage(handle,a_value.value)
100      ensure set: linkage=a_value
101      end
102
103   set_external_linkage
104      local l: like linkage
105      do
106         llvmset_linkage(handle,l.external_linkage_low_level)
107      end
108
109   set_link_once_any_linkage
110      local l: like linkage
111      do
112         llvmset_linkage(handle,l.link_once_any_linkage_low_level)
113      end
114
115   set_link_once_odrlinkage
116      local l: like linkage
117      do
118         llvmset_linkage(handle,l.link_once_odrlinkage_low_level)
119      end
120
121   set_weak_any_linkage
122      local l: like linkage
123      do
124         llvmset_linkage(handle,l.weak_any_linkage_low_level)
125      end
126
127   set_weak_odrlinkage
128      local l: like linkage
129      do
130         llvmset_linkage(handle,l.weak_odrlinkage_low_level)
131      end
132
133   set_appending_linkage
134      local l: like linkage
135      do
136         llvmset_linkage(handle,l.appending_linkage_low_level)
137      end
138
139   set_internal_linkage
140      local l: like linkage
141      do
142         llvmset_linkage(handle,l.internal_linkage_low_level)
143      end
144
145   set_private_linkage
146      local l: like linkage
147      do
148         llvmset_linkage(handle,l.private_linkage_low_level)
149      end
150
151   set_dllimport_linkage
152      local l: like linkage
153      do
154         llvmset_linkage(handle,l.dllimport_linkage_low_level)
155      end
156
157   set_dllexport_linkage
158      local l: like linkage
159      do
160         llvmset_linkage(handle,l.dllexport_linkage_low_level)
161      end
162
163   set_external_weak_linkage
164      local l: like linkage
165      do
166         llvmset_linkage(handle,l.external_weak_linkage_low_level)
167      end
168
169   set_ghost_linkage
170      local l: like linkage
171      do
172         llvmset_linkage(handle,l.ghost_linkage_low_level)
173      end
174
175   set_common_linkage
176      local l: like linkage
177      do
178         llvmset_linkage(handle,l.common_linkage_low_level)
179      end
180
181   set_linker_private_linkage
182      local l: like linkage
183      do
184         llvmset_linkage(handle,l.linker_private_linkage_low_level)
185      end
186
187end -- class LLVM_GLOBAL_VALUE
188
189-- Copyright (C) 2009-2017: Paolo Redaelli
190
191-- This file is part of LLVM wrappers for Liberty Eiffel.
192--
193-- This library is free software: you can redistribute it and/or modify
194-- it under the terms of the GNU Lesser General Public License as published by
195-- the Free Software Foundation, version 3 of the License.
196--
197-- Liberty Eiffel is distributed in the hope that it will be useful,
198-- but WITHOUT ANY WARRANTY; without even the implied warranty of
199-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
200-- GNU General Public License for more details.
201--
202-- You should have received a copy of the GNU General Public License
203-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
204--