class RLTK::CG::StructType

A type for representing an arbitrary collection of types.

Public Class Methods

new(overloaded, name = nil, packed = false, context = nil) click to toggle source

Create a new struct type.

@param [FFI::Pointer, Array<Type>] overloaded Pointer to an existing struct type or an array of types in the struct. @param [String, nil] name Name of the new struct type in LLVM IR. @param [Boolean] packed Are the types packed already, or should they be re-arranged to save space? @param [Context, nil] context Context in which to create this new type.

# File lib/rltk/cg/type.rb, line 408
def initialize(overloaded, name = nil, packed = false, context = nil)
        @ptr =
        case overloaded
        when FFI::Pointer
                overloaded
        else
                # Check the types of the elements of the overloaded parameter.
                @element_types = check_cg_array_type(overloaded, Type, 'overloaded')

                el_types_ptr = FFI::MemoryPointer.new(:pointer, @element_types.length)
                el_types_ptr.write_array_of_pointer(@element_types)

                if name
                        @name = check_type(name, String, 'name')

                        Bindings.struct_create_named(Context.global, @name).tap do |ptr|
                                Bindings.struct_set_body(ptr, el_types_ptr, @element_types.length, packed.to_i) unless @element_types.empty?
                        end

                elsif context
                        check_type(context, Context, 'context')

                        Bindings.struct_type_in_context(context, el_types_ptr, @element_types.length, is_packed.to_i)

                else
                        Bindings.struct_type(el_types_ptr, @element_types.length, packed.to_i)
                end
        end
end

Public Instance Methods

element_types() click to toggle source

@return [Array<Type>] Array of the types in this struct type.

# File lib/rltk/cg/type.rb, line 439
def element_types
        @element_types ||=
        begin
                num_elements = Bindings.count_struct_element_types(@ptr)

                ret_ptr = FFI::MemoryPointer.new(:pointer)
                Bindings.get_struct_element_types(@ptr, ret_ptr)

                types_ptr = ret_ptr.get_pointer(0)

                types_ptr.get_array_of_pointer(0, num_elements).map { |ptr| Type.from_ptr(ptr) }
        end
end
element_types=(el_types, packed = false) click to toggle source

Set the types in the body of this struct type.

@param [Array<Type>] el_types Array of types in the struct. @param [Boolean] packed Are the types packed already, or should they be re-arranged to save space?

@return [void]

# File lib/rltk/cg/type.rb, line 459
def element_types=(el_types, packed = false)
        @element_types = check_cg_array_type(el_types, Type, 'el_types')

        el_types_ptr = FFI::MemoryPointer.new(:pointer, @element_types.length)
        el_types_ptr.write_array_of_pointer(@element_types)

        Bindings.struct_set_body(@ptr, el_types_ptr, @element_types.length, packed.to_i)
end
name() click to toggle source

@return [String] Name of the struct type in LLVM IR.

# File lib/rltk/cg/type.rb, line 469
def name
        @name ||= Bindings.get_struct_name(@ptr)
end