Package ghidra.app.plugin.processors.sleigh

# Class SleighInstructionPrototype

java.lang.Object
ghidra.app.plugin.processors.sleigh.SleighInstructionPrototype

All Implemented Interfaces:
  `InstructionPrototype`

public class SleighInstructionPrototype extends Object implements InstructionPrototype
The InstructionPrototype for sleigh languages. The prototype is unique up to the tree of Constructors. Variations in the bit pattern that none of the Constructor mask/values care about get lumped under the same prototype

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `SleighInstructionPrototype.FlowRecord`
  `static class`
  `SleighInstructionPrototype.FlowSummary`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `BRANCH_INDIRECT`
  `static final int`
  `BRANCH_TO_END`
  `static final int`
  `CALL`
  `static final int`
  `CALL_INDIRECT`
  `static final int`
  `CROSSBUILD`
  `static final int`
  `JUMPOUT`
  `static final int`
  `LABEL`
  `static final int`
  `NO_FALLTHRU`
  `static final int`
  `RETURN`

  ### Fields inherited from interface ghidra.program.model.lang.InstructionPrototype

  `INVALID_DEPTH_CHANGE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SleighInstructionPrototype(SleighLanguage lang, MemBuffer buf, ProcessorContextView context, ContextCache cache, boolean inDelaySlot, SleighDebugLogger debug)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `dumpConstructorTree()`
  Used for testing and diagnostics: list the constructor line numbers used to resolve this encoding This includes braces to describe the tree structure
  `boolean`
  `equals(Object obj)`
  `static FlowType`
  `flowListToFlowType(List<SleighInstructionPrototype.FlowRecord> flowstate)`
  `Address`
  `getAddress(int opIndex, InstructionContext context)`
  If the indicated operand is an address, this gets the address value for that operand
  `int`
  `getDelaySlotByteCount()`
  `int`
  `getDelaySlotDepth(InstructionContext context)`
  Get the number of delay slot instructions for this argument.
  `Address`
  `getFallThrough(InstructionContext context)`
  Get the Address for default flow after instruction.
  `int`
  `getFallThroughOffset(InstructionContext context)`
  Get the byte offset to the default flow after instruction.
  `Address[]`
  `getFlows(InstructionContext context)`
  Get an array of Address objects for all flows other than a fall-through, null if no flows.
  `FlowType`
  `getFlowType(InstructionContext context)`
  Get the flow type of this instruction.
  `Object[]`
  `getInputObjects(InstructionContext context)`
  Get the Result objects produced/affected by this instruction These would probably only be Register or Address
  `Mask`
  `getInstructionMask()`
  Get a Mask that describe which bits of this instruction determine the opcode.
  `Language`
  `getLanguage()`
  Get processor language module associated with this prototype.
  `int`
  `getLength()`
  Get the length of this CodeProtoype.
  `String`
  `getMnemonic(InstructionContext context)`
  Get the mnemonic for this CodeProtype.
  `int`
  `getNumOperands()`
  Return the number of operands in this instruction.
  `RefType`
  `getOperandRefType(int opIndex, InstructionContext context, PcodeOverride override)`
  Get the suggested operand reference type.
  `Mask`
  `getOperandValueMask(int operandIndex)`
  Get a Mask that describe which bits of this instruction determine the operand value.
  `Object[]`
  `getOpObjects(int opIndex, InstructionContext context)`
  Get objects used by this operand (Address, Scalar, Register ...)
  `ArrayList<Object>`
  `getOpRepresentationList(int opIndex, InstructionContext context)`
  Get a List of Objects that can be used to render an operands representation.
  `int`
  `getOpType(int opIndex, InstructionContext context)`
  Get the type of a specific operand.
  `SleighParserContext`
  `getParserContext(MemBuffer buf, ProcessorContextView processorContext)`
  Get a new instance of a ParserContext.
  `PcodeOp[]`
  `getPcode(InstructionContext context, int opIndex)`
  Get an array of PCode operations (micro code) that a particular operand performs to compute its value.
  `PcodeOp[]`
  `getPcode(InstructionContext context, PcodeOverride override)`
  Get an array of PCode operations (micro code) that this instruction performs.
  `void`
  `getPcodePacked(PatchEncoder encoder, InstructionContext context, PcodeOverride override)`
  Same as getPcode but emits the operations directly to an encoder to optimize transfer to other processes
  `ParserContext`
  `getPseudoParserContext(Address addr, MemBuffer buffer, ProcessorContextView processorContext)`
  Get a ParserContext by parsing bytes outside of the normal disassembly process
  `Register`
  `getRegister(int opIndex, InstructionContext context)`
  If the indicated operand is a register, this gets the register value for that operand
  `Object[]`
  `getResultObjects(InstructionContext context)`
  Get the Result objects produced/affected by this instruction These would probably only be Register or Address
  `ConstructState`
  `getRootState()`
  `Scalar`
  `getScalar(int opIndex, InstructionContext context)`
  If the indicated operand is a scalar, this gets the scalar value for that operand
  `String`
  `getSeparator(int opIndex)`
  Get the separator strings between an operand.
  `boolean`
  `hasCrossBuildDependency()`
  `boolean`
  `hasDelaySlots()`
  `boolean`
  `hasDelimeter(int opIndex)`
  Return true if the operand at opIndex should have a delimiter following it.
  `int`
  `hashCode()`
  `boolean`
  `isInDelaySlot()`
  Return true if this prototype was disassembled in a delay slot.
  `static SleighInstructionPrototype.FlowSummary`
  `walkTemplates(OpTplWalker walker)`
  Walk the pcode templates in the order they would be emitted.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### RETURN

    public static final int RETURN
    See Also:
      - Constant Field Values

  - ### CALL_INDIRECT

    public static final int CALL_INDIRECT
    See Also:
      - Constant Field Values

  - ### BRANCH_INDIRECT

    public static final int BRANCH_INDIRECT
    See Also:
      - Constant Field Values

  - ### CALL

    public static final int CALL
    See Also:
      - Constant Field Values

  - ### JUMPOUT

    public static final int JUMPOUT
    See Also:
      - Constant Field Values

  - ### NO_FALLTHRU

    public static final int NO_FALLTHRU
    See Also:
      - Constant Field Values

  - ### BRANCH_TO_END

    public static final int BRANCH_TO_END
    See Also:
      - Constant Field Values

  - ### CROSSBUILD

    public static final int CROSSBUILD
    See Also:
      - Constant Field Values

  - ### LABEL

    public static final int LABEL
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### SleighInstructionPrototype

    public SleighInstructionPrototype(SleighLanguage lang, MemBuffer buf, ProcessorContextView context, ContextCache cache, boolean inDelaySlot, SleighDebugLogger debug) throws UnknownInstructionException, MemoryAccessException
    Throws:
      `UnknownInstructionException`
      `MemoryAccessException`

- ## Method Details

  - ### getLength

    public int getLength()
    Description copied from interface: `InstructionPrototype`
    Get the length of this CodeProtoype.
    Specified by:
      `getLength` in interface `InstructionPrototype`
    Returns:
      the length of this CodeProtoype.

  - ### hasDelaySlots

    public boolean hasDelaySlots()
    Specified by:
      `hasDelaySlots` in interface `InstructionPrototype`
    Returns:
      true if instruction prototype expects one or more delay slotted instructions to exist.

  - ### hasCrossBuildDependency

    public boolean hasCrossBuildDependency()
    Specified by:
      `hasCrossBuildDependency` in interface `InstructionPrototype`
    Returns:
      true if instruction semantics have a CrossBuild instruction dependency which may require a robust InstructionContext with access to preceding instructions

  - ### walkTemplates

    public static SleighInstructionPrototype.FlowSummary walkTemplates(OpTplWalker walker)
    Walk the pcode templates in the order they would be emitted. Collect flowFlags FlowRecords
    Parameters:
      `walker` - the pcode template walker
    Returns:
      a summary of the flow information

  - ### flowListToFlowType

    public static FlowType flowListToFlowType(List<SleighInstructionPrototype.FlowRecord> flowstate)

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### getInstructionMask

    public Mask getInstructionMask()
    Description copied from interface: `InstructionPrototype`
    Get a Mask that describe which bits of this instruction determine the opcode.
    Specified by:
      `getInstructionMask` in interface `InstructionPrototype`
    Returns:
      a Mask for the opcode bits or null if unknown.

  - ### getOperandValueMask

    public Mask getOperandValueMask(int operandIndex)
    Description copied from interface: `InstructionPrototype`
    Get a Mask that describe which bits of this instruction determine the operand value.
    Specified by:
      `getOperandValueMask` in interface `InstructionPrototype`
    Returns:
      a Mask for the operand bits or null if unknown.

  - ### getFlowType

    public FlowType getFlowType(InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get the flow type of this instruction. Used for analysis purposes. i.e., how this instruction flows to the next instruction.
    Specified by:
      `getFlowType` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
    Returns:
      flow type.

  - ### getDelaySlotByteCount

    public int getDelaySlotByteCount()
    Specified by:
      `getDelaySlotByteCount` in interface `InstructionPrototype`
    Returns:
      the number of delay-slot instruction bytes which correspond to this prototype.

  - ### getDelaySlotDepth

    public int getDelaySlotDepth(InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get the number of delay slot instructions for this argument. 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.
    Specified by:
      `getDelaySlotDepth` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
    Returns:
      the number of delay slot instructions for this instruction.

  - ### isInDelaySlot

    public boolean isInDelaySlot()
    Description copied from interface: `InstructionPrototype`
    Return true if this prototype was disassembled in a delay slot.
    Specified by:
      `isInDelaySlot` in interface `InstructionPrototype`

  - ### getNumOperands

    public int getNumOperands()
    Description copied from interface: `InstructionPrototype`
    Return the number of operands in this instruction.
    Specified by:
      `getNumOperands` in interface `InstructionPrototype`

  - ### getOpType

    public int getOpType(int opIndex, InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get the type of a specific operand.
    Specified by:
      `getOpType` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - the index of the operand. (zero based)
      `context` - the instruction context.
    Returns:
      the type of the operand.

  - ### getFallThrough

    public Address getFallThrough(InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get the Address for default flow after instruction.
    Specified by:
      `getFallThrough` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
    Returns:
      Address of fall through flow or null if flow does not fall through this instruction.

  - ### getFallThroughOffset

    public int getFallThroughOffset(InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get the byte offset to the default flow after instruction. If this instruction does not have a fall-through due to flow behavior, this method will still return an offset which accounts for the instruction length including delay slotted instructions if applicable.
    Specified by:
      `getFallThroughOffset` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
    Returns:
      int how much to add to the current address to get the fall through address.

  - ### getFlows

    public Address[] getFlows(InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get an array of Address objects for all flows other than a fall-through, null if no flows.
    Specified by:
      `getFlows` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context.
    Returns:
      an array of Address objects for all flows other than a fall-through, null if no flows.

  - ### getSeparator

    public String getSeparator(int opIndex)
    Description copied from interface: `InstructionPrototype`
    Get the separator strings between an operand. The separator string for 0 are the characters before the first operand. The separator string for numOperands+1 are the characters after the last operand.
    Specified by:
      `getSeparator` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - valid values are 0 thru numOperands+1
    Returns:
      separator string, or null if there is no string

  - ### getOpRepresentationList

    public ArrayList<Object> getOpRepresentationList(int opIndex, InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get a List of Objects that can be used to render an operands representation.
    Specified by:
      `getOpRepresentationList` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - operand to get the Representation List
      `context` - the instruction context
    Returns:
      ArrayList of Register, Address, Scalar, VariableOffset and Character objects of null if the operation isn't supported

  - ### getAddress

    public Address getAddress(int opIndex, InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    If the indicated operand is an address, this gets the address value for that operand
    Specified by:
      `getAddress` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - index of the operand.
      `context` - the instruction context.
    Returns:
      the address indicated by the operand

  - ### getScalar

    public Scalar getScalar(int opIndex, InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    If the indicated operand is a scalar, this gets the scalar value for that operand
    Specified by:
      `getScalar` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - index of the operand.
      `context` - the instruction context
    Returns:
      the scalar for the indicated operand

  - ### getRegister

    public Register getRegister(int opIndex, InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    If the indicated operand is a register, this gets the register value for that operand
    Specified by:
      `getRegister` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - index of the operand.
      `context` - the instruction context
    Returns:
      a register description for the indicated operand

  - ### getOpObjects

    public Object[] getOpObjects(int opIndex, InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get objects used by this operand (Address, Scalar, Register ...)
    Specified by:
      `getOpObjects` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - the index of the operand. (zero based)
      `context` - the instruction context
    Returns:
      an array of objects found at this operand.

  - ### hasDelimeter

    public boolean hasDelimeter(int opIndex)
    Description copied from interface: `InstructionPrototype`
    Return true if the operand at opIndex should have a delimiter following it.
    Specified by:
      `hasDelimeter` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - the index of the operand to test for having a delimiter.

  - ### getInputObjects

    public Object[] getInputObjects(InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get the Result objects produced/affected by this instruction These would probably only be Register or Address
    Specified by:
      `getInputObjects` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
    Returns:
      an array of objects that are used by this instruction

  - ### getResultObjects

    public Object[] getResultObjects(InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get the Result objects produced/affected by this instruction These would probably only be Register or Address
    Specified by:
      `getResultObjects` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
    Returns:
      an array of objects that are affected by this instruction

  - ### getPcode

    public PcodeOp[] getPcode(InstructionContext context, PcodeOverride override)
    Description copied from interface: `InstructionPrototype`
    Get an array of PCode operations (micro code) that this instruction performs.
    Specified by:
      `getPcode` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
      `override` - if not null, may indicate that different elements of the pcode generation are overridden
    Returns:
      array of PCODE, zero length array if language doesn't support PCODE for this instruction

  - ### getPcodePacked

    public void getPcodePacked(PatchEncoder encoder, InstructionContext context, PcodeOverride override) throws IOException
    Description copied from interface: `InstructionPrototype`
    Same as getPcode but emits the operations directly to an encoder to optimize transfer to other processes
    Specified by:
      `getPcodePacked` in interface `InstructionPrototype`
    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

    public PcodeOp[] getPcode(InstructionContext context, int opIndex)
    Description copied from interface: `InstructionPrototype`
    Get an array of PCode operations (micro code) that a particular operand performs to compute its value.
    Specified by:
      `getPcode` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
      `opIndex` - the index of the operand for which to get PCode.
    Returns:
      array of PCODE, zero length array if language doesn't support PCODE for this instruction

  - ### getOperandRefType

    public RefType getOperandRefType(int opIndex, InstructionContext context, PcodeOverride override)
    Description copied from interface: `InstructionPrototype`
    Get the suggested operand reference type.
    Specified by:
      `getOperandRefType` in interface `InstructionPrototype`
    Parameters:
      `opIndex` - the index of the operand. (zero based)
      `context` - the instruction context
      `override` - if not null, steers local overrides of pcode generation
    Returns:
      reference type.

  - ### getMnemonic

    public String getMnemonic(InstructionContext context)
    Description copied from interface: `InstructionPrototype`
    Get the mnemonic for this CodeProtype. Examples: "MOV" and "CALL" for instructions and "DB" and "DA" for data.
    Specified by:
      `getMnemonic` in interface `InstructionPrototype`
    Parameters:
      `context` - the instruction context
    Returns:
      the mnemonic for this CodePrototype.

  - ### getParserContext

    public SleighParserContext getParserContext(MemBuffer buf, ProcessorContextView processorContext) throws MemoryAccessException
    Description copied from interface: `InstructionPrototype`
    Get a new instance of a ParserContext.
    Specified by:
      `getParserContext` in interface `InstructionPrototype`
    Parameters:
      `buf` -
      `processorContext` -
    Returns:
      instruction ParserContext
    Throws:
      `MemoryAccessException`

  - ### getPseudoParserContext

    public ParserContext getPseudoParserContext(Address addr, MemBuffer buffer, ProcessorContextView processorContext) throws InsufficientBytesException, UnknownInstructionException, UnknownContextException, MemoryAccessException
    Description copied from interface: `InstructionPrototype`
    Get a ParserContext by parsing bytes outside of the normal disassembly process
    Specified by:
      `getPseudoParserContext` in interface `InstructionPrototype`
    Parameters:
      `addr` - where the ParserContext is needed
      `buffer` - of actual bytes
      `processorContext` -
    Returns:
    Throws:
      `InsufficientBytesException`
      `UnknownInstructionException`
      `UnknownContextException`
      `MemoryAccessException`

  - ### getRootState

    public ConstructState getRootState()

  - ### getLanguage

    public Language getLanguage()
    Description copied from interface: `InstructionPrototype`
    Get processor language module associated with this prototype.
    Specified by:
      `getLanguage` in interface `InstructionPrototype`
    Returns:
      language module

  - ### dumpConstructorTree

    public String dumpConstructorTree()
    Used for testing and diagnostics: list the constructor line numbers used to resolve this encoding This includes braces to describe the tree structure
    Returns:
      the constructor tree
    See Also:
      - `AssemblyResolvedPatterns.dumpConstructorTree()`