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

http://github.com/tybor/Liberty · Specman e · 149 lines · 69 code · 22 blank · 58 comment · 0 complexity · ab2bb4c873c82546460b1c0309eb8561 MD5 · raw file

  1. deferred class LLVM_TYPE
  2. -- Type is a superclass of all type classes.
  3. -- Every Value has a Type. Type cannot be
  4. -- instantiated directly but only through its
  5. -- subclasses. Certain primitive types
  6. -- (VoidType, LabelType, FloatType and
  7. -- DoubleType) have hidden subclasses. They are
  8. -- hidden because they offer no useful
  9. -- functionality beyond what the Type class
  10. -- offers except to distinguish themselves from
  11. -- other subclasses of Type.
  12. -- All other types are subclasses of
  13. -- DerivedType. Types can be named, but this is
  14. -- not a requirement. There exists exactly one
  15. -- instance of a given shape at any one time.
  16. -- This allows type equality to be performed
  17. -- with address equality of the Type Instance.
  18. -- That is, given two Type* values, the types
  19. -- are identical if the pointers are identical.
  20. -- The representation of the base type of all datatypes in LLVM. Anchestor
  21. -- of all hierarchy of types. See
  22. -- http://llvm.org/doxygen/classllvm_1_1Type.html for a clean graph of its
  23. -- heirs.
  24. -- TODO: when implementing `refine' remember to redefine it in LLVM_STRUCT_TYPE to take in count about cyclic type
  25. inherit
  26. C_STRUCT
  27. C_OWNED
  28. insert CORE_EXTERNALS
  29. feature {ANY} -- Queries
  30. type_kind: LLVMTYPE_KIND_ENUM
  31. -- The actual type of Current
  32. do
  33. Result.change_value (llvmget_type_kind(handle))
  34. end
  35. -- TODO: C binding offers a call "LLVMTypeRef
  36. -- LLVMGetElementType(LLVMTypeRef Ty);"; provide a meaningful Eiffel
  37. -- equivalent.
  38. context: LLVM_CONTEXT
  39. do
  40. create Result.from_external_pointer(llvmget_type_context(handle))
  41. end
  42. struct_size: like size_t
  43. -- LLVM_TYPE actually wraps a polymorphic C++ class; temporarly this query always fails.
  44. require implemented: False
  45. do
  46. not_yet_implemented -- or mostly unuseful
  47. end
  48. is_boolean: BOOLEAN
  49. -- Is Current a one-bit integer?
  50. do
  51. Result := is_integer and then as_integer.width=1.to_natural_32
  52. end
  53. is_integer: BOOLEAN
  54. -- Is Current an integer type?
  55. do
  56. Result := type_kind.is_integer_type_kind
  57. end
  58. is_floating_point: BOOLEAN
  59. -- Is Current a floating point type?
  60. do
  61. Result := type_kind.is_double_type_kind or else
  62. type_kind.is_x86_fp80type_kind or else
  63. type_kind.is_fp128type_kind or else
  64. type_kind.is_ppc_fp128type_kind
  65. end
  66. is_vector: BOOLEAN
  67. -- Is Current a vector?
  68. do
  69. Result := type_kind.is_vector_type_kind
  70. end
  71. is_pointer: BOOLEAN
  72. -- Is Current a pointer?
  73. do
  74. Result := type_kind.is_pointer_type_kind
  75. end
  76. is_struct: BOOLEAN
  77. -- Is Current a struct type?
  78. do
  79. Result := type_kind.is_struct_type_kind
  80. end
  81. is_array: BOOLEAN
  82. -- Is Current an array type?
  83. do
  84. Result := type_kind.is_array_type_kind
  85. end
  86. -- is_abstract: BOOLEAN is -- is Current abstract, i.e. does it contain opaque type anywhere in its definition.
  87. -- is_sized: BOOLEAN is -- Has the type a known size? Things that don't have a size are abstract types, labels and void.
  88. feature {ANY}
  89. as_integer: LLVM_INTEGER_TYPE
  90. -- Downcasting to integer type
  91. require is_integer
  92. do
  93. -- Forced assignment is allowed because of the precondition.
  94. Result ::= Current
  95. ensure Result/=Void
  96. end
  97. as_struct: LLVM_STRUCT_TYPE
  98. -- Downcasting to struct type
  99. require is_struct
  100. do
  101. -- Safe forced assignment because of the precondition
  102. Result ::= Current
  103. end
  104. as_vector: LLVM_VECTOR_TYPE
  105. -- Downcasting to integer type
  106. require is_vector
  107. do
  108. -- Forced assignment is safe because of the precondition.
  109. Result::=Current
  110. ensure Result/=Void
  111. end
  112. end -- class LLVM_TYPE
  113. -- Copyright (C) 2009-2017: Paolo Redaelli
  114. -- This file is part of LLVM wrappers for Liberty Eiffel.
  115. --
  116. -- This library is free software: you can redistribute it and/or modify
  117. -- it under the terms of the GNU Lesser General Public License as published by
  118. -- the Free Software Foundation, version 3 of the License.
  119. --
  120. -- Liberty Eiffel is distributed in the hope that it will be useful,
  121. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  122. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  123. -- GNU General Public License for more details.
  124. --
  125. -- You should have received a copy of the GNU General Public License
  126. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  127. --