Class: RLTK::CG::Function

Inherits:
GlobalValue show all
Defined in:
lib/rltk/cg/function.rb

Overview

An LLVM IR function.

Defined Under Namespace

Classes: BasicBlockCollection, FunctionAttrCollection, ParameterCollection

Instance Attribute Summary collapse

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods inherited from GlobalValue

#alignment, #alignment=, #declaration?, #externally_initialized=, #externally_initialized?, #global_constant=, #global_constant?, #initializer, #initializer=, #linkage, #linkage=, #section, #section=, #thread_local_mode, #thread_local_mode=, #visibility, #visibility=

Methods inherited from Constant

#addr_space_cast, #bitcast_to, #get_element_ptr, #get_element_ptr_in_bounds

Methods inherited from User

#operands

Methods inherited from Value

#==, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #undefined?, #zextend, #zextend_or_bitcast

Methods included from BindingClass

#==

Constructor Details

#initialize(overloaded, name = '', *type_info, &block) ⇒ Function

Define a new function in a given module. You can also use the Module::FunctionCollection#add method to add functions to modules.

Parameters:

  • overloaded (FFI::Pointer, Module)

    Pointer to a function objet or a module.

  • name (String) (defaults to: '')

    Name of the function in LLVM IR.

  • type_info (FunctionType, Array(Type, Array<Type>))

    FunctionType or Values that will be passed to RLTK::CG::FunctionType#initialize.

  • block (Proc)

    Block to be executed inside the context of the function.

Raises:

  • (RuntimeError)

    An error is raised if the overloaded parameter is of an incorrect type.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rltk/cg/function.rb', line 36

def initialize(overloaded, name = '', *type_info, &block)
	@ptr =
	case overloaded
	when FFI::Pointer
		overloaded

	when RLTK::CG::Module
		@type = if type_info.first.is_a?(FunctionType) then type_info.first else FunctionType.new(*type_info) end

		Bindings.add_function(overloaded, name.to_s, @type)

	else
		raise 'The first argument to Function.new must be either a pointer or an instance of RLTK::CG::Module.'
	end

	self.instance_exec(self, &block) if block
end

Instance Attribute Details

#typeFunctionType (readonly)

Returns FunctionType object describing this function’s type.

Returns:

  • (FunctionType)

    FunctionType object describing this function’s type.



24
25
26
# File 'lib/rltk/cg/function.rb', line 24

def type
  @type
end

Instance Method Details

#attributesFunctionAttrCollection Also known as: attrs

Returns Proxy object for inspecting function attributes.

Returns:



55
56
57
# File 'lib/rltk/cg/function.rb', line 55

def attributes
	@attributes ||= FunctionAttrCollection.new(self)
end

#basic_blocksBasicBlockCollection Also known as: blocks

Returns Proxy object for inspecting a function’s basic blocks.

Returns:



61
62
63
# File 'lib/rltk/cg/function.rb', line 61

def basic_blocks
	@basic_blocks ||= BasicBlockCollection.new(self)
end

#calling_conventionSymbol

Get a function’s calling convention.

Returns:

  • (Symbol)

See Also:



71
72
73
# File 'lib/rltk/cg/function.rb', line 71

def calling_convention
	Bindings.enum_type(:call_conv)[Bindings.get_function_call_conv(@ptr)]
end

#calling_convention=(conv) ⇒ Object

Set a function’s calling convention.

Parameters:

  • conv (Symbol)

    Calling convention to set.

See Also:



80
81
82
83
84
# File 'lib/rltk/cg/function.rb', line 80

def calling_convention=(conv)
	Bindings.set_function_call_conv(@ptr, Bindings.enum_type(:call_conv)[conv])

	conv
end

#parametersParameterCollection Also known as: params

Returns Proxy object for inspecting a function’s parameters.

Returns:



87
88
89
# File 'lib/rltk/cg/function.rb', line 87

def parameters
	@parameters ||= ParameterCollection.new(self)
end

#verifynil, String

Verify that the function is valid LLVM IR.

Returns:

  • (nil, String)

    Human-readable description of any invalid constructs if invalid.



95
96
97
# File 'lib/rltk/cg/function.rb', line 95

def verify
	do_verification(:return_status)
end

#verify!nil

Verify that the function is valid LLVM IR and abort the process if it isn’t.

Returns:

  • (nil)


102
103
104
# File 'lib/rltk/cg/function.rb', line 102

def verify!
	do_verification(:abort_process)
end