Class: Kumi::IR::Base::Block
- Inherits:
-
Object
- Object
- Kumi::IR::Base::Block
- Includes:
- Enumerable
- Defined in:
- lib/kumi/ir/base/block.rb
Instance Attribute Summary collapse
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #append(instr) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(name:, instructions: []) ⇒ Block
constructor
A new instance of Block.
-
#terminal_instruction ⇒ Object
The block’s last result-bearing instruction.
Constructor Details
#initialize(name:, instructions: []) ⇒ Block
Returns a new instance of Block.
11 12 13 14 |
# File 'lib/kumi/ir/base/block.rb', line 11 def initialize(name:, instructions: []) @name = name.to_sym @instructions = instructions.dup end |
Instance Attribute Details
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
9 10 11 |
# File 'lib/kumi/ir/base/block.rb', line 9 def instructions @instructions end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/kumi/ir/base/block.rb', line 9 def name @name end |
Instance Method Details
#append(instr) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/kumi/ir/base/block.rb', line 20 def append(instr) raise ArgumentError, "instruction required" unless instr.is_a?(Instruction) @instructions << instr instr end |
#each ⇒ Object
16 17 18 |
# File 'lib/kumi/ir/base/block.rb', line 16 def each(&) @instructions.each(&) end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/kumi/ir/base/block.rb', line 27 def empty? @instructions.empty? end |
#terminal_instruction ⇒ Object
The block’s last result-bearing instruction. By the IR convention this is the function’s result, so passes that drop/dedup instructions use it to avoid collapsing the terminal (which would change what the function returns). nil for a block that defines no value.
35 36 37 |
# File 'lib/kumi/ir/base/block.rb', line 35 def terminal_instruction @instructions.reverse_each.find { |instr| instr.defs.first } end |