class RLTK::CG::Type

The Type class and its sub-classes are used to describe the size and structure of various data objects inside LLVM and how different operations interact with them. When instantiating objects of the {Value} class you will often need to pass in some type information.

@abstract Root of the type class hierarchy.

Public Class Methods

from_ptr(ptr) click to toggle source

Instantiate a Type object from a pointer. This function is used internally, and as a library user you should never have to call it.

@param [FFI::Pointer] ptr

@return [Type] A object of type Type or one of its sub-classes.

# File lib/rltk/cg/type.rb, line 42
def self.from_ptr(ptr)
        case Bindings.get_type_kind(ptr)
        when :array          then ArrayType.new(ptr)
        when :half          then HalfType.new
        when :double         then DoubleType.new
        when :float          then FloatType.new
        when :function               then FunctionType.new(ptr)
        when :fp128          then FP128Type.new
        when :integer                then IntType.new
        when :label          then LabelType.new
        when :metadata               then raise "Can't generate a Type object for objects of type Metadata."
        when :pointer                then PointerType.new(ptr)
        when :ppc_fp128      then PPCFP128Type.new
        when :struct         then StructType.new(ptr)
        when :vector         then VectorType.new(ptr)
        when :void           then VoidType.new
        when :x86_fp80               then X86FP80Type.new
        when :x86_mmx                then X86MMXType.new
        end
end
new(context = nil) click to toggle source

The default constructor for Type objects.

@param [Context, nil] context An optional context in which to create the type.

# File lib/rltk/cg/type.rb, line 66
def initialize(context = nil)
        bname = Bindings.get_bname(self.class.short_name)

        @ptr =
        if context
                Bindings.send((bname.to_s + '_in_context').to_sym, check_type(context, Context, 'context'))
        else
                Bindings.send(bname)
        end
end

Public Instance Methods

allignment() click to toggle source

@return [NativeInt] Alignment of the type.

# File lib/rltk/cg/type.rb, line 78
def allignment
        NativeInt.new(Bindings.align_of(@ptr))
end
context() click to toggle source

@return [Context] Context in which this type was created.

# File lib/rltk/cg/type.rb, line 83
def context
        Context.new(Bindings.get_type_context(@ptr))
end
dump() click to toggle source

Dump a string representation of the type to stdout.

@return [void]

# File lib/rltk/cg/type.rb, line 90
def dump
        Bindings.dump_type(@ptr)
end
hash() click to toggle source

@return [Fixnum] Hashed value of the pointer representing this type.

# File lib/rltk/cg/type.rb, line 95
def hash
        @ptr.address.hash
end
kind() click to toggle source

@see Bindings.enum_type_kind

@return [Symbol] The kind of this type.

# File lib/rltk/cg/type.rb, line 102
def kind
        Bindings.get_type_kind(@ptr)
end
size() click to toggle source

@return [NativeInt] Size of objects of this type.

# File lib/rltk/cg/type.rb, line 107
def size
        Int64.new(Bindings.size_of(@ptr))
end
to_s() click to toggle source

@return [String] LLVM IR representation of the type

# File lib/rltk/cg/type.rb, line 112
def to_s
        Bindings.print_type_to_string(@ptr)
end