Package serp.bytecode
Class InstructionPtrStrategy
- java.lang.Object
-
- serp.bytecode.InstructionPtrStrategy
-
- All Implemented Interfaces:
InstructionPtr
class InstructionPtrStrategy extends java.lang.Object implements InstructionPtr
InstructionPtrStrategy handles the different strategies for finding the Instructions that InstructionPtrs point to. These strategies include, from least desirable to most desirable, using byte indexes, and storing a reference to the target Instruction proper.
-
-
Field Summary
Fields Modifier and Type Field Description private int
_byteIndex
private InstructionPtr
_pointer
private Instruction
_target
-
Constructor Summary
Constructors Constructor Description InstructionPtrStrategy(InstructionPtr pointer)
InstructionPtrStrategy(InstructionPtr pointer, Instruction target)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getByteIndex()
Returns the byteIndex at which the target instruction can be found.Code
getCode()
Returns the Code block that owns the Instruction(s) this InstructionPtr points to.Instruction
getTargetInstruction()
Returns the Instruction this Target is targetting.void
replaceTarget(Instruction oldTarget, Instruction newTarget)
Replace the given old, likely invalid, target with a new target.void
setByteIndex(int index)
Sets the byteIndex where the target Instruction can be found.void
setTargetInstruction(Instruction ins)
Changes the target Instruction.void
updateTargets()
Same as getInstruction, but this method alters the Target strategy to use the returned Instruction.
-
-
-
Field Detail
-
_pointer
private InstructionPtr _pointer
-
_target
private Instruction _target
-
_byteIndex
private int _byteIndex
-
-
Constructor Detail
-
InstructionPtrStrategy
public InstructionPtrStrategy(InstructionPtr pointer)
-
InstructionPtrStrategy
public InstructionPtrStrategy(InstructionPtr pointer, Instruction target)
-
-
Method Detail
-
setByteIndex
public void setByteIndex(int index)
Sets the byteIndex where the target Instruction can be found. This target will now be using byte indices as its target finding strategy, which is the least robust option. Changing the Code block or importing it into another Method may result in an invalid target.
-
setTargetInstruction
public void setTargetInstruction(Instruction ins)
Changes the target Instruction. The target is in the best state possible and should maintain this information even in the face of Code imports and Code changes.
-
getTargetInstruction
public Instruction getTargetInstruction()
Returns the Instruction this Target is targetting. This request does not change the targetting strategy for this Target.
-
getByteIndex
public int getByteIndex()
Returns the byteIndex at which the target instruction can be found. This call does not change the Target strategy.
-
updateTargets
public void updateTargets()
Same as getInstruction, but this method alters the Target strategy to use the returned Instruction. This method alters the Target strategy (and Instruction) iff it was previously using byte indexes.- Specified by:
updateTargets
in interfaceInstructionPtr
-
replaceTarget
public void replaceTarget(Instruction oldTarget, Instruction newTarget)
Description copied from interface:InstructionPtr
Replace the given old, likely invalid, target with a new target. The new target Instruction is guaranteed to be in the same code block as this InstructionPtr.- Specified by:
replaceTarget
in interfaceInstructionPtr
-
getCode
public Code getCode()
Description copied from interface:InstructionPtr
Returns the Code block that owns the Instruction(s) this InstructionPtr points to.- Specified by:
getCode
in interfaceInstructionPtr
-
-