Package com.tonic.analysis.ssa.ir
Class IRInstruction
- java.lang.Object
-
- com.tonic.analysis.ssa.ir.IRInstruction
-
- Direct Known Subclasses:
ArrayAccessInstruction,BinaryOpInstruction,BranchInstruction,ConstantInstruction,CopyInstruction,FieldAccessInstruction,InvokeInstruction,LoadLocalInstruction,NewArrayInstruction,NewInstruction,PhiInstruction,ReturnInstruction,SimpleInstruction,StoreLocalInstruction,SwitchInstruction,TypeCheckInstruction,UnaryOpInstruction
public abstract class IRInstruction extends Object
Base class for all IR instructions, carrying an id, owning block, optional result, and bytecode offset.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract <T> Taccept(IRVisitor<T> visitor)Accepts a visitor for this instruction.IRInstructioncopyWithNewOperands(SSAValue newResult, List<Value> newOperands)Creates a copy of this instruction with new result and operands.booleanequals(Object o)Identity byid.IRBlockgetBlock()intgetBytecodeOffset()Stamped by the lifter so SSA instructions can be correlated back to their source bytecode (e.g.intgetId()abstract List<Value>getOperands()Gets the operands used by this instruction.SSAValuegetResult()IRTypegetResultType()Gets the type of the result value.inthashCode()booleanhasResult()Checks if this instruction produces a result value.booleanisPhi()Checks if this is a phi instruction.booleanisTerminator()Checks if this instruction terminates a basic block.abstract voidreplaceOperand(Value oldValue, Value newValue)Replaces an operand value with a new value.voidreplaceTarget(IRBlock oldTarget, IRBlock newTarget)Replaces a target block in terminator instructions.static voidresetIdCounter()Resets the instruction ID counter.voidsetBlock(IRBlock block)voidsetBytecodeOffset(int bytecodeOffset)voidsetResult(SSAValue result)
-
-
-
Method Detail
-
getId
public int getId()
- Returns:
- the id
-
getBlock
public IRBlock getBlock()
- Returns:
- the block
-
setBlock
public void setBlock(IRBlock block)
- Parameters:
block- the block containing this instruction
-
getResult
public SSAValue getResult()
- Returns:
- the result
-
setResult
public void setResult(SSAValue result)
- Parameters:
result- the SSA value produced by this instruction, or null for none
-
getBytecodeOffset
public int getBytecodeOffset()
Stamped by the lifter so SSA instructions can be correlated back to their source bytecode (e.g. data-flow provenance).- Returns:
- the originating bytecode offset, or -1 when unknown
-
setBytecodeOffset
public void setBytecodeOffset(int bytecodeOffset)
- Parameters:
bytecodeOffset- the originating bytecode offset, or -1 when unknown
-
getOperands
public abstract List<Value> getOperands()
Gets the operands used by this instruction.- Returns:
- list of operand values
-
replaceOperand
public abstract void replaceOperand(Value oldValue, Value newValue)
Replaces an operand value with a new value.- Parameters:
oldValue- the value to replacenewValue- the replacement value
-
accept
public abstract <T> T accept(IRVisitor<T> visitor)
Accepts a visitor for this instruction.- Type Parameters:
T- the return type- Parameters:
visitor- the visitor to accept- Returns:
- the visitor result
-
hasResult
public boolean hasResult()
Checks if this instruction produces a result value.- Returns:
- true if instruction has a result
-
getResultType
public IRType getResultType()
Gets the type of the result value.- Returns:
- the result type, or null if no result
-
isTerminator
public boolean isTerminator()
Checks if this instruction terminates a basic block.- Returns:
- true if this is a terminator instruction
-
isPhi
public boolean isPhi()
Checks if this is a phi instruction.- Returns:
- true if this is a phi instruction
-
resetIdCounter
public static void resetIdCounter()
Resets the instruction ID counter.
-
copyWithNewOperands
public IRInstruction copyWithNewOperands(SSAValue newResult, List<Value> newOperands)
Creates a copy of this instruction with new result and operands.- Parameters:
newResult- the new result value (may be null)newOperands- the new operand values- Returns:
- a copy of this instruction, or null if copying not supported
-
-