Class: RLTK::CG::Module::FunctionCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rltk/cg/module.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ FunctionCollection

Returns a new instance of FunctionCollection.

Parameters:

  • mod (Module)

    Module for which this is a proxy.



230
231
232
# File 'lib/rltk/cg/module.rb', line 230

def initialize(mod)
	@module = mod
end

Instance Method Details

#[](key) ⇒ Function

Retreive a Function object.

Parameters:

  • key (String, Symbol, Integer)

    Function identifier. Either the name of the function or its index.

Returns:



239
240
241
242
243
244
245
246
247
# File 'lib/rltk/cg/module.rb', line 239

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) ⇒ Function

Add a Function to this module.

Parameters:

  • name (String)

    Name of the module in LLVM IR.

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

    FunctionType or Values that will be passed to FunctionType#initialize.

  • block (Proc)

    Block to be executed inside the context of the function.

Returns:



256
257
258
# File 'lib/rltk/cg/module.rb', line 256

def add(name, *type_info, &block)
	Function.new(@module, name, *type_info, &block)
end

#delete(fun) ⇒ void

This method returns an undefined value.

Remove a function from the module.

Parameters:

  • fun (Function)

    Function to remove.



265
266
267
# File 'lib/rltk/cg/module.rb', line 265

def delete(fun)
	Bindings.delete_function(fun)
end

#each {|fun| ... } ⇒ Enumerator

An iterator for each function inside this collection.

Yield Parameters:

Returns:

  • (Enumerator)

    Returns an Enumerator if no block is given.



274
275
276
277
278
279
280
281
282
283
# File 'lib/rltk/cg/module.rb', line 274

def each
	return to_enum(:each) unless block_given?
	
	fun = self.first
	
	while fun
		yield fun
		fun = self.next(fun)
	end
end

#firstFunction?

Returns The module’s first function if one has been added.

Returns:

  • (Function, nil)

    The module’s first function if one has been added.



286
287
288
# File 'lib/rltk/cg/module.rb', line 286

def first
	if (ptr = Bindings.get_first_function(@module)).null? then nil else Function.new(ptr) end
end

#lastFunction?

Returns The module’s last function if one has been added.

Returns:

  • (Function, nil)

    The module’s last function if one has been added.



291
292
293
# File 'lib/rltk/cg/module.rb', line 291

def last
	if (ptr = Bindings.get_last_function(@module)).null? then nil else Function.new(ptr) end
end

#named(name) ⇒ Function?

Returns The function with the given name.

Parameters:

  • name (String, Symbol)

    Name of the desired function.

Returns:

  • (Function, nil)

    The function with the given name.



298
299
300
# File 'lib/rltk/cg/module.rb', line 298

def named(name)
	if (ptr = Bindings.get_named_function(@module, name)).null? then nil else Function.new(ptr) end
end

#next(fun) ⇒ Function?

Returns Next function in the collection.

Parameters:

  • fun (Function)

    Function you want the successor for.

Returns:

  • (Function, nil)

    Next function in the collection.



305
306
307
# File 'lib/rltk/cg/module.rb', line 305

def next(fun)
	if (ptr = Bindings.get_next_function(fun)).null? then nil else Function.new(ptr) end
end

#previous(fun) ⇒ Function?

Returns Previous function in the collection.

Parameters:

  • fun (Function)

    Function you want the predecessor for.

Returns:

  • (Function, nil)

    Previous function in the collection.



312
313
314
# File 'lib/rltk/cg/module.rb', line 312

def previous(fun)
	if (ptr = Bindings.get_previous_function(fun)).null? then nil else Function.new(ptr) end
end