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

http://github.com/tybor/Liberty · Specman e · 143 lines · 80 code · 15 blank · 48 comment · 2 complexity · f9ad564bc293234ab78d6dd047c05060 MD5 · raw file

  1. class LLVM_BASIC_BLOCK
  2. -- LLVM Basic Block Representation.
  3. -- This represents a single basic block in LLVM. A basic
  4. -- block is simply a container of instructions that
  5. -- execute sequentially. Basic blocks are Values because
  6. -- they are referenced by instructions such as branches
  7. -- and switch tables.
  8. -- The type of a BasicBlock is "Type::LabelTy" because
  9. -- the basic block represents a label to which a branch
  10. -- can jump.
  11. -- well formed basic block is formed of a list of
  12. -- non-terminating instructions followed by a single
  13. -- TerminatorInst instruction. TerminatorInst's may not
  14. -- occur in the middle of basic blocks, and must
  15. -- terminate the blocks. The BasicBlock class allows
  16. -- malformed basic blocks to occur because it may be
  17. -- useful in the intermediate stage of constructing or
  18. -- modifying a program. However, the verifier will ensure
  19. -- that basic blocks are "well formed".
  20. inherit LLVM_VALUE
  21. insert LLVM_VALUE_WRAPPER_FACTORY
  22. create {WRAPPER, WRAPPER_HANDLER} from_external_pointer
  23. create {ANY} appended_in_context, inserted_in_context, appended_to, inserted_before
  24. feature {} -- Creation
  25. appended_in_context (a_context: LLVM_CONTEXT; a_function: LLVM_FUNCTION; a_name: ABSTRACT_STRING)
  26. -- TODO: documentation
  27. -- TODO: `a_function' may be an more general LLVM_VALUE but any actual
  28. -- usage of something other that an LLVM_FUNCTION is not clear to me.
  29. require
  30. a_context/=Void
  31. a_function/=Void
  32. a_name/=Void
  33. do
  34. handle:=llvmappend_basic_block_in_context
  35. (a_context.handle, a_function.handle, a_name.to_external)
  36. ensure name_not_changed: a_name.is_equal(old a_name)
  37. end
  38. inserted_in_context (a_context: LLVM_CONTEXT; a_block: LLVM_BASIC_BLOCK; a_name: ABSTRACT_STRING)
  39. -- TODO: doc.
  40. require
  41. a_context/=Void
  42. a_block/=Void
  43. a_name/=Void
  44. do
  45. handle:=llvminsert_basic_block_in_context
  46. (a_context.handle, a_block.handle, a_name.to_external)
  47. ensure name_not_changed: a_name.is_equal(old a_name)
  48. end
  49. appended_to (a_value: LLVM_VALUE; a_name: ABSTRACT_STRING)
  50. -- TODO: doc
  51. require
  52. a_value/=Void
  53. a_name/=Void
  54. do
  55. handle:=llvmappend_basic_block(a_value.handle,a_name.to_external)
  56. ensure name_not_changed: a_name.is_equal(old a_name)
  57. end
  58. inserted_before (a_block: LLVM_BASIC_BLOCK; a_name: ABSTRACT_STRING)
  59. -- TODO: doc
  60. require
  61. a_block/=Void
  62. a_name/=Void
  63. do
  64. handle:=llvminsert_basic_block(a_block.handle,a_name.to_external)
  65. ensure name_not_changed: a_name.is_equal(old a_name)
  66. end
  67. feature {ANY} -- queries
  68. -- TODO: the following feature may not be necessary "as_value: LLVM_VALUE
  69. -- is -- Current basic block as a value do LLVMValueRef
  70. -- LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);:w" and
  71. parent: LLVM_VALUE
  72. --- The value that contains Current block
  73. do
  74. Result:=value_wrapper_or_void(llvmget_basic_block_parent(handle))
  75. end
  76. next: LLVM_BASIC_BLOCK
  77. -- The block after Current. May be Void
  78. local p: POINTER
  79. do
  80. p:=llvmget_next_basic_block(handle)
  81. if p.is_not_null then
  82. create Result.from_external_pointer(p)
  83. end
  84. end
  85. previous: LLVM_BASIC_BLOCK
  86. -- The block before Current. May be Void
  87. local p: POINTER
  88. do
  89. p:= llvmget_previous_basic_block(handle)
  90. if p.is_not_null then
  91. create Result.from_external_pointer(p)
  92. end
  93. end
  94. delete
  95. -- Delete current block.
  96. do
  97. llvmdelete_basic_block(handle)
  98. handle := default_pointer
  99. ensure is_deleted
  100. end
  101. is_deleted: BOOLEAN
  102. -- Has Current been deleted?
  103. do
  104. Result:=handle.is_null
  105. end
  106. -- void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
  107. feature {ANY} -- Iterating over instructions
  108. new_iterator: ITERATOR[LLVM_INSTRUCTION]
  109. do
  110. create {ITERATOR_OVER_INSTRUCTIONS} Result.from_block(Current)
  111. ensure Result/=Void
  112. end
  113. end -- class LLVM_BASIC_BLOCK
  114. -- Copyright (C) 2009-2017: Paolo Redaelli, partially derived from LLVM documentation
  115. -- This file is part of LLVM wrappers for Liberty Eiffel.
  116. --
  117. -- This library is free software: you can redistribute it and/or modify
  118. -- it under the terms of the GNU Lesser General Public License as published by
  119. -- the Free Software Foundation, version 3 of the License.
  120. --
  121. -- Liberty Eiffel is distributed in the hope that it will be useful,
  122. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  123. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  124. -- GNU General Public License for more details.
  125. --
  126. -- You should have received a copy of the GNU General Public License
  127. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  128. --