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:

  • 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 = '', builder = nil, context = nil, *block_args, &block) ⇒ BasicBlock

Note:

The first argument to any proc passed to this function

Add a BasicBlock to the end of this function.

will be the function the block is being appended to.

Parameters:

  • (defaults to: '')

    Name of the block in LLVM IR.

  • (defaults to: nil)

    Builder to be used in evaluating block.

  • (defaults to: nil)

    Context in which to create the block.

  • Arguments to be passed to block. The function the block is appended to is automatically added to the front of this list.

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

Returns:

  • New BasicBlock.



133
134
135
# File 'lib/rltk/cg/function.rb', line 133

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

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

An iterator for each block inside this collection.

Yield Parameters:

Returns:

  • Returns an Enumerator if no block is given.



142
143
144
145
146
147
148
149
150
151
# File 'lib/rltk/cg/function.rb', line 142

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:

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



154
155
156
# File 'lib/rltk/cg/function.rb', line 154

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:

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



159
160
161
# File 'lib/rltk/cg/function.rb', line 159

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:

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



164
165
166
# File 'lib/rltk/cg/function.rb', line 164

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:

  • Number of basic blocks that comprise this function.



169
170
171
# File 'lib/rltk/cg/function.rb', line 169

def size
  Bindings.count_basic_blocks(@fun)
end