class RLTK::CG::Instruction
This class represents LLVM
IR instructions.
Constants
- TESTABLE
Many of the C functions for interacting with instructions treat all instructions as
Instruction
objects. However, someInstruction
sub-types can be tested for. This is a list of those sub-types and the names of their tests.
Public Class Methods
Instantiate an Instruction
object from a given pointer. The type of the instruction is tested and the appropriate sub-type is picked if possible. If not, a generic Instruction
object is returned.
@param [FFI::Pointer] ptr Pointer to a C instruction object.
@return [Instruction] An Instruction
or one of its sub-types.
# File lib/rltk/cg/instruction.rb, line 66 def self.from_ptr(ptr) match = nil TESTABLE.each do |el| klass, test = if el.is_a?(Symbol) [RLTK::CG.const_get("#{el}Inst".to_sym), Bindings.get_bname("IsA#{el}Inst")] else [RLTK::CG.const_get("#{el.first}Inst".to_sym), Bindings.get_bname("IsA#{el.last}Inst")] end match = klass if Bindings.send(test, ptr) end if match then match else Intruction end.new(ptr) end
You should never instantiate Instruction
object directly. Use the builder class to add new instructions.
@param [FFI::Pointer] ptr Pointer to a C instruction object.
# File lib/rltk/cg/instruction.rb, line 88 def initialize(ptr) @ptr = check_type(ptr, FFI::Pointer, 'ptr') end
Public Instance Methods
@return [Instruction, nil] Instruction
that follows the current one in a {BasicBlock}.
# File lib/rltk/cg/instruction.rb, line 93 def next if (ptr = Bindings.get_next_instruction(@ptr)).null? then nil else Instruction.from_ptr(ptr) end end
@return [BasicBlock] BasicBlock
that contains this Instruction
.
# File lib/rltk/cg/instruction.rb, line 98 def parent if (ptr = Bindings.get_instruction_parent(@ptr)).null? then nil else BasicBlock.new(ptr) end end
@return [Instruction, nil] Instruction
that precedes the current on in a {BasicBlock}.
# File lib/rltk/cg/instruction.rb, line 103 def previous if (ptr = Bindings.get_previous_instruction(@ptr)).null? then nil else Instruction.from_ptr(ptr) end end