Class: LLVM::Type
- Inherits:
-
Object
- Object
- LLVM::Type
- Includes:
- PointerIdentity
- Defined in:
- lib/llvm/core/type.rb
Direct Known Subclasses
Class Method Summary collapse
-
.array(ty, sz = 0) ⇒ Object
Creates an array type of Type with the given size.
- .from_ptr(ptr, kind) ⇒ Object
-
.function(arg_types, result_type, options = {}) ⇒ Object
Creates a function type.
-
.pointer(ty, address_space = 0) ⇒ Object
Creates the pointer type of Type with the given address space.
- .rec ⇒ Object
-
.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.
Instance Method Summary collapse
- #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.).
-
#kind ⇒ Object
Returns a symbol representation of the types kind (ex. :pointer, :vector, :array.).
-
#null ⇒ Object
Returns a null ConstantExpr of this type.
-
#null_pointer ⇒ Object
Returns a null pointer ConstantExpr of this type.
-
#pointer(address_space = 0) ⇒ Object
Creates a pointer type with this type and the given address space.
-
#size ⇒ Object
Returns the size of the type.
Methods included from PointerIdentity
Class Method Details
.array(ty, sz = 0) ⇒ Object
Creates an array type of Type with the given size.
63 64 65 |
# File 'lib/llvm/core/type.rb', line 63 def self.array(ty, sz = 0) from_ptr(C.array_type(LLVM::Type(ty), sz), :array) end |
.from_ptr(ptr, kind) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/llvm/core/type.rb', line 6 def self.from_ptr(ptr, kind) return if ptr.null? kind ||= C.get_type_kind(ptr) ty = case kind when :integer then IntType.allocate when :function then FunctionType.allocate when :struct then 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.
79 80 81 82 83 84 |
# File 'lib/llvm/core/type.rb', line 79 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 |
.pointer(ty, address_space = 0) ⇒ Object
Creates the pointer type of Type with the given address space.
68 69 70 |
# File 'lib/llvm/core/type.rb', line 68 def self.pointer(ty, address_space = 0) from_ptr(C.pointer_type(LLVM::Type(ty), address_space), :pointer) end |
.rec ⇒ Object
105 106 107 108 109 110 |
# File 'lib/llvm/core/type.rb', line 105 def self.rec h = opaque ty = yield h h.refine(ty) ty end |
.struct(elt_types, is_packed, name = nil) ⇒ Object
Creates a struct type with the given array of element types.
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/llvm/core/type.rb', line 87 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.
73 74 75 |
# File 'lib/llvm/core/type.rb', line 73 def self.vector(ty, element_count) from_ptr(C.vector_type(LLVM::Type(ty), element_count), :vector) end |
Instance Method Details
#align ⇒ Object
30 31 32 |
# File 'lib/llvm/core/type.rb', line 30 def align LLVM::Int64.from_ptr(C.align_of(self)) end |
#dump ⇒ Object
Print the type’s representation to stdout.
58 59 60 |
# File 'lib/llvm/core/type.rb', line 58 def dump C.dump_type(self) end |
#element_type ⇒ Object
Returns the type of this types elements (works only for Pointer, Vector, and Array types.)
35 36 37 38 39 40 |
# File 'lib/llvm/core/type.rb', line 35 def element_type case kind when :pointer, :vector, :array Type.from_ptr(C.get_element_type(self), nil) end end |
#kind ⇒ Object
Returns a symbol representation of the types kind (ex. :pointer, :vector, :array.)
21 22 23 |
# File 'lib/llvm/core/type.rb', line 21 def kind @kind end |
#null ⇒ Object
Returns a null ConstantExpr of this type.
48 49 50 |
# File 'lib/llvm/core/type.rb', line 48 def null ConstantExpr.from_ptr(C.const_null(self)) end |
#null_pointer ⇒ Object
Returns a null pointer ConstantExpr of this type.
43 44 45 |
# File 'lib/llvm/core/type.rb', line 43 def null_pointer ConstantExpr.from_ptr(C.const_pointer_null(self)) end |