class RCGTK::Function

An LLVM IR function.

Attributes

type[R]

@return [FunctionType] FunctionType object describing this function’s type.

Public Class Methods

new(overloaded, name = '', *type_info, &block) click to toggle source

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

@param [FFI::Pointer, Module] overloaded Pointer to a function objet or a module. @param [String] name Name of the function in LLVM IR. @param [FunctionType, Array(Type, Array<Type>)] type_info FunctionType or Values that will be passed to {FunctionType#initialize}. @param [Proc] block Block to be executed inside the context of the function.

@raise [RuntimeError] An error is raised if the overloaded parameter is of an incorrect type.

# File lib/rcgtk/function.rb, line 36
def initialize(overloaded, name = '', *type_info, &block)
        @ptr =
        case overloaded
        when FFI::Pointer
                overloaded

        when RCGTK::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 RCGTK::Module.'
        end

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

Public Instance Methods

attributes() click to toggle source

@return [FunctionAttrCollection] Proxy object for inspecting function attributes.

# File lib/rcgtk/function.rb, line 55
def attributes
        @attributes ||= FunctionAttrCollection.new(self)
end
Also aliased as: attrs
attrs()
Alias for: attributes
basic_blocks() click to toggle source

@return [BasicBlockCollection] Proxy object for inspecting a function’s basic blocks.

# File lib/rcgtk/function.rb, line 61
def basic_blocks
        @basic_blocks ||= BasicBlockCollection.new(self)
end
Also aliased as: blocks
blocks()
Alias for: basic_blocks
calling_convention() click to toggle source

Get a function’s calling convention.

@see Bindings.enum_call_conv

@return [Symbol]

# File lib/rcgtk/function.rb, line 71
def calling_convention
        Bindings.enum_type(:call_conv)[Bindings.get_function_call_conv(@ptr)]
end
calling_convention=(conv) click to toggle source

Set a function’s calling convention.

@see Bindings.enum_call_conv

@param [Symbol] conv Calling convention to set.

# File lib/rcgtk/function.rb, line 80
def calling_convention=(conv)
        Bindings.set_function_call_conv(@ptr, Bindings.enum_type(:call_conv)[conv])

        conv
end
parameters() click to toggle source

@return [ParameterCollection] Proxy object for inspecting a function’s parameters.

# File lib/rcgtk/function.rb, line 87
def parameters
        @parameters ||= ParameterCollection.new(self)
end
Also aliased as: params
params()
Alias for: parameters
verify() click to toggle source

Verify that the function is valid LLVM IR.

@return [nil, String] Human-readable description of any invalid constructs if invalid.

# File lib/rcgtk/function.rb, line 95
def verify
        do_verification(:return_status)
end
verify!() click to toggle source

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

@return [nil]

# File lib/rcgtk/function.rb, line 102
def verify!
        do_verification(:abort_process)
end

Private Instance Methods

do_verification(action) click to toggle source

Helper function for {#verify} and {#verify!}

# File lib/rcgtk/function.rb, line 107
def do_verification(action)
        Bindings.verify_function(@ptr, action).to_bool
end