Class: RLTK::CG::Type Abstract

Inherits:
Object show all
Includes:
AbstractClass, BindingClass
Defined in:
lib/rltk/cg/type.rb

Overview

This class is abstract.

Root of the type class hierarchy.

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.

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AbstractClass

included

Methods included from BindingClass

#==

Constructor Details

#initialize(context = nil) ⇒ Type

The default constructor for Type objects.

Parameters:

  • context (Context, nil) (defaults to: nil)

    An optional context in which to create the type.



63
64
65
66
67
68
69
70
71
72
# File 'lib/rltk/cg/type.rb', line 63

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

Class Method Details

.from_ptr(ptr) ⇒ Type

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

Parameters:

  • ptr (FFI::Pointer)

Returns:

  • (Type)

    A object of type Type or one of its sub-classes.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rltk/cg/type.rb', line 40

def self.from_ptr(ptr)
	case Bindings.get_type_kind(ptr)
	when :array		then ArrayType.new(ptr)
	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

Instance Method Details

#allignmentNativeInt

Returns Alignment of the type.

Returns:



75
76
77
# File 'lib/rltk/cg/type.rb', line 75

def allignment
	Int64.new(Bindings.align_of(@ptr))
end

#contextContext

Returns Context in which this type was created.

Returns:

  • (Context)

    Context in which this type was created.



80
81
82
# File 'lib/rltk/cg/type.rb', line 80

def context
	Context.new(Bindings.get_type_context(@ptr))
end

#hashFixnum

Returns Hashed value of the pointer representing this type.

Returns:

  • (Fixnum)

    Hashed value of the pointer representing this type.



85
86
87
# File 'lib/rltk/cg/type.rb', line 85

def hash
	@ptr.address.hash
end

#kindSymbol

Returns The kind of this type.

Returns:

  • (Symbol)

    The kind of this type.

See Also:



92
93
94
# File 'lib/rltk/cg/type.rb', line 92

def kind
	Bindings.get_type_kind(@ptr)
end

#sizeNativeInt

Returns Size of objects of this type.

Returns:

  • (NativeInt)

    Size of objects of this type.



97
98
99
# File 'lib/rltk/cg/type.rb', line 97

def size
	Int64.new(Bindings.size_of(@ptr))
end