Class: RLTK::CG::PhiInst::IncomingCollection
- Includes:
- Enumerable
- Defined in:
- lib/rltk/cg/instruction.rb
Overview
This class is used to access a Phi node’s incoming BasicBlock/Value pairs.
Instance Method Summary collapse
-
#[](index) ⇒ Array(BasicBlock, Value)
Access the BasicBlock/Value pair at the given index.
-
#add(overloaded, value = nil) ⇒ void
(also: #<<)
Add incoming BasicBlock/Value pairs to a Phi node.
-
#block(index) ⇒ BasicBlock
Incoming BasicBlock.
-
#each {|pair| ... } ⇒ Enumerator
An iterator for each incoming BasicBlock/Value pair.
-
#initialize(phi) ⇒ IncomingCollection
constructor
A new instance of IncomingCollection.
-
#size ⇒ Integer
Number of incoming BasicBlock/Value pairs.
-
#value(index) ⇒ BasicBlock
Incoming Value.
Constructor Details
#initialize(phi) ⇒ IncomingCollection
Returns a new instance of IncomingCollection.
162 163 164 |
# File 'lib/rltk/cg/instruction.rb', line 162 def initialize(phi) @phi = phi end |
Instance Method Details
#[](index) ⇒ Array(BasicBlock, Value)
Access the BasicBlock/Value pair at the given index.
171 172 173 174 175 176 177 |
# File 'lib/rltk/cg/instruction.rb', line 171 def [](index) index += self.size if index < 0 if 0 <= index and index < self.size [self.block(index), self.value(index)] end end |
#add(overloaded, value = nil) ⇒ void Also known as: <<
This method returns an undefined value.
Add incoming BasicBlock/Value pairs to a Phi node.
phi.incoming.add(bb, val)
phi.incoming.add(=> val0, bb1 => val1)
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/rltk/cg/instruction.rb', line 191 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) returning(nil) { Bindings.add_incoming(@phi, vals_ptr, blks_ptr, vals.length) } end |
#block(index) ⇒ BasicBlock
Returns Incoming BasicBlock.
216 217 218 219 220 221 222 |
# File 'lib/rltk/cg/instruction.rb', line 216 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 |
#each {|pair| ... } ⇒ Enumerator
An iterator for each incoming BasicBlock/Value pair.
229 230 231 232 233 234 235 |
# File 'lib/rltk/cg/instruction.rb', line 229 def each return to_enum(:each) unless block_given? self.size.times { |index| yield self[index] } self end |
#size ⇒ Integer
Returns Number of incoming BasicBlock/Value pairs.
238 239 240 |
# File 'lib/rltk/cg/instruction.rb', line 238 def size Bindings.count_incoming(@phi) end |
#value(index) ⇒ BasicBlock
Returns Incoming Value.
245 246 247 248 249 250 251 |
# File 'lib/rltk/cg/instruction.rb', line 245 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 |