Interface InstructionPrototype

All Known Implementing Classes:
InvalidPrototype, SleighInstructionPrototype

public interface InstructionPrototype
InstructionPrototype is designed to describe one machine level instruction. A language parser can return the same InstructionProtoype object for the same type node. Prototypes for instructions will normally be fixed for a node.
  • Field Details

    • INVALID_DEPTH_CHANGE

      static final int INVALID_DEPTH_CHANGE
      Sentinel value to indicate an invalid depth change
      See Also:
  • Method Details

    • getParserContext

      ParserContext getParserContext(MemBuffer buf, ProcessorContextView processorContext) throws MemoryAccessException
      Returns a new instance of an instruction ParserContext.
      Parameters:
      buf - the memory from which this prototype was parsed, or an equivalent cache
      processorContext - the (incoming) processor context during parse
      Returns:
      a new instance of an instruction ParserContext
      Throws:
      MemoryAccessException - if the memory buffer cannot be accessed
    • getPseudoParserContext

      Returns a ParserContext by parsing bytes outside of the normal disassembly process.
      Parameters:
      address - where the ParserContext is needed, i.e., the first address of an instruction to be parsed
      buffer - of actual bytes
      processorContext - the (incoming) processor context
      Returns:
      a ParserContext by parsing bytes outside of the normal disassembly process
      Throws:
      InsufficientBytesException - if not enough bytes are in the buffer
      UnknownInstructionException - if the bytes do not constitute a valid instruction
      UnknownContextException - if contextual dependencies, e.g. crossbuild instructions, are not available
      MemoryAccessException - if the memory buffer cannot be accessed
    • hasDelaySlots

      boolean hasDelaySlots()
      Returns true if instruction prototype expects one or more delay slotted instructions to exist.
      Returns:
      true if instruction prototype expects one or more delay slotted instructions to exist
    • hasCrossBuildDependency

      boolean hasCrossBuildDependency()
      Returns true if instruction semantics have a crossbuild instruction dependency which may require a robust InstructionContext with access to preceding instructions.
      Returns:
      true if instruction semantics have a crossbuild instruction dependency which may require a robust InstructionContext with access to preceding instructions
    • hasNext2Dependency

      boolean hasNext2Dependency()
      Returns true if instruction semantics contain a reference to inst_next2..
      Returns:
      true if instruction semantics contain a reference to inst_next2
    • getMnemonic

      String getMnemonic(InstructionContext context)
      Returns the mnemonic for this prototype.

      Examples: "MOV" and "CALL"

      Parameters:
      context - the instruction context
      Returns:
      the mnemonic for this prototype
    • getLength

      int getLength()
      Returns the length in bytes of this prototype.
      Returns:
      the length in bytes of this prototype
    • getInstructionMask

      Mask getInstructionMask()
      Returns the Mask that describe which bits of this instruction determine the opcode, or null if unknown.
      Returns:
      the Mask that describe which bits of this instruction determine the opcode, or null if unknown
    • getOperandValueMask

      Mask getOperandValueMask(int operandIndex)
      Returns the Mask that describe which bits of this instruction determine a specific operand's value, or null if unknown.
      Parameters:
      operandIndex - the 0-up index of the operand
      Returns:
      the Mask that describe which bits of this instruction determine a specific operand's value, or null if unknown
    • getFlowType

      FlowType getFlowType(InstructionContext context)
      Returns the flow type of this instruction.

      This is used for analysis purposes. i.e., how this instruction flows to the next instruction.

      Parameters:
      context - the instruction context
      Returns:
      the flow type of this instruction
    • getDelaySlotDepth

      int getDelaySlotDepth(InstructionContext context)
      Returns the number of delay slot instructions following this instruction.

      This should be 0 for instructions which don't have a delay slot. This is used to support the delay slots found on some RISC processors such as SPARC and the PA-RISC. This returns an integer instead of a boolean in case some other processor executes more than one instruction from a delay slot.

      Parameters:
      context - the instruction context
      Returns:
      the number of delay slot instructions following this instruction
    • getDelaySlotByteCount

      int getDelaySlotByteCount()
      Returns the number of delay-slot instruction bytes which correspond to this prototype.
      Returns:
      the number of delay-slot instruction bytes which correspond to this prototype
    • isInDelaySlot

      boolean isInDelaySlot()
      Returns true if this prototype was disassembled in a delay slot.
      Returns:
      true if this prototype was disassembled in a delay slot
    • getNumOperands

      int getNumOperands()
      Returns the number of operands in this instruction.
      Returns:
      the number of operands in this instruction
    • getOpType

      int getOpType(int operandIndex, InstructionContext context)
      Returns the type of a specific operand.
      Parameters:
      operandIndex - the 0-up index of the operand
      context - the instruction context.
      Returns:
      the type of a specific operand
    • getFallThrough

      Address getFallThrough(InstructionContext context)
      Returns the Address for fall-through flow after this instruction, or null if flow cannot fall through this instruction.
      Parameters:
      context - the instruction context
      Returns:
      the Address for fall-through flow after this instruction, or null if flow cannot fall through this instruction
    • getFallThroughOffset

      int getFallThroughOffset(InstructionContext context)
      Returns the byte offset to the fall-through flow after this instruction.

      Ordinarily, this is just the length (in bytes) of this instruction. However, if this instruction has delay-slotted instruction(s), their lengths are included. Even if flow cannot fall through this instruction, this method will still return a the fall-through offset.

      Parameters:
      context - the instruction context
      Returns:
      the byte offset to the fall-through flow after this instruction
    • getFlows

      Address[] getFlows(InstructionContext context)
      Returns the Addresses for all flows other than a fall-through, or null if no flows.

      A null return is equivalent to an empty array. Note the result may include Address.NO_ADDRESS to indicate flow to an address that could not be evaluated, e.g., to inst_next2 when the skipped instruction could not be parsed.

      Parameters:
      context - the instruction context.
      Returns:
      the Addresses for all flows other than a fall-through, or null if no flows
    • getSeparator

      String getSeparator(int operandIndex)
      Returns the separator string before a specific operand, or null.

      In particular, the separator string for operand 0 are the characters before the first operand. The separator string for numOperands are the characters after the last operand. A null return value is equivalent to an empty string.

      Parameters:
      operandIndex - valid values are 0 thru numOperands, inclusive
      Returns:
      the separator string before a specific operand, or null
    • getOpRepresentationList

      ArrayList<Object> getOpRepresentationList(int operandIndex, InstructionContext context)
      Returns a the objects for rendering an operand's representation.

      Each element is one of Address, Register, Scalar, VariableOffset, Character, or null. This method may also return null (as in no list at all) if the operation is not supported. Nulls should be rendered as empty strings.

      Parameters:
      operandIndex - the 0-up index of the operand
      context - the instruction context
      Returns:
      a the objects for rendering an operand's representation
    • getAddress

      Address getAddress(int operandIndex, InstructionContext context)
      Returns the Address value of a specific operand, or null if its value is not an Address.
      Parameters:
      operandIndex - the 0-up index of the operand
      context - the instruction context.
      Returns:
      the Address value of a specific operand, or null if its value is not an Address
    • getRegister

      Register getRegister(int operandIndex, InstructionContext context)
      Returns the Register value of a specific operand, or null if its value is not an Register.
      Parameters:
      operandIndex - the 0-up index of the operand
      context - the instruction context
      Returns:
      the Register value of a specific operand, or null if its value is not an Register
    • getScalar

      Scalar getScalar(int operandIndex, InstructionContext context)
      Returns the Scalar value of a specific operand, or null if its value is not an Scalar.
      Parameters:
      operandIndex - the 0-up index of the operand
      context - the instruction context
      Returns:
      the Scalar value of a specific operand, or null if its value is not an Scalar
    • getOpObjects

      Object[] getOpObjects(int operandIndex, InstructionContext context)
      Returns the objects used by a specific operand.

      Each element is one of Address, Register, Scalar, or VariableOffset.

      Parameters:
      operandIndex - the 0-up index of the operand
      context - the instruction context
      Returns:
      the objects used by a specific operand
    • getOperandRefType

      RefType getOperandRefType(int operandIndex, InstructionContext context, PcodeOverride override)
      Returns the suggested reference type for a specific operand.
      Parameters:
      operandIndex - the 0-up index of the operand
      context - the instruction context
      override - if not null, steers local overrides of p-code generation
      Returns:
      the suggested reference type for a specific operand
    • hasDelimeter

      boolean hasDelimeter(int operandIndex)
      Returns true if a specific operand ought to have a delimiter following it.
      Parameters:
      operandIndex - the 0-up index of the operand
      Returns:
      true if a specific operand ought to have a delimiter following it
    • getInputObjects

      Object[] getInputObjects(InstructionContext context)
      Returns the objects used as input by this instruction.

      Each element should probably only be one of Address or Register.

      Parameters:
      context - the instruction context
      Returns:
      the objects used as input by this instruction
    • getResultObjects

      Object[] getResultObjects(InstructionContext context)
      Returns the objects affected by this instruction.

      Each element should probably only be one of Address or Register.

      Parameters:
      context - the instruction context
      Returns:
      the objects affected by this instruction
    • getPcode

      PcodeOp[] getPcode(InstructionContext context, PcodeOverride override)
      Returns the p-code operations (micro code) that this instruction performs.

      This will return an empty array if the language does not support p-code for this instruction.

      Parameters:
      context - the instruction context
      override - if not null, may indicate that different elements of the pcode generation are overridden
      Returns:
      the p-code operations (micro code) that this instruction performs
    • getPcodePacked

      void getPcodePacked(PatchEncoder encoder, InstructionContext context, PcodeOverride override) throws IOException
      Does the same as getPcode(InstructionContext, PcodeOverride) but emits the operations directly to an encoder to optimize transfer to other processes}
      Parameters:
      encoder - is the encoder receiving the operations
      context - the instruction context
      override - if not null, may indicate that different elements of the pcode generation are overridden
      Throws:
      IOException - for errors writing to any stream underlying the encoder
    • getPcode

      PcodeOp[] getPcode(InstructionContext context, int operandIndex)
      Returns the p-code operations (micro code) that perform the computation of a particular operand's value.
      Parameters:
      context - the instruction context
      operandIndex - the 0-up index of the operand
      Returns:
      the p-code operations (micro code) that perform the computation of a particular operand's value
    • getLanguage

      Language getLanguage()
      Returns the processor language module associated with this prototype.
      Returns:
      the processor language module associated with this prototype