Class BasicCompilerSpec

java.lang.Object
ghidra.program.model.lang.BasicCompilerSpec
All Implemented Interfaces:
CompilerSpec
Direct Known Subclasses:
ProgramCompilerSpec

public class BasicCompilerSpec extends Object implements CompilerSpec
BasicCompilerSpec implements the CompilerSpec interface based on static information from a particular .cspec file. Typically the .cspec file is read in once by a Language object whenever a new or opened Program indicates a particular language and compiler. The BasicCompilerSpec is owned by the Language and (parts of it) may be reused by multiple Programs.
  • Field Details

  • Constructor Details

  • Method Details

    • getErrorHandler

      protected static ErrorHandler getErrorHandler(String docTitle)
      Generate an XML error handler suitable for parsing a specification document. - Warnings are logged. - Errors cause a SAXParseException
      Parameters:
      docTitle - is the title of the document
      Returns:
      the error handler object
    • applyContextSettings

      public void applyContextSettings(DefaultProgramContext programContext)
      Description copied from interface: CompilerSpec
      Apply context settings to the ProgramContext as specified by the configuration
      Specified by:
      applyContextSettings in interface CompilerSpec
      Parameters:
      programContext - is the ProgramContext
    • getCompilerSpecID

      public CompilerSpecID getCompilerSpecID()
      Specified by:
      getCompilerSpecID in interface CompilerSpec
      Returns:
      the id string associated with this compiler spec;
    • doesCDataTypeConversions

      public boolean doesCDataTypeConversions()
      Description copied from interface: CompilerSpec
      Return true if function prototypes respect the C-language data-type conversion conventions. This amounts to converting array data-types to pointer-to-element data-types. In C, arrays are passed by reference (structures are still passed by value)
      Specified by:
      doesCDataTypeConversions in interface CompilerSpec
      Returns:
      if the prototype does C-language data-type conversions
    • getCallingConventions

      public PrototypeModel[] getCallingConventions()
      Specified by:
      getCallingConventions in interface CompilerSpec
      Returns:
      an array of the prototype models. Each prototype model specifies a calling convention.
    • getCallingConvention

      public PrototypeModel getCallingConvention(String name)
      Description copied from interface: CompilerSpec
      Returns the Calling Convention Model with the given name.
      Specified by:
      getCallingConvention in interface CompilerSpec
      Parameters:
      name - the name of the calling convention to retrieve
      Returns:
      the calling convention with the given name or null if there is none with that name.
    • getAllModels

      public PrototypeModel[] getAllModels()
      Specified by:
      getAllModels in interface CompilerSpec
      Returns:
      all possible PrototypeModels, including calling conventions and merge models
    • getDefaultCallingConvention

      public PrototypeModel getDefaultCallingConvention()
      Description copied from interface: CompilerSpec
      Returns the prototype model that is the default calling convention or else null.
      Specified by:
      getDefaultCallingConvention in interface CompilerSpec
      Returns:
      the default calling convention or null.
    • getDecompilerOutputLanguage

      public DecompilerLanguage getDecompilerOutputLanguage()
      Description copied from interface: CompilerSpec
      Get the language that the decompiler produces
      Specified by:
      getDecompilerOutputLanguage in interface CompilerSpec
      Returns:
      an enum specifying the language
    • getPrototypeEvaluationModel

      public PrototypeModel getPrototypeEvaluationModel(CompilerSpec.EvaluationModelType modelType)
      Description copied from interface: CompilerSpec
      Get the evaluation model matching the given type. If analysis needs to apply a PrototypeModel to a function but a specific model is not known, then this method can be used to select a putative PrototypeModel based on the analysis use-case: - EVAL_CURRENT indicates the model to use for the "current function" being analyzed - EVAL_CALLED indicates the model to use for a function called by the current function
      Specified by:
      getPrototypeEvaluationModel in interface CompilerSpec
      Parameters:
      modelType - is the type of evaluation model
      Returns:
      prototype evaluation model
    • getStackPointer

      public Register getStackPointer()
      Description copied from interface: CompilerSpec
      Get the default Stack Pointer register for this language if there is one.
      Specified by:
      getStackPointer in interface CompilerSpec
      Returns:
      default stack pointer register.
    • isStackRightJustified

      public boolean isStackRightJustified()
      Description copied from interface: CompilerSpec
      Indicates whether variables are right-justified within the stack alignment.
      Specified by:
      isStackRightJustified in interface CompilerSpec
      Returns:
      true if right stack justification applies.
    • getStackSpace

      public AddressSpace getStackSpace()
      Description copied from interface: CompilerSpec
      Get the stack address space defined by this specification
      Specified by:
      getStackSpace in interface CompilerSpec
      Returns:
      stack address space
    • getStackBaseSpace

      public AddressSpace getStackBaseSpace()
      Description copied from interface: CompilerSpec
      Get the physical space used for stack data storage
      Specified by:
      getStackBaseSpace in interface CompilerSpec
      Returns:
      address space which contains the stack
    • stackGrowsNegative

      public boolean stackGrowsNegative()
      Specified by:
      stackGrowsNegative in interface CompilerSpec
      Returns:
      true if the stack grows with negative offsets
    • isGlobal

      public boolean isGlobal(Address addr)
      Specified by:
      isGlobal in interface CompilerSpec
      Parameters:
      addr - is the (start of the) storage location
      Returns:
      true if the specified storage location has been designated "global" in scope
    • getLanguage

      public Language getLanguage()
      Description copied from interface: CompilerSpec
      Get the Language this compiler spec is based on. Note that compiler specs may be reused across multiple languages in the cspec files on disk, but once loaded in memory are actually separate objects. (M:N on disk, 1:N in memory)
      Specified by:
      getLanguage in interface CompilerSpec
      Returns:
      the language this compiler spec is based on
    • getCompilerSpecDescription

      public CompilerSpecDescription getCompilerSpecDescription()
      Specified by:
      getCompilerSpecDescription in interface CompilerSpec
      Returns:
      a brief description of the compiler spec
    • getAddressSpace

      public AddressSpace getAddressSpace(String spaceName)
      Description copied from interface: CompilerSpec
      Get an address space by name. This can be value added over the normal AddressFactory.getAddressSpace routine because the compiler spec can refer to special internal spaces like the stack space
      Specified by:
      getAddressSpace in interface CompilerSpec
      Parameters:
      spaceName - is the name of the address space
      Returns:
      the corresponding AddressSpace object
    • modelXrefs

      protected String modelXrefs(List<PrototypeModel> modelList, String defaultName, String evalCurrent, String evalCalled) throws XmlParseException
      Establish cross referencing to prototype models. All xrefs are regenerated from a single complete list of PrototypeModels. If there are PrototypeModels with duplicate names, return an example name. Return null otherwise The modelList must provide a model with name matching defaultName or an exception is thrown. (In theory the schema guarantees this model always exists)
      Parameters:
      modelList - is the complete list of models
      defaultName - is the name to use for the default model
      evalCurrent - is the name to use for evaluating the current function (or null)
      evalCalled - is the name to use for evaluating called functions (or null)
      Returns:
      a PrototypeModel name that was duplicated or null
      Throws:
      XmlParseException - if there is no model matching defaultName
    • encode

      public void encode(Encoder encoder) throws IOException
      Description copied from interface: CompilerSpec
      Encode this entire specification to a stream. A document is written with root element \.
      Specified by:
      encode in interface CompilerSpec
      Parameters:
      encoder - is the stream encoder
      Throws:
      IOException - for errors writing to the underlying stream
    • getDataOrganization

      public DataOrganization getDataOrganization()
      Specified by:
      getDataOrganization in interface CompilerSpec
    • matchConvention

      public PrototypeModel matchConvention(String conventionName)
      Description copied from interface: CompilerSpec
      Get the PrototypeModel which corresponds to the given calling convention name. If no match is found the default prototype model is returned.
      Specified by:
      matchConvention in interface CompilerSpec
      Parameters:
      conventionName - calling convention name.
      Returns:
      the matching model or the defaultModel if nothing matches
    • findBestCallingConvention

      public PrototypeModel findBestCallingConvention(Parameter[] params)
      Description copied from interface: CompilerSpec
      Find the best guess at a calling convention model from this compiler spec given an ordered list of (potential) parameters with storage assignments.
      Specified by:
      findBestCallingConvention in interface CompilerSpec
      Parameters:
      params - is the ordered list of parameters
      Returns:
      prototype model corresponding to the specified function signature
    • getProperty

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

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

      public String getProperty(String key, String defaultString)
      Description copied from interface: CompilerSpec
      Gets the value of a property as a String, returning defaultString if undefined.
      Specified by:
      getProperty in interface CompilerSpec
      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: CompilerSpec
      Gets the value of a property as a boolean, returning defaultBoolean if undefined.
      Specified by:
      getPropertyAsBoolean in interface CompilerSpec
      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: CompilerSpec
      Gets the value of a property as an int, returning defaultInt if undefined.
      Specified by:
      getPropertyAsInt in interface CompilerSpec
      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: CompilerSpec
      Returns whether this language has a property defined.
      Specified by:
      hasProperty in interface CompilerSpec
      Parameters:
      key - the property key
      Returns:
      if the property is defined
    • getPcodeInjectLibrary

      public PcodeInjectLibrary getPcodeInjectLibrary()
      Specified by:
      getPcodeInjectLibrary in interface CompilerSpec
    • removeProgramMechanismPayloads

      protected void removeProgramMechanismPayloads(Collection<PrototypeModel> modelList)
      Remove any call mechanism injections associated with the given list of PrototypeModels
      Parameters:
      modelList - is the given list
    • registerProgramInject

      protected void registerProgramInject(List<InjectPayloadSleigh> injectExtensions)
      Register Program based InjectPayloads with the p-code library. This allows derived classes to extend the library
      Parameters:
      injectExtensions - is the list of payloads to register
    • markPrototypeAsExtension

      protected static void markPrototypeAsExtension(PrototypeModel model)
      Mark a given PrototypeModel as a Program specific extension
      Parameters:
      model - is the given PrototypeModel
    • setDefaultReturnAddressIfNeeded

      protected void setDefaultReturnAddressIfNeeded(PrototypeModel model)
      Sets the returnaddress of model to the returnAddress of this if the model does not have a return address set.
      Parameters:
      model - prototype
    • isEquivalent

      public boolean isEquivalent(CompilerSpec obj)
      Description copied from interface: CompilerSpec
      Determine if this CompilerSpec is equivalent to another specified instance
      Specified by:
      isEquivalent in interface CompilerSpec
      Parameters:
      obj - is the other instance
      Returns:
      true if they are equivalent