class RCGTK::Function::BasicBlockCollection

This class is used to access a function’s {BasicBlock BasicBlocks}

Public Class Methods

new(fun) click to toggle source

@param [Function] fun Function for which this is a proxy.

# File lib/rcgtk/function.rb, line 117
def initialize(fun)
        @fun = fun
end

Public Instance Methods

append(name = '', builder = nil, context = nil, *block_args, &block) click to toggle source

Add a {BasicBlock} to the end of this function.

@note The first argument to any proc passed to this function

will be the function the block is being appended to.

@param [String] name Name of the block in LLVM IR. @param [Builder, nil] builder Builder to be used in evaluating block. @param [Context, nil] context Context in which to create the block. @param [Array<Object>] block_args Arguments to be passed to block. The function the block is appended to is automatically added to the front of this list. @param [Proc] block Block to be evaluated using builder after positioning it at the end of the new block.

@return [BasicBlock] New BasicBlock.

# File lib/rcgtk/function.rb, line 133
def append(name = '', builder = nil, context = nil, *block_args, &block)
        BasicBlock.new(@fun, name, builder, context, *block_args, &block)
end
each() { |basic_block| ... } click to toggle source

An iterator for each block inside this collection.

@yieldparam block [BasicBlock]

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

# File lib/rcgtk/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
entry() click to toggle source

@return [BasicBlock, nil] The function’s entry block if it has been added.

# File lib/rcgtk/function.rb, line 154
def entry
        if (ptr = Bindings.get_entry_basic_block(@fun)) then BasicBlock.new(ptr) else nil end
end
first() click to toggle source

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

# File lib/rcgtk/function.rb, line 159
def first
        if (ptr = Bindings.get_first_basic_block(@fun)) then BasicBlock.new(ptr) else nil end
end
last() click to toggle source

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

# File lib/rcgtk/function.rb, line 164
def last
        if (ptr = Bindings.get_last_basic_block(@fun)) then BasicBlock.new(ptr) else nil end
end
size() click to toggle source

@return [Integer] Number of basic blocks that comprise this function.

# File lib/rcgtk/function.rb, line 169
def size
        Bindings.count_basic_blocks(@fun)
end