/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

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