Class: RLTK::CG::Function::BasicBlockCollection

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

Overview

This class is used to access a function’s BasicBlocks

Instance Method Summary collapse

Constructor Details

#initialize(fun) ⇒ BasicBlockCollection

Returns a new instance of BasicBlockCollection.

Parameters:

  • fun (Function)

    Function for which this is a proxy.



117
118
119
# File 'lib/rltk/cg/function.rb', line 117

def initialize(fun)
	@fun = fun
end

Instance Method Details

#append(name = '', context = nil, builder = nil, *block_args, &block) ⇒ BasicBlock

Add a BasicBlock to the end of this function.

Parameters:

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

    Name of the block in LLVM IR.

  • context (Context, nil) (defaults to: nil)

    Context in which to create the block.

  • builder (Builder, nil) (defaults to: nil)

    Builder to be used in evaluating block.

  • block_args (Array<Object>)

    Arguments to be passed to block.

  • block (Proc)

    Block to be evaluated using builder after positioning it at the end of the new block.

Returns:



130
131
132
# File 'lib/rltk/cg/function.rb', line 130

def append(name = '', context = nil, builder = nil, *block_args, &block)
	BasicBlock.new(@fun, name, context, builder, *block_args, &block)
end

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

An iterator for each block inside this collection.

Yield Parameters:

Returns:

  • (Enumerator)

    Returns an Enumerator if no block is given.



139
140
141
142
143
144
145
146
147
148
# File 'lib/rltk/cg/function.rb', line 139

def each
	return to_enum :each unless block_given?
	
	ptr = Bindings.get_first_basic_block(@fun)
	
	self.size.times do |i|
		yield BasicBlock.new(ptr)
		ptr = Bindings.get_next_basic_block(ptr)
	end
end

#entryBasicBlock?

Returns The function’s entry block if it has been added.

Returns:

  • (BasicBlock, nil)

    The function’s entry block if it has been added.



151
152
153
# File 'lib/rltk/cg/function.rb', line 151

def entry
	if (ptr = Bindings.get_entry_basic_block(@fun)) then BasicBlock.new(ptr) else nil end
end

#firstBasicBlock?

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

Returns:

  • (BasicBlock, nil)

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



156
157
158
# File 'lib/rltk/cg/function.rb', line 156

def first
	if (ptr = Bindings.get_first_basic_block(@fun)) then BasicBlock.new(ptr) else nil end
end

#lastBasicBlock?

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

Returns:

  • (BasicBlock, nil)

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



161
162
163
# File 'lib/rltk/cg/function.rb', line 161

def last
	if (ptr = Bindings.get_last_basic_block(@fun)) then BasicBlock.new(ptr) else nil end
end

#sizeInteger

Returns Number of basic blocks that comprise this function.

Returns:

  • (Integer)

    Number of basic blocks that comprise this function.



166
167
168
# File 'lib/rltk/cg/function.rb', line 166

def size
	Bindings.count_basic_blocks(@fun)
end