Package ghidra.app.plugin.processors.sleigh

# Class SleighLanguage

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

All Implemented Interfaces:
  `Language`

public class SleighLanguage extends Object implements Language

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `SLA_FORMAT_VERSION`
  SLA_FORMAT_VERSION will be incremented whenever the format of the .sla files change.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `applyContextSettings(DefaultProgramContext programContext)`
  Apply context settings to the ProgramContext as specified by the configuration
  `void`
  `encodeTranslator(Encoder encoder, AddressFactory factory, long uniqueOffset)`
  Encode limited information to the stream about the SLEIGH translator for the specified address factory and optional register set.
  `List<InjectPayloadSleigh>`
  `getAdditionalInject()`
  `AddressFactory`
  `getAddressFactory()`
  Get the AddressFactory for this language.
  `List<CompilerSpecDescription>`
  `getCompatibleCompilerSpecDescriptions()`
  Returns a list of all compatible compiler spec descriptions.
  `CompilerSpec`
  `getCompilerSpecByID(CompilerSpecID compilerSpecID)`
  Returns the compiler spec associated with a given CompilerSpecID.
  `Register`
  `getContextBaseRegister()`
  Returns processor context base register or null if one has not been defined by the language.
  `List<Register>`
  `getContextRegisters()`
  Get an unsorted unmodifiable list of processor context registers that this language defines (includes context base register and its context field registers).
  `CompilerSpec`
  `getDefaultCompilerSpec()`
  Returns the default compiler spec for this language, which is used when a loader cannot determine the compiler spec or for upgrades when a program had no compiler spec registered (seriously old program, like Ghidra 4.1 or earlier).
  `AddressSpace`
  `getDefaultDataSpace()`
  Get the preferred data space used by loaders for data sections.
  `MemoryBlockDefinition[]`
  `getDefaultMemoryBlocks()`
  Returns the default memory blocks for this language.
  `int`
  `getDefaultPointerWordSize()`
  Deprecated.
  Will be removed once we have better way to attach address spaces to pointer data-types
  `AddressSpace`
  `getDefaultSpace()`
  Get the default memory/code space.
  `List<AddressLabelInfo>`
  `getDefaultSymbols()`
  Returns the default symbols for this language.
  `int`
  `getInstructionAlignment()`
  Get instruction alignment in terms of bytes.
  `LanguageDescription`
  `getLanguageDescription()`
  Returns the LanguageDescription of this language, which contains useful information about the characteristics of the language.
  `LanguageID`
  `getLanguageID()`
  Returns the LanguageID of this language, which is used as a primary key to find the language when Ghidra loads it.
  `ManualEntry`
  `getManualEntry(String instruction)`
  Get the ManualEntry for the given instruction mnemonic.
  `Exception`
  `getManualException()`
  Returns the exception generated trying to load the manual, or null if it succeeded.
  `Set<String>`
  `getManualInstructionMnemonicKeys()`
  Returns a read-only set view of the instruction mnemonic keys defined on this language.
  `int`
  `getMinorVersion()`
  Returns the minor version for this language.
  `int`
  `getNumberOfUserDefinedOpNames()`
  Get the total number of user defined pcode names.
  `ParallelInstructionLanguageHelper`
  `getParallelInstructionHelper()`
  Returns a parallel instruction helper for this language or null if one has not been defined.
  `Processor`
  `getProcessor()`
  Returns the processor name on which this language is based.
  `Register`
  `getProgramCounter()`
  Get the default program counter register for this language if there is one.
  `String`
  `getProperty(String key)`
  Gets a property defined for this language, or null if that property isn't defined.
  `String`
  `getProperty(String key, String defaultString)`
  Gets the value of a property as a String, returning defaultString if undefined.
  `boolean`
  `getPropertyAsBoolean(String key, boolean defaultBoolean)`
  Gets the value of a property as a boolean, returning defaultBoolean if undefined.
  `int`
  `getPropertyAsInt(String key, int defaultInt)`
  Gets the value of a property as an int, returning defaultInt if undefined.
  `Set<String>`
  `getPropertyKeys()`
  Returns a read-only set view of the property keys defined on this language.
  `Register`
  `getRegister(Address addr, int size)`
  Get a register given it's underlying address location and size.
  `Register`
  `getRegister(AddressSpace addrspc, long offset, int size)`
  Get a register given the address space it is in, its offset in the space and its size.
  `Register`
  `getRegister(String name)`
  Get a register given the name of the register
  `AddressSetView`
  `getRegisterAddresses()`
  Returns address set of all registers.
  `List<String>`
  `getRegisterNames()`
  Get an alphabetical sorted unmodifiable list of original register names (including context registers).
  `List<Register>`
  `getRegisters()`
  Get an unsorted unmodifiable list of Register objects that this language defines (including context registers).
  `Register[]`
  `getRegisters(Address address)`
  Returns all the registers (each different size is a different register) for an address.
  `DecisionNode`
  `getRootDecisionNode()`
  `String`
  `getSegmentedSpace()`
  Returns the name of the segmented space for this language, or the empty string if the memory model for this language is not segmented.
  `List<Register>`
  `getSortedVectorRegisters()`
  Returns an unmodifiable list of vector registers, sorted first by size and then by name.
  `SourceFileIndexer`
  `getSourceFileIndexer()`
  Returns the source file indexer
  `SymbolTable`
  `getSymbolTable()`
  `int`
  `getUniqueAllocationMask()`
  `long`
  `getUniqueBase()`
  Returns the unique base offset from which additional temporary variables may be created.
  `String`
  `getUserDefinedOpName(int index)`
  Get the user define name for a given index.
  `int`
  `getVersion()`
  Returns the major version for this language.
  `AddressSetView`
  `getVolatileAddresses()`
  Returns an AddressSetView of the volatile addresses for this language
  `boolean`
  `hasManual()`
  Returns whether the language has a valid manual defined.
  `boolean`
  `hasProperty(String key)`
  Returns whether this lanugage has a property defined.
  `boolean`
  `isBigEndian()`
  get the Endian type for this language.
  `boolean`
  `isVolatile(Address addr)`
  Returns true if the language has defined the specified location as volatile.
  `void`
  `loadIndex(ResourceFile processorFile)`
  `int`
  `numSections()`
  `InstructionPrototype`
  `parse(MemBuffer buf, ProcessorContext context, boolean inDelaySlot)`
  Get the InstructionPrototype that matches the bytes presented by the MemBuffer object.
  `void`
  `reloadLanguage(TaskMonitor monitor)`
  Refreshes the definition of this language if possible.
  `boolean`
  `supportsPcode()`
  Return true if the instructions in this language support Pcode.
  `String`
  `toString()`

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

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### SLA_FORMAT_VERSION

    public static final int SLA_FORMAT_VERSION
    SLA_FORMAT_VERSION will be incremented whenever the format of the .sla files change.

    Version 3: January 2021: added source file information for each constructor.
    Version 2: April 2019: Changed numbering of Overlay spaces.
    Version 1: Initial version.

    See Also:
      - Constant Field Values

- ## Method Details

  - ### getUniqueBase

    public long getUniqueBase()
    Returns the unique base offset from which additional temporary variables may be created.
    Returns:
      unique base offset

  - ### getUniqueAllocationMask

    public int getUniqueAllocationMask()

  - ### numSections

    public int numSections()
    Returns:
      (maximum) number of named p-code sections

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### applyContextSettings

    public void applyContextSettings(DefaultProgramContext programContext)
    Description copied from interface: `Language`
    Apply context settings to the ProgramContext as specified by the configuration
    Specified by:
      `applyContextSettings` in interface `Language`
    Parameters:
      `programContext` - is the default program context

  - ### getAddressFactory

    public AddressFactory getAddressFactory()
    Description copied from interface: `Language`
    Get the AddressFactory for this language. The returned Address factory will allow addresses associated with physical, constant and unique spaces to be instantiated. NOTE! this factory does not know about compiler or program specified spaces. Spaces such as stack and overlay spaces are not defined by the language - if these are needed, Program.getAddressFactory() should be used instead.
    Specified by:
      `getAddressFactory` in interface `Language`
    Returns:
      the AddressFactory for this language.
    See Also:
      - `Program.getAddressFactory()`

  - ### getAdditionalInject

    public List<InjectPayloadSleigh> getAdditionalInject()

  - ### getContextBaseRegister

    public Register getContextBaseRegister()
    Description copied from interface: `Language`
    Returns processor context base register or null if one has not been defined by the language.
    Specified by:
      `getContextBaseRegister` in interface `Language`
    Returns:
      base context register or Register.NO_CONTEXT if not defined

  - ### getContextRegisters

    public List<Register> getContextRegisters()
    Description copied from interface: `Language`
    Get an unsorted unmodifiable list of processor context registers that this language defines (includes context base register and its context field registers).
    Specified by:
      `getContextRegisters` in interface `Language`
    Returns:
      unmodifiable list of processor registers.

  - ### getDefaultMemoryBlocks

    public MemoryBlockDefinition[] getDefaultMemoryBlocks()
    Description copied from interface: `Language`
    Returns the default memory blocks for this language.
    Specified by:
      `getDefaultMemoryBlocks` in interface `Language`
    Returns:
      the default memory blocks for this language

  - ### getProgramCounter

    public Register getProgramCounter()
    Description copied from interface: `Language`
    Get the default program counter register for this language if there is one.
    Specified by:
      `getProgramCounter` in interface `Language`
    Returns:
      default program counter register.

  - ### getDefaultSymbols

    public List<AddressLabelInfo> getDefaultSymbols()
    Description copied from interface: `Language`
    Returns the default symbols for this language. This list does not contain registers.
    Specified by:
      `getDefaultSymbols` in interface `Language`
    Returns:
      the default symbols for this language

  - ### getInstructionAlignment

    public int getInstructionAlignment()
    Description copied from interface: `Language`
    Get instruction alignment in terms of bytes.
    Specified by:
      `getInstructionAlignment` in interface `Language`
    Returns:
      instruction alignment

  - ### getMinorVersion

    public int getMinorVersion()
    Description copied from interface: `Language`
    Returns the minor version for this language. Returning a minor version number different than before could cause the program to try and "update" itself. Those languages which do not support this feature may always return a constant value of 0.
    Specified by:
      `getMinorVersion` in interface `Language`
    Returns:
      the language minor version number

  - ### getLanguageID

    public LanguageID getLanguageID()
    Description copied from interface: `Language`
    Returns the LanguageID of this language, which is used as a primary key to find the language when Ghidra loads it.
    Specified by:
      `getLanguageID` in interface `Language`
    Returns:
      the LanguageID of this language

  - ### getUserDefinedOpName

    public String getUserDefinedOpName(int index)
    Description copied from interface: `Language`
    Get the user define name for a given index. Certain pcode has operations defined only by name that when the pcode returns, only the index is known. Note: only works for Pcode based languages
    Specified by:
      `getUserDefinedOpName` in interface `Language`
    Parameters:
      `index` - user defined pcodeop index
    Returns:
      pcodeop name or null if not defined

  - ### getNumberOfUserDefinedOpNames

    public int getNumberOfUserDefinedOpNames()
    Description copied from interface: `Language`
    Get the total number of user defined pcode names. Note: only works for Pcode based languages
    Specified by:
      `getNumberOfUserDefinedOpNames` in interface `Language`
    Returns:
      number of user defined pcodeops

  - ### getProcessor

    public Processor getProcessor()
    Description copied from interface: `Language`
    Returns the processor name on which this language is based. For example, 30386, Pentium, 68010, etc.
    Specified by:
      `getProcessor` in interface `Language`
    Returns:
      the processor name

  - ### getRegister

    public Register getRegister(AddressSpace addrspc, long offset, int size)
    Description copied from interface: `Language`
    Get a register given the address space it is in, its offset in the space and its size.
    Specified by:
      `getRegister` in interface `Language`
    Parameters:
      `addrspc` - address space the register is in
      `offset` - offset of the register in the space
      `size` - size of the register in bytes
    Returns:
      the register

  - ### getRegister

    public Register getRegister(String name)
    Description copied from interface: `Language`
    Get a register given the name of the register
    Specified by:
      `getRegister` in interface `Language`
    Parameters:
      `name` - Register name
    Returns:
      the register

  - ### getRegister

    public Register getRegister(Address addr, int size)
    Description copied from interface: `Language`
    Get a register given it's underlying address location and size.
    Specified by:
      `getRegister` in interface `Language`
    Parameters:
      `addr` - location of the register in its address space
      `size` - the size of the register (in bytes). A value of 0 will return the largest register at the specified addr
    Returns:
      the register

  - ### getRegisters

    public Register[] getRegisters(Address address)
    Description copied from interface: `Language`
    Returns all the registers (each different size is a different register) for an address.
    Specified by:
      `getRegisters` in interface `Language`
    Parameters:
      `address` - the register address for which to return all registers.
    Returns:
      all the registers (each different size is a different register) for an address.

  - ### getRegisters

    public List<Register> getRegisters()
    Description copied from interface: `Language`
    Get an unsorted unmodifiable list of Register objects that this language defines (including context registers).
    Specified by:
      `getRegisters` in interface `Language`
    Returns:
      unmodifiable list of processor registers.

  - ### getRegisterNames

    public List<String> getRegisterNames()
    Description copied from interface: `Language`
    Get an alphabetical sorted unmodifiable list of original register names (including context registers). Names correspond to orignal register name and not aliases which may be defined.
    Specified by:
      `getRegisterNames` in interface `Language`
    Returns:
      alphabetical sorted unmodifiable list of original register names.

  - ### getSegmentedSpace

    public String getSegmentedSpace()
    Description copied from interface: `Language`
    Returns the name of the segmented space for this language, or the empty string if the memory model for this language is not segmented.
    Specified by:
      `getSegmentedSpace` in interface `Language`
    Returns:
      the name of the segmented space or ""

  - ### getVersion

    public int getVersion()
    Description copied from interface: `Language`
    Returns the major version for this language. Returning a version number different than before could cause the program to try and "update" itself. Those languages which do not support this feature may always return a constant value of 1.
    Specified by:
      `getVersion` in interface `Language`
    Returns:
      the language version number

  - ### getVolatileAddresses

    public AddressSetView getVolatileAddresses()
    Description copied from interface: `Language`
    Returns an AddressSetView of the volatile addresses for this language
    Specified by:
      `getVolatileAddresses` in interface `Language`
    Returns:
      an AddressSetView of the volatile addresses for this language

  - ### isBigEndian

    public boolean isBigEndian()
    Description copied from interface: `Language`
    get the Endian type for this language. (If a language supports both, then this returns an initial or default value.)
    Specified by:
      `isBigEndian` in interface `Language`
    Returns:
      true for BigEndian, false for LittleEndian.

  - ### isVolatile

    public boolean isVolatile(Address addr)
    Description copied from interface: `Language`
    Returns true if the language has defined the specified location as volatile.
    Specified by:
      `isVolatile` in interface `Language`
    Parameters:
      `addr` - location address
    Returns:
      true if specified address is within a volatile range

  - ### parse

    public InstructionPrototype parse(MemBuffer buf, ProcessorContext context, boolean inDelaySlot) throws InsufficientBytesException, UnknownInstructionException
    Description copied from interface: `Language`
    Get the InstructionPrototype that matches the bytes presented by the MemBuffer object.
    Specified by:
      `parse` in interface `Language`
    Parameters:
      `buf` - the MemBuffer that presents the bytes in Memory at some address as if they were an array of bytes starting at index 0.
      `context` - the processor context at the address to be disassembled
      `inDelaySlot` - true if this instruction should be parsed as if it were in a delay slot
    Returns:
      the InstructionPrototype that matches the bytes in buf.
    Throws:
      `InsufficientBytesException` - thrown if there are not enough bytes in memory to satisfy a legal instruction.
      `UnknownInstructionException` - thrown if the byte pattern does not match any legal instruction.

  - ### getRootDecisionNode

    public DecisionNode getRootDecisionNode()

  - ### getSymbolTable

    public SymbolTable getSymbolTable()

  - ### getSourceFileIndexer

    public SourceFileIndexer getSourceFileIndexer()
    Returns the source file indexer
    Returns:
      indexer

  - ### reloadLanguage

    public void reloadLanguage(TaskMonitor monitor) throws IOException
    Description copied from interface: `Language`
    Refreshes the definition of this language if possible. Use of this method is intended for development purpose only since stale references to prior language resources (e.g., registers) may persist.
    Specified by:
      `reloadLanguage` in interface `Language`
    Parameters:
      `monitor` - monitor for progress back to the user
    Throws:
      `IOException` - if error occurs while reloading language spec file(s)

  - ### supportsPcode

    public boolean supportsPcode()
    Description copied from interface: `Language`
    Return true if the instructions in this language support Pcode.
    Specified by:
      `supportsPcode` in interface `Language`
    Returns:
      true if language supports the use of pcode

  - ### getDefaultSpace

    public AddressSpace getDefaultSpace()
    Description copied from interface: `Language`
    Get the default memory/code space.
    Specified by:
      `getDefaultSpace` in interface `Language`
    Returns:
      default address space

  - ### getDefaultDataSpace

    public AddressSpace getDefaultDataSpace()
    Description copied from interface: `Language`
    Get the preferred data space used by loaders for data sections.
    Specified by:
      `getDefaultDataSpace` in interface `Language`
    Returns:
      default data address space

  - ### getDefaultPointerWordSize

    @Deprecated public int getDefaultPointerWordSize()
    Deprecated.
    Will be removed once we have better way to attach address spaces to pointer data-types
    Returns:
      the default wordsize to use when analyzing pointer offsets

  - ### getCompatibleCompilerSpecDescriptions

    public List<CompilerSpecDescription> getCompatibleCompilerSpecDescriptions()
    Description copied from interface: `Language`
    Returns a list of all compatible compiler spec descriptions. The first item in the list is the default.
    Specified by:
      `getCompatibleCompilerSpecDescriptions` in interface `Language`
    Returns:
      list of all compatible compiler specifications descriptions

  - ### getCompilerSpecByID

    public CompilerSpec getCompilerSpecByID(CompilerSpecID compilerSpecID) throws CompilerSpecNotFoundException
    Description copied from interface: `Language`
    Returns the compiler spec associated with a given CompilerSpecID.
    Specified by:
      `getCompilerSpecByID` in interface `Language`
    Parameters:
      `compilerSpecID` - the compiler spec id
    Returns:
      the compiler spec associated with the given id
    Throws:
      `CompilerSpecNotFoundException` - if no such compiler spec exists

  - ### getLanguageDescription

    public LanguageDescription getLanguageDescription()
    Description copied from interface: `Language`
    Returns the LanguageDescription of this language, which contains useful information about the characteristics of the language.
    Specified by:
      `getLanguageDescription` in interface `Language`
    Returns:
      the LanguageDescription of this language

  - ### getDefaultCompilerSpec

    public CompilerSpec getDefaultCompilerSpec()
    Description copied from interface: `Language`
    Returns the default compiler spec for this language, which is used when a loader cannot determine the compiler spec or for upgrades when a program had no compiler spec registered (seriously old program, like Ghidra 4.1 or earlier). NOTE: this has NOTHING to do with the compiler spec registered for a program. Use Program.getCompilerSpec() for that!
    Specified by:
      `getDefaultCompilerSpec` in interface `Language`
    Returns:
      the default compiler spec for this language

  - ### getProperty

    public String getProperty(String key)
    Description copied from interface: `Language`
    Gets a property defined for this language, or null if that property isn't defined.
    Specified by:
      `getProperty` in interface `Language`
    Parameters:
      `key` - the property key
    Returns:
      the property value, or null if not defined

  - ### getPropertyKeys

    public Set<String> getPropertyKeys()
    Description copied from interface: `Language`
    Returns a read-only set view of the property keys defined on this language.
    Specified by:
      `getPropertyKeys` in interface `Language`
    Returns:
      read-only set of property keys

  - ### getProperty

    public String getProperty(String key, String defaultString)
    Description copied from interface: `Language`
    Gets the value of a property as a String, returning defaultString if undefined.
    Specified by:
      `getProperty` in interface `Language`
    Parameters:
      `key` - the property key
      `defaultString` - the default value to return if property is undefined
    Returns:
      the property value as a String, or the default value if undefined

  - ### getPropertyAsBoolean

    public boolean getPropertyAsBoolean(String key, boolean defaultBoolean)
    Description copied from interface: `Language`
    Gets the value of a property as a boolean, returning defaultBoolean if undefined.
    Specified by:
      `getPropertyAsBoolean` in interface `Language`
    Parameters:
      `key` - the property key
      `defaultBoolean` - the default value to return if property is undefined
    Returns:
      the property value as a boolean, or the default value if undefined

  - ### getPropertyAsInt

    public int getPropertyAsInt(String key, int defaultInt)
    Description copied from interface: `Language`
    Gets the value of a property as an int, returning defaultInt if undefined.
    Specified by:
      `getPropertyAsInt` in interface `Language`
    Parameters:
      `key` - the property key
      `defaultInt` - the default value to return if property is undefined
    Returns:
      the property value as an int, or the default value if undefined

  - ### hasProperty

    public boolean hasProperty(String key)
    Description copied from interface: `Language`
    Returns whether this lanugage has a property defined.
    Specified by:
      `hasProperty` in interface `Language`
    Parameters:
      `key` - the property key
    Returns:
      if the property is defined

  - ### getManualEntry

    public ManualEntry getManualEntry(String instruction)
    Description copied from interface: `Language`
    Get the ManualEntry for the given instruction mnemonic.
    Specified by:
      `getManualEntry` in interface `Language`
    Parameters:
      `instruction` - the instruction mnemonic
    Returns:
      the ManualEntry or null. A default manual entry will be returned if an instruction can not be found within the index and a manual exists.

  - ### getManualInstructionMnemonicKeys

    public Set<String> getManualInstructionMnemonicKeys()
    Description copied from interface: `Language`
    Returns a read-only set view of the instruction mnemonic keys defined on this language.
    Specified by:
      `getManualInstructionMnemonicKeys` in interface `Language`
    Returns:
      read-only set of instruction mnemonic keys

  - ### loadIndex

    public void loadIndex(ResourceFile processorFile) throws IOException
    Throws:
      `IOException`

  - ### getManualException

    public Exception getManualException()
    Description copied from interface: `Language`
    Returns the exception generated trying to load the manual, or null if it succeeded.
    Specified by:
      `getManualException` in interface `Language`
    Returns:
      the exception generated trying to load the manual, or null if it succeeded

  - ### hasManual

    public boolean hasManual()
    Description copied from interface: `Language`
    Returns whether the language has a valid manual defined.
    Specified by:
      `hasManual` in interface `Language`
    Returns:
      if the language has a manual

  - ### encodeTranslator

    public void encodeTranslator(Encoder encoder, AddressFactory factory, long uniqueOffset) throws IOException
    Encode limited information to the stream about the SLEIGH translator for the specified address factory and optional register set.
    Parameters:
      `encoder` - is the stream encoder
      `factory` - is the specified address factory
      `uniqueOffset` - the initial offset within the unique address space to start assigning temporary registers
    Throws:
      `IOException` - for errors writing to the underlying stream

  - ### getParallelInstructionHelper

    public ParallelInstructionLanguageHelper getParallelInstructionHelper()
    Description copied from interface: `Language`
    Returns a parallel instruction helper for this language or null if one has not been defined.
    Specified by:
      `getParallelInstructionHelper` in interface `Language`
    Returns:
      parallel instruction helper or null if not applicable

  - ### getSortedVectorRegisters

    public List<Register> getSortedVectorRegisters()
    Description copied from interface: `Language`
    Returns an unmodifiable list of vector registers, sorted first by size and then by name.
    Specified by:
      `getSortedVectorRegisters` in interface `Language`
    Returns:
      unmodifiable list of vector registers.

  - ### getRegisterAddresses

    public AddressSetView getRegisterAddresses()
    Description copied from interface: `Language`
    Returns address set of all registers.
    Specified by:
      `getRegisterAddresses` in interface `Language`
    Returns:
      the address set.