Class: RLTK::CG::PhiInst::IncomingCollection
- Inherits:
-
Object
- Object
- 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.
177 178 179 |
# File 'lib/rltk/cg/instruction.rb', line 177 def initialize(phi) @phi = phi end |
Instance Method Details
#[](index) ⇒ Array(BasicBlock, Value)
Access the BasicBlock/Value pair at the given index.
186 187 188 189 190 191 192 |
# 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(overloaded, value = nil) ⇒ void Also known as: <<
This method returns an undefined value.
Add incoming BasicBlock/Value pairs to a Phi node.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# 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 |
#block(index) ⇒ BasicBlock
Returns Incoming BasicBlock.
231 232 233 234 235 236 237 |
# 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 |
#each {|pair| ... } ⇒ Enumerator
An iterator for each incoming BasicBlock/Value pair.
244 245 246 247 248 249 250 |
# 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 |
#size ⇒ Integer
Returns Number of incoming BasicBlock/Value pairs.
253 254 255 |
# File 'lib/rltk/cg/instruction.rb', line 253 def size Bindings.count_incoming(@phi) end |
#value(index) ⇒ BasicBlock
Returns Incoming Value.
260 261 262 263 264 265 266 |
# 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 |