Package jminusminus

Class CLInstruction

java.lang.Object
jminusminus.CLInstruction
Direct Known Subclasses:
CLArithmeticInstruction, CLArrayInstruction, CLBitInstruction, CLComparisonInstruction, CLConversionInstruction, CLFieldInstruction, CLFlowControlInstruction, CLLoadStoreInstruction, CLMethodInstruction, CLMiscInstruction, CLObjectInstruction, CLStackInstruction

abstract class CLInstruction extends Object
Representation of a JVM instruction. It stores the opcode and mnenomic of an instruction, its operand count (DYNAMIC if the instruction has variable number operands), pc (location counter), stack units (words produced - words consumed from the operand stack), and local variable index (IRRELEVANT if the instruction does not operate on local variables).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final CLInsInfo[]
    For each JVM instruction, this array stores its opcode, mnemonic, number of operands (DYNAMIC for instructions with variable attribute count), local variable index (IRRELEVANT where not applicable), stack units, and instruction category.
    protected int
    Index of the local variable that this instruction refers to; applies only to instructions that operate on local variables.
    protected String
    Mnemonic for this instruction.
    protected int
    Opcode for this instruction.
    protected int
    Number of operands for this instruction; determined statically for all instructions except TABLESWITCH and LOOKUPSWITCH.
    protected int
    Location counter; index of this instruction within the code array of a method.
    protected int
    Stack units; words produced - words consumed from the operand stack by this instruction.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    byteAt(int i, int byteNum)
    Returns the byte from i at position byteNum.
    static boolean
    isValid(int opcode)
    Returns true if the opcode is valid, and false otherwise.
    int
    Returns the local variable index for this instruction.
    Returns the mnemonic for this instruction.
    int
    Returns the opcode for this instruction.
    int
    Returns the number of operands for this instruction.
    int
    pc()
    Returns the pc for this instruction.
    int
    Returns the stack units for this instruction.
    abstract ArrayList<Integer>
    Returns the bytecode for this instruction.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • opcode

      protected int opcode
      Opcode for this instruction.
    • mnemonic

      protected String mnemonic
      Mnemonic for this instruction.
    • operandCount

      protected int operandCount
      Number of operands for this instruction; determined statically for all instructions except TABLESWITCH and LOOKUPSWITCH.
    • pc

      protected int pc
      Location counter; index of this instruction within the code array of a method.
    • stackUnits

      protected int stackUnits
      Stack units; words produced - words consumed from the operand stack by this instruction.
    • localVariableIndex

      protected int localVariableIndex
      Index of the local variable that this instruction refers to; applies only to instructions that operate on local variables.
    • instructionInfo

      public static final CLInsInfo[] instructionInfo
      For each JVM instruction, this array stores its opcode, mnemonic, number of operands (DYNAMIC for instructions with variable attribute count), local variable index (IRRELEVANT where not applicable), stack units, and instruction category. For example, for IMUL, these parameters are IMUL, "imul", 0, IRRELEVANT, -1, ARITHMETIC1.
  • Constructor Details

    • CLInstruction

      CLInstruction()
  • Method Details

    • isValid

      public static boolean isValid(int opcode)
      Returns true if the opcode is valid, and false otherwise.
      Parameters:
      opcode - instruction opcode.
      Returns:
      true if the opcode is valid, and false otherwise.
    • opcode

      public int opcode()
      Returns the opcode for this instruction.
      Returns:
      the opcode for this instruction.
    • mnemonic

      public String mnemonic()
      Returns the mnemonic for this instruction.
      Returns:
      the mnemonic for this instruction.
    • operandCount

      public int operandCount()
      Returns the number of operands for this instruction.
      Returns:
      the number of operands for this instruction.
    • pc

      public int pc()
      Returns the pc for this instruction.
      Returns:
      the pc for this instruction.
    • stackUnits

      public int stackUnits()
      Returns the stack units for this instruction.
      Returns:
      the stack units for this instruction.
    • localVariableIndex

      public int localVariableIndex()
      Returns the local variable index for this instruction.
      Returns:
      the local variable index for this instruction.
    • toBytes

      public abstract ArrayList<Integer> toBytes()
      Returns the bytecode for this instruction.
      Returns:
      the bytecode for this instruction.
    • byteAt

      protected int byteAt(int i, int byteNum)
      Returns the byte from i at position byteNum.
      Parameters:
      i - number whose individual byte is required.
      byteNum - the byte to return (1: lower - 4: higher).
      Returns:
      the byte at the specified position.