class SyntaxTree::YARV::BasicBlock

This object represents a single basic block, wherein all contained instructions do not branch except for the last one.

Attributes

block_start[R]

This is the index into the list of instructions where this block starts.

id[R]

This is the unique identifier for this basic block.

incoming_blocks[R]

This is an array of basic blocks that lead into this block.

insns[R]

This is the set of instructions that this block contains.

outgoing_blocks[R]

This is an array of basic blocks that this block leads into.

Public Class Methods

new(block_start, insns) click to toggle source
# File lib/syntax_tree/yarv/basic_block.rb, line 23
def initialize(block_start, insns)
  @id = "block_#{block_start}"

  @block_start = block_start
  @insns = insns

  @incoming_blocks = []
  @outgoing_blocks = []
end

Public Instance Methods

each_with_length() { |insn, length| ... } click to toggle source

Yield each instruction in this basic block along with its index from the original instruction sequence.

# File lib/syntax_tree/yarv/basic_block.rb, line 35
def each_with_length
  return enum_for(:each_with_length) unless block_given?

  length = block_start
  insns.each do |insn|
    yield insn, length
    length += insn.length
  end
end
verify() click to toggle source

This method is used to verify that the basic block is well formed. It checks that the only instruction in this basic block that branches is the last instruction.

# File lib/syntax_tree/yarv/basic_block.rb, line 48
def verify
  insns[0...-1].each { |insn| raise unless insn.branch_targets.empty? }
end