/src/wrappers/llvm/library/types/llvm_struct_type.e

http://github.com/tybor/Liberty · Specman e · 93 lines · 52 code · 12 blank · 29 comment · 0 complexity · 55827509519628653b605278437f28ad MD5 · raw file

  1. class LLVM_STRUCT_TYPE
  2. -- A type representing a structure in LLVM.
  3. -- It is also a COLLECTION of LLVM_TYPEs, the types of its fields.
  4. inherit
  5. LLVM_COMPOSITE_TYPE
  6. --undefine fill_tagged_out_memory
  7. redefine copy end
  8. LLVM_TYPE_FACTORY
  9. -- TODO: evolve the primitive array-like features into a proper heir of C_ARRAY[LLVM_TYPE]
  10. -- undefine is_equal -- use is_equal from LLVM_TYPE
  11. -- redefine copy
  12. -- end
  13. ARRAYED_COLLECTION_HANDLER
  14. create {ANY} make, in_context, from_external_pointer
  15. feature {ANY} -- Creation
  16. make (some_elements: COLLECTION[LLVM_TYPE]; packed: BOOLEAN)
  17. require
  18. some_elements/=Void
  19. not some_elements.is_empty
  20. do
  21. handle := llvmstruct_type(collection_to_c_array(some_elements).storage.to_external, some_elements.count.to_natural_32, packed.to_integer)
  22. refresh_storage
  23. end
  24. in_context (a_context: LLVM_CONTEXT; some_elements: COLLECTION[LLVM_TYPE]; packed: BOOLEAN)
  25. require
  26. a_context/=Void
  27. some_elements/=Void
  28. not some_elements.is_empty
  29. do
  30. handle := llvmstruct_type_in_context(a_context.handle, collection_to_c_array(some_elements).storage.to_external, some_elements.count.to_natural_32, packed.to_integer)
  31. refresh_storage
  32. end
  33. copy (another: like Current)
  34. do
  35. handle:=another.handle
  36. refresh_storage
  37. end
  38. feature {ANY} -- Packing
  39. is_packed: BOOLEAN
  40. do
  41. Result:=llvmis_packed_struct(handle).to_boolean
  42. end
  43. feature {ANY} -- Element access
  44. elements_count: INTEGER_32
  45. element (an_index: INTEGER_32): LLVM_TYPE
  46. require valid_index: an_index.in_range(0,elements_count-1)
  47. do
  48. Result:=type_wrapper(storage.item(an_index))
  49. end
  50. feature {} -- Implementation
  51. storage: NATIVE_ARRAY[POINTER]
  52. -- The addresses of Current's elements
  53. refresh_storage
  54. -- Initialize `storage' with the field types of the structure
  55. do
  56. elements_count := llvmcount_struct_element_types(handle).to_integer_32
  57. storage := storage.calloc(elements_count)
  58. llvmget_struct_element_types(handle, storage.to_pointer)
  59. end
  60. -- An LLVMStruct will (mostly) not change its elements, allowing to cache
  61. -- the result of an llvmget_struct_element_types. Types are generally
  62. -- immutable, the one exception is when type refinement happens Check out
  63. -- LLVM's ProgrammersManual in the cyclic types section. refine type
  64. -- feature shalle be redefined.
  65. invariant type_kind.is_struct_type_kind
  66. end -- class LLVM_STRUCT_TYPE
  67. -- Copyright (C) 2009-2017: Paolo Redaelli
  68. -- This file is part of LLVM wrappers for Liberty Eiffel.
  69. --
  70. -- This library is free software: you can redistribute it and/or modify
  71. -- it under the terms of the GNU Lesser General Public License as published by
  72. -- the Free Software Foundation, version 3 of the License.
  73. --
  74. -- Liberty Eiffel is distributed in the hope that it will be useful,
  75. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  76. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  77. -- GNU General Public License for more details.
  78. --
  79. -- You should have received a copy of the GNU General Public License
  80. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  81. --