class RLTK::CG::PhiInst::IncomingCollection
This class is used to access a Phi node’s incoming {BasicBlock}/{Value} pairs.
Public Class Methods
@param [PhiInst] phi Phi instruction for which this is a proxy.
# File lib/rltk/cg/instruction.rb, line 177 def initialize(phi) @phi = phi end
Public Instance Methods
Access the {BasicBlock}/{Value} pair at the given index.
@param [Integer] index Index of the desired pair. May be negative.
@return [Array(BasicBlock
, Value
)]
# File lib/rltk/cg/instruction.rb, line 186 def [](index) index += self.size if index < 0 if 0 <= index and index < self.size [self.block(index), self.value(index)] end end
Add incoming {BasicBlock}/{Value} pairs to a Phi node.
@example Adding a single block/value pair:
phi.incoming.add(bb, val)
@example Adding several block/value pairs:
phi.incoming.add({bb0 => val0, bb1 => val1})
@param [BasicBlock, Hash{BasicBlock => Value}] overloaded @param [Value, nil] value
@return [void]
# File lib/rltk/cg/instruction.rb, line 206 def add(overloaded, value = nil) blks, vals = if overloaded.is_a?(BasicBlock) and check_type(value, Value, 'value') [overloaded, value] else if RUBY_VERSION[0..2] == '1.9' [overloaded.keys, overloaded.values] else [(keys = overloaded.keys), overloaded.values_at(*keys)] end end vals_ptr = FFI::MemoryPointer.new(:pointer, vals.size) vals_ptr.write_array_of_pointer(vals) blks_ptr = FFI::MemoryPointer.new(:pointer, blks.size) blks_ptr.write_array_of_pointer(blks) nil.tap { Bindings.add_incoming(@phi, vals_ptr, blks_ptr, vals.length) } end
@param [Integer] index Index of desired incoming {BasicBlock}.
@return [BasicBlock] Incoming {BasicBlock}.
# File lib/rltk/cg/instruction.rb, line 231 def block(index) index += self.size if index < 0 if 0 <= index and index < self.size BasicBlock.new(Bindings.get_incoming_block(@phi, index)) end end
An iterator for each incoming {BasicBlock}/{Value} pair.
@yieldparam pair [Array(BasicBlock
, Value
)]
@return [Enumerator] Returns an Enumerator if no block is given.
# File lib/rltk/cg/instruction.rb, line 244 def each return to_enum(:each) unless block_given? self.size.times { |index| yield self[index] } self end
@return [Integer] Number of incoming {BasicBlock}/{Value} pairs.
# File lib/rltk/cg/instruction.rb, line 253 def size Bindings.count_incoming(@phi) end
@param [Integer] index Index of desired incoming {Value}.
@return [BasicBlock] Incoming {Value}.
# File lib/rltk/cg/instruction.rb, line 260 def value(index) index += self.size if index < 0 if 0 <= index and index < self.size Value.new(Bindings.get_incoming_value(@phi, index)) end end