Package com.tonic.analysis.instruction
Class LdcInstruction
- java.lang.Object
-
- com.tonic.analysis.instruction.Instruction
-
- com.tonic.analysis.instruction.LdcInstruction
-
public class LdcInstruction extends Instruction
Represents the LDC instruction (0x12).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLdcInstruction.ConstantTypeThe kinds of constant-pool entry an ldc-family instruction can load.
-
Constructor Summary
Constructors Constructor Description LdcInstruction(ConstPool constPool, int opcode, int offset, int cpIndex)Constructs an LdcInstruction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(AbstractBytecodeVisitor visitor)Accepts a visitor for bytecode analysis.LdcInstruction.ConstantTypegetConstantType()Classifies the referenced constant-pool entry.ConstPoolgetConstPool()intgetCpIndex()intgetLocalChange()Returns the change in local variables caused by this instruction.intgetStackChange()Returns the change in stack size caused by this instruction.StringresolveConstant()Resolves and returns a string representation of the constant.StringtoString()Returns a string representation of the instruction.voidwrite(DataOutputStream dos)Writes the LDC opcode and its operand to the DataOutputStream.-
Methods inherited from class com.tonic.analysis.instruction.Instruction
getLength, getOffset, getOpcode, setOffset
-
-
-
-
Constructor Detail
-
LdcInstruction
public LdcInstruction(ConstPool constPool, int opcode, int offset, int cpIndex)
Constructs an LdcInstruction.- Parameters:
constPool- The constant pool associated with the class.opcode- The nominal opcode (ignored; the form is derived fromcpIndex).offset- The bytecode offset of the instruction.cpIndex- The constant pool index.
-
-
Method Detail
-
getCpIndex
public int getCpIndex()
- Returns:
- the cp index
-
getConstPool
public ConstPool getConstPool()
- Returns:
- the const pool
-
accept
public void accept(AbstractBytecodeVisitor visitor)
Description copied from class:InstructionAccepts a visitor for bytecode analysis.- Specified by:
acceptin classInstruction- Parameters:
visitor- The visitor to accept.
-
write
public void write(DataOutputStream dos) throws IOException
Writes the LDC opcode and its operand to the DataOutputStream.- Specified by:
writein classInstruction- Parameters:
dos- The DataOutputStream to write to.- Throws:
IOException- If an I/O error occurs.
-
getStackChange
public int getStackChange()
Returns the change in stack size caused by this instruction.- Specified by:
getStackChangein classInstruction- Returns:
- The stack size change (pushes a reference or primitive).
-
getConstantType
public LdcInstruction.ConstantType getConstantType()
Classifies the referenced constant-pool entry.- Returns:
- the constant kind, or UNKNOWN for an invalid index or unrecognized entry
-
getLocalChange
public int getLocalChange()
Returns the change in local variables caused by this instruction.- Specified by:
getLocalChangein classInstruction- Returns:
- The local variables size change (none).
-
resolveConstant
public String resolveConstant()
Resolves and returns a string representation of the constant.- Returns:
- The constant as a string.
-
toString
public String toString()
Returns a string representation of the instruction.- Overrides:
toStringin classInstruction- Returns:
- The mnemonic, constant pool index, and resolved constant.
-
-