class RLTK::CG::Module::FunctionCollection
This class is used to access a module’s {Function Functions}.
Public Class Methods
@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
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 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
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
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
@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
@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
@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
@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
@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