class RLTK::CG::Module::FunctionCollection

This class is used to access a module’s {Function Functions}.

Public Class Methods

new(mod) click to toggle source

@param [Module] mod Module for which this is a proxy.

# File lib/rltk/cg/module.rb, line 275
def initialize(mod)
        @module = mod
end

Public Instance Methods

[](key) click to toggle source

Retreive a Function object.

@param [String, Symbol, Integer] key Function identifier. Either the name of the function or its index.

@return [Function]

# File lib/rltk/cg/module.rb, line 284
def [](key)
        case key
        when String, Symbol
                self.named(key)

        when Integer
                (1...key).inject(self.first) { |fun| if fun then self.next(fun) else break end }
        end
end
add(name, *type_info, &block) click to toggle source

Add a Function to this module.

@param [String] name Name of the module 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.

@return [Function]

# File lib/rltk/cg/module.rb, line 301
def add(name, *type_info, &block)
        Function.new(@module, name, *type_info, &block)
end
delete(fun) click to toggle source

Remove a function from the module.

@param [Function] fun Function to remove.

@return [void]

# File lib/rltk/cg/module.rb, line 310
def delete(fun)
        Bindings.delete_function(fun)
end
each() { |fun| ... } click to toggle source

An iterator for each function inside this collection.

@yieldparam fun [Function]

@return [Enumerator] Returns an Enumerator if no block is given.

# File lib/rltk/cg/module.rb, line 319
def each
        return to_enum(:each) unless block_given?

        fun = self.first

        while fun
                yield fun
                fun = self.next(fun)
        end
end
first() click to toggle source

@return [Function, nil] The module’s first function if one has been added.

# File lib/rltk/cg/module.rb, line 331
def first
        if (ptr = Bindings.get_first_function(@module)).null? then nil else Function.new(ptr) end
end
last() click to toggle source

@return [Function, nil] The module’s last function if one has been added.

# File lib/rltk/cg/module.rb, line 336
def last
        if (ptr = Bindings.get_last_function(@module)).null? then nil else Function.new(ptr) end
end
named(name) click to toggle source

@param [String, Symbol] name Name of the desired function.

@return [Function, nil] The function with the given name.

# File lib/rltk/cg/module.rb, line 343
def named(name)
        if (ptr = Bindings.get_named_function(@module, name)).null? then nil else Function.new(ptr) end
end
next(fun) click to toggle source

@param [Function] fun Function you want the successor for.

@return [Function, nil] Next function in the collection.

# File lib/rltk/cg/module.rb, line 350
def next(fun)
        if (ptr = Bindings.get_next_function(fun)).null? then nil else Function.new(ptr) end
end
previous(fun) click to toggle source

@param [Function] fun Function you want the predecessor for.

@return [Function, nil] Previous function in the collection.

# File lib/rltk/cg/module.rb, line 357
def previous(fun)
        if (ptr = Bindings.get_previous_function(fun)).null? then nil else Function.new(ptr) end
end