Class: LLVM::Type
- Inherits:
-
Object
- Object
- LLVM::Type
- Includes:
- PointerIdentity
- Defined in:
- lib/llvm/core/type.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns a symbol representation of the types kind (ex. :pointer, :vector, :array.).
Class Method Summary collapse
-
.array(ty, sz = 0) ⇒ Object
Creates an array type of Type with the given size.
- .double ⇒ Object
- .float ⇒ Object
- .from_ptr(ptr, kind = nil) ⇒ Object
-
.function(arg_types, result_type, options = {}) ⇒ Object
Creates a function type.
-
.integer(width) ⇒ Object
(also: i)
def self.rec h = opaque ty = yield h h.refine(ty) ty end.
- .label ⇒ Object
- .named(name) ⇒ Object
- .opaque_struct(name) ⇒ Object
-
.pointer(ty = nil, address_space = 0) ⇒ Object
Creates the pointer type of Type with the given address space.
-
.ptr(address_space = 0) ⇒ Object
opaque pointer.
-
.struct(elt_types, is_packed, name = nil) ⇒ Object
Creates a struct type with the given array of element types.
-
.vector(ty, element_count) ⇒ Object
Creates a vector type of Type with the given element count.
-
.void ⇒ Object
Creates a void type.
- .x86_amx ⇒ Object
- .x86_mmx ⇒ Object
Instance Method Summary collapse
- #===(other) ⇒ Object
- #aggregate? ⇒ Boolean
- #align ⇒ Object
-
#dump ⇒ Object
Print the type’s representation to stdout.
-
#element_type ⇒ Object
Returns the type of this types elements (works only for Pointer, Vector, and Array types.).
- #literal_struct? ⇒ Boolean
-
#null ⇒ Object
Returns a null ConstantExpr of this type.
-
#null_pointer ⇒ Object
Returns a null pointer ConstantExpr of this type.
- #opaque_struct? ⇒ Boolean
- #packed_struct? ⇒ Boolean
-
#pointer(address_space = 0) ⇒ Object
Creates a pointer type with this type and the given address space.
- #poison ⇒ Object
-
#size ⇒ Object
Returns the size of the type.
-
#to_s ⇒ Object
Build string of LLVM type representation.
- #undef ⇒ Object
Methods included from PointerIdentity
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns a symbol representation of the types kind (ex. :pointer, :vector, :array.)
29 30 31 |
# File 'lib/llvm/core/type.rb', line 29 def kind @kind end |
Class Method Details
.array(ty, sz = 0) ⇒ Object
Creates an array type of Type with the given size. arrays can be size >= 0, llvm.org/docs/LangRef.html#array-type
117 118 119 120 121 122 |
# File 'lib/llvm/core/type.rb', line 117 def self.array(ty, sz = 0) sz = sz.to_i raise ArgumentError, "LLVM Array size must be >= 0" if sz.negative? from_ptr(C.array_type(LLVM::Type(ty), sz), :array) end |
.double ⇒ Object
217 218 219 |
# File 'lib/llvm/core/type.rb', line 217 def self.double RealType.from_ptr(C.double_type, kind: :double) end |
.float ⇒ Object
213 214 215 |
# File 'lib/llvm/core/type.rb', line 213 def self.float RealType.from_ptr(C.float_type, kind: :float) end |
.from_ptr(ptr, kind = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/llvm/core/type.rb', line 8 def self.from_ptr(ptr, kind = nil) return if ptr.null? kind ||= C.get_type_kind(ptr) ty = case kind when :integer IntType.allocate when :float, :double RealType.allocate when :function FunctionType.allocate when :struct StructType.allocate else allocate end ty.instance_variable_set(:@ptr, ptr) ty.instance_variable_set(:@kind, kind) ty end |
.function(arg_types, result_type, options = {}) ⇒ Object
Creates a function type. Takes an array of argument Types and the result Type. The only option is :varargs
, which when set to true makes the function type take a variable number of args.
149 150 151 152 153 154 |
# File 'lib/llvm/core/type.rb', line 149 def self.function(arg_types, result_type, = {}) arg_types.map! { |ty| LLVM::Type(ty) } arg_types_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * arg_types.size) arg_types_ptr.write_array_of_pointer(arg_types) from_ptr(C.function_type(LLVM::Type(result_type), arg_types_ptr, arg_types.size, [:varargs] ? 1 : 0), :function) end |
.integer(width) ⇒ Object Also known as: i
def self.rec
h = opaque
ty = yield h
h.refine(ty)
ty
end
205 206 207 |
# File 'lib/llvm/core/type.rb', line 205 def self.integer(width) IntType.from_ptr(C.int_type(width), :integer) end |
.label ⇒ Object
183 184 185 |
# File 'lib/llvm/core/type.rb', line 183 def self.label from_ptr(C.label_type, :label) end |
.named(name) ⇒ Object
174 175 176 |
# File 'lib/llvm/core/type.rb', line 174 def self.named(name) from_ptr(C.get_type_by_name2(Context.global, name.to_s), nil) end |
.opaque_struct(name) ⇒ Object
170 171 172 |
# File 'lib/llvm/core/type.rb', line 170 def self.opaque_struct(name) from_ptr(C.struct_create_named(Context.global, name.to_s), :struct) end |
.pointer(ty = nil, address_space = 0) ⇒ Object
Creates the pointer type of Type with the given address space.
125 126 127 128 129 130 131 |
# File 'lib/llvm/core/type.rb', line 125 def self.pointer(ty = nil, address_space = 0) if ty from_ptr(C.pointer_type(LLVM::Type(ty), address_space), :pointer) else ptr(address_space) end end |
.ptr(address_space = 0) ⇒ Object
opaque pointer
134 135 136 |
# File 'lib/llvm/core/type.rb', line 134 def self.ptr(address_space = 0) from_ptr(C.pointer_type(void, address_space), :pointer) end |
.struct(elt_types, is_packed, name = nil) ⇒ Object
Creates a struct type with the given array of element types.
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/llvm/core/type.rb', line 157 def self.struct(elt_types, is_packed, name = nil) elt_types.map! { |ty| LLVM::Type(ty) } elt_types_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * elt_types.size) elt_types_ptr.write_array_of_pointer(elt_types) if name struct = from_ptr(C.struct_create_named(Context.global, name), :struct) C.struct_set_body(struct, elt_types_ptr, elt_types.size, is_packed ? 1 : 0) unless elt_types.empty? struct else from_ptr(C.struct_type(elt_types_ptr, elt_types.size, is_packed ? 1 : 0), :struct) end end |
.vector(ty, element_count) ⇒ Object
Creates a vector type of Type with the given element count. vectors can be size > 0, llvm.org/docs/LangRef.html#vector-type
140 141 142 143 144 145 |
# File 'lib/llvm/core/type.rb', line 140 def self.vector(ty, element_count) element_count = element_count.to_i raise ArgumentError, "LLVM Vector size must be > 0" unless element_count.positive? from_ptr(C.vector_type(LLVM::Type(ty), element_count), :vector) end |
.void ⇒ Object
Creates a void type.
179 180 181 |
# File 'lib/llvm/core/type.rb', line 179 def self.void from_ptr(C.void_type, :void) end |
.x86_amx ⇒ Object
191 192 193 |
# File 'lib/llvm/core/type.rb', line 191 def self.x86_amx from_ptr(C.x86amx_type, :x86amx) end |
.x86_mmx ⇒ Object
187 188 189 |
# File 'lib/llvm/core/type.rb', line 187 def self.x86_mmx from_ptr(C.x86mmx_type, :x86mmx) end |
Instance Method Details
#===(other) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/llvm/core/type.rb', line 107 def ===(other) if other.is_a?(LLVM::Value) return self == other.type end super end |
#aggregate? ⇒ Boolean
91 92 93 |
# File 'lib/llvm/core/type.rb', line 91 def aggregate? [:struct, :array].include?(kind) end |
#align ⇒ Object
36 37 38 |
# File 'lib/llvm/core/type.rb', line 36 def align LLVM::Int64.from_ptr(C.align_of(self)) end |
#dump ⇒ Object
Print the type’s representation to stdout.
80 81 82 83 84 |
# File 'lib/llvm/core/type.rb', line 80 def dump # :nocov: C.dump_type(self) # :nocov: end |
#element_type ⇒ Object
Returns the type of this types elements (works only for Pointer, Vector, and Array types.)
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/llvm/core/type.rb', line 41 def element_type case kind when :vector, :array element_type = C.get_element_type(self) Type.from_ptr(element_type) when :pointer LLVM.Void else raise ArgumentError, "element_type not supported for kind: #{kind}" end end |
#literal_struct? ⇒ Boolean
103 104 105 |
# File 'lib/llvm/core/type.rb', line 103 def literal_struct? C.is_literal_struct(self) end |
#null ⇒ Object
Returns a null ConstantExpr of this type.
59 60 61 62 |
# File 'lib/llvm/core/type.rb', line 59 def null # ConstantExpr.from_ptr(C.const_null(self)) Constant.null(self) end |
#null_pointer ⇒ Object
Returns a null pointer ConstantExpr of this type.
54 55 56 |
# File 'lib/llvm/core/type.rb', line 54 def null_pointer ConstantExpr.from_ptr(C.const_pointer_null(self)) end |
#opaque_struct? ⇒ Boolean
95 96 97 |
# File 'lib/llvm/core/type.rb', line 95 def opaque_struct? C.is_opaque_struct(self) end |
#packed_struct? ⇒ Boolean
99 100 101 |
# File 'lib/llvm/core/type.rb', line 99 def packed_struct? C.is_packed_struct(self) end |
#pointer(address_space = 0) ⇒ Object
Creates a pointer type with this type and the given address space.
75 76 77 |
# File 'lib/llvm/core/type.rb', line 75 def pointer(address_space = 0) Type.pointer(self, address_space) end |
#poison ⇒ Object
64 65 66 67 |
# File 'lib/llvm/core/type.rb', line 64 def poison # ConstantExpr.from_ptr(C.get_poison(self)) Constant.poison(self) end |
#size ⇒ Object
Returns the size of the type.
32 33 34 |
# File 'lib/llvm/core/type.rb', line 32 def size LLVM::Int64.from_ptr(C.size_of(self)) end |
#to_s ⇒ Object
Build string of LLVM type representation.
87 88 89 |
# File 'lib/llvm/core/type.rb', line 87 def to_s C.print_type_to_string(self) end |