Class: RLTK::CG::Instruction
- Defined in:
- lib/rltk/cg/instruction.rb
Overview
This class represents LLVM IR instructions.
Direct Known Subclasses
ARightShiftInst, AddInst, AllocaInst, AndInst, ArrayAllocaInst, ArrayMallocInst, BitCastInst, BranchInst, CallInst, CondBranchInst, ExactSDivInst, ExtractElementInst, ExtractValueInst, FAddInst, FCmpInst, FDivInst, FMulInst, FNegInst, FPCastInst, FPExtendInst, FPToSIInst, FPToUIInst, FPTruncInst, FRemInst, FSubInst, FreeInst, GetElementPtrInst, GlobalStringInst, GlobalStringPtrInst, InBoundsGEPInst, InsertElementInst, InsertValueInst, IntCastInst, IntCmpInst, IntToPtrInst, InvokeInst, IsNotNullInst, IsNullInstInst, LRightShiftInst, LeftShiftInst, LoadInst, MallocInst, MulInst, NSWAddInst, NSWMulInst, NSWNegInst, NSWSubInst, NUWAddInst, NUWMulInst, NUWNegInst, NUWSubInst, NegInst, NotInst, OrInst, PhiInst, PtrCastInst, PtrDiffInst, PtrToIntInst, ReturnAggregateInst, ReturnInst, ReturnVoidInst, SDivInst, SIToFPInst, SRemInst, SelectInst, ShuffleVectorInst, SignExtendInst, SignExtendOrBitCastInst, StoreInst, StructGEPInst, SubInst, SwitchInst, TruncateInst, TruncateOrBitCastInst, UDivInst, UIToFPInst, URemInst, UnreachableInst, XOrInst, ZeroExtendInst, ZeroExtendOrBitCastInst
Constant Summary collapse
- TESTABLE =
Many of the C functions for interacting with instructions treat all instructions as Instruction objects. However, some Instruction sub-types can be tested for. This is a list of those sub-types and the names of their tests.
[ :Alloca, :BitCast, :Call, :ExtractElement, :ExtractValue, :FCmp, [:FPExtend, :FPExt], :FPToSI, :FPToUI, :FPTrunc, :GetElementPtr, [:IntCmp, :ICmp], :InsertElement, :InsertValue, :IntToPtr, :Invoke, :Load, :PtrToInt, :Return, [:SignExtend, :SExt], :SIToFP, :Select, :ShuffleVector, :Store, :Switch, [:Truncate, :Trunc], :UIToFP, :Unreachable ]
Instance Attribute Summary
Attributes included from BindingClass
Class Method Summary collapse
-
.from_ptr(ptr) ⇒ Instruction
Instantiate an Instruction object from a given pointer.
Instance Method Summary collapse
-
#initialize(ptr) ⇒ Instruction
constructor
You should never instantiate Instruction object directly.
-
#next ⇒ Instruction?
Instruction that follows the current one in a BasicBlock.
-
#parent ⇒ BasicBlock
BasicBlock that contains this Instruction.
-
#previous ⇒ Instruction?
Instruction that precedes the current on in a BasicBlock.
Methods inherited from User
Methods included from AbstractClass
Methods inherited from Value
#==, #attributes, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #type, #undefined?, #zextend, #zextend_or_bitcast
Methods included from BindingClass
Constructor Details
#initialize(ptr) ⇒ Instruction
You should never instantiate Instruction object directly. Use the builder class to add new instructions.
87 88 89 |
# File 'lib/rltk/cg/instruction.rb', line 87 def initialize(ptr) @ptr = check_type(ptr, FFI::Pointer, 'ptr') end |
Class Method Details
.from_ptr(ptr) ⇒ Instruction
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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rltk/cg/instruction.rb', line 65 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 |
Instance Method Details
#next ⇒ Instruction?
Returns Instruction that follows the current one in a BasicBlock.
92 93 94 |
# File 'lib/rltk/cg/instruction.rb', line 92 def next if (ptr = Bindings.get_next_instruction(@ptr)).null? then nil else Instruction.from_ptr(ptr) end end |
#parent ⇒ BasicBlock
Returns BasicBlock that contains this Instruction.
97 98 99 |
# File 'lib/rltk/cg/instruction.rb', line 97 def parent if (ptr = Bindings.get_instruction_parent(@ptr)).null? then nil else BasicBlock.new(ptr) end end |
#previous ⇒ Instruction?
Returns Instruction that precedes the current on in a BasicBlock.
102 103 104 |
# File 'lib/rltk/cg/instruction.rb', line 102 def previous if (ptr = Bindings.get_previous_instruction(@ptr)).null? then nil else Instruction.from_ptr(ptr) end end |