Package com.tonic.analysis.ssa.ir
Class SwitchInstruction
- java.lang.Object
-
- com.tonic.analysis.ssa.ir.IRInstruction
-
- com.tonic.analysis.ssa.ir.SwitchInstruction
-
public class SwitchInstruction extends IRInstruction
A multi-way branch on an int key, covering both tableswitch and lookupswitch.
-
-
Constructor Summary
Constructors Constructor Description SwitchInstruction(Value key, IRBlock defaultTarget)Creates a switch with no cases yet and registers a use of an SSA key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(IRVisitor<T> visitor)Accepts a visitor for this instruction.voidaddCase(int value, IRBlock target)Adds a case to the switch instruction.IRBlockgetCase(int value)Gets the target block for a specific case value.Map<Integer,IRBlock>getCases()IRBlockgetDefaultTarget()ValuegetKey()List<Value>getOperands()Gets the operands used by this instruction.booleanisTerminator()Checks if this instruction terminates a basic block.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.voidsetDefaultTarget(IRBlock defaultTarget)StringtoString()-
Methods inherited from class com.tonic.analysis.ssa.ir.IRInstruction
copyWithNewOperands, equals, getBlock, getBytecodeOffset, getId, getResult, getResultType, hashCode, hasResult, isPhi, resetIdCounter, setBlock, setBytecodeOffset, setResult
-
-
-
-
Method Detail
-
getKey
public Value getKey()
- Returns:
- the key
-
getDefaultTarget
public IRBlock getDefaultTarget()
- Returns:
- the default target
-
setDefaultTarget
public void setDefaultTarget(IRBlock defaultTarget)
- Parameters:
defaultTarget- the block taken when no case matches
-
addCase
public void addCase(int value, IRBlock target)Adds a case to the switch instruction.- Parameters:
value- the case valuetarget- the target block for this case
-
getCase
public IRBlock getCase(int value)
Gets the target block for a specific case value.- Parameters:
value- the case value- Returns:
- the target block, or default target if not found
-
getOperands
public List<Value> getOperands()
Description copied from class:IRInstructionGets the operands used by this instruction.- Specified by:
getOperandsin classIRInstruction- Returns:
- list of operand values
-
replaceOperand
public void replaceOperand(Value oldValue, Value newValue)
Description copied from class:IRInstructionReplaces an operand value with a new value.- Specified by:
replaceOperandin classIRInstruction- Parameters:
oldValue- the value to replacenewValue- the replacement value
-
accept
public <T> T accept(IRVisitor<T> visitor)
Description copied from class:IRInstructionAccepts a visitor for this instruction.- Specified by:
acceptin classIRInstruction- Type Parameters:
T- the return type- Parameters:
visitor- the visitor to accept- Returns:
- the visitor result
-
isTerminator
public boolean isTerminator()
Description copied from class:IRInstructionChecks if this instruction terminates a basic block.- Overrides:
isTerminatorin classIRInstruction- Returns:
- true if this is a terminator instruction
-
replaceTarget
public void replaceTarget(IRBlock oldTarget, IRBlock newTarget)
Description copied from class:IRInstructionReplaces a target block in terminator instructions.- Overrides:
replaceTargetin classIRInstruction- Parameters:
oldTarget- the block to replacenewTarget- the replacement block
-
-