Class: SyntaxTree::YARV::BasicBlock
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::BasicBlock
- Defined in:
- lib/syntax_tree/yarv/basic_block.rb
Overview
This object represents a single basic block, wherein all contained instructions do not branch except for the last one.
Instance Attribute Summary collapse
-
#block_start ⇒ Object
readonly
This is the index into the list of instructions where this block starts.
-
#id ⇒ Object
readonly
This is the unique identifier for this basic block.
-
#incoming_blocks ⇒ Object
readonly
This is an array of basic blocks that lead into this block.
-
#insns ⇒ Object
readonly
This is the set of instructions that this block contains.
-
#outgoing_blocks ⇒ Object
readonly
This is an array of basic blocks that this block leads into.
Instance Method Summary collapse
-
#each_with_length ⇒ Object
Yield each instruction in this basic block along with its index from the original instruction sequence.
-
#initialize(block_start, insns) ⇒ BasicBlock
constructor
A new instance of BasicBlock.
-
#verify ⇒ Object
This method is used to verify that the basic block is well formed.
Constructor Details
#initialize(block_start, insns) ⇒ BasicBlock
Returns a new instance of BasicBlock.
23 24 25 26 27 28 29 30 31 |
# 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 |
Instance Attribute Details
#block_start ⇒ Object (readonly)
This is the index into the list of instructions where this block starts.
12 13 14 |
# File 'lib/syntax_tree/yarv/basic_block.rb', line 12 def block_start @block_start end |
#id ⇒ Object (readonly)
This is the unique identifier for this basic block.
9 10 11 |
# File 'lib/syntax_tree/yarv/basic_block.rb', line 9 def id @id end |
#incoming_blocks ⇒ Object (readonly)
This is an array of basic blocks that lead into this block.
18 19 20 |
# File 'lib/syntax_tree/yarv/basic_block.rb', line 18 def incoming_blocks @incoming_blocks end |
#insns ⇒ Object (readonly)
This is the set of instructions that this block contains.
15 16 17 |
# File 'lib/syntax_tree/yarv/basic_block.rb', line 15 def insns @insns end |
#outgoing_blocks ⇒ Object (readonly)
This is an array of basic blocks that this block leads into.
21 22 23 |
# File 'lib/syntax_tree/yarv/basic_block.rb', line 21 def outgoing_blocks @outgoing_blocks end |
Instance Method Details
#each_with_length ⇒ Object
Yield each instruction in this basic block along with its index from the original instruction sequence.
35 36 37 38 39 40 41 42 43 |
# 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 ⇒ Object
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.
48 49 50 |
# File 'lib/syntax_tree/yarv/basic_block.rb', line 48 def verify insns[0...-1].each { |insn| raise unless insn.branch_targets.empty? } end |