Class BasicCompilerSpec

  • All Implemented Interfaces:
    CompilerSpec
    Direct Known Subclasses:
    ProgramCompilerSpec

    public class BasicCompilerSpec
    extends java.lang.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.
    • Constructor Detail

      • BasicCompilerSpec

        public BasicCompilerSpec​(CompilerSpecDescription description,
                                 SleighLanguage language,
                                 java.io.InputStream stream)
                          throws XmlParseException,
                                 org.xml.sax.SAXException,
                                 java.io.IOException
        Construct the specification from an XML stream. This is currently only used for testing.
        Parameters:
        description - is the .ldefs description matching this specification
        language - is the language that owns the specification
        stream - is the XML stream
        Throws:
        XmlParseException - for badly formed XML
        org.xml.sax.SAXException - for syntax errors in the XML
        java.io.IOException - for errors accessing the stream
      • BasicCompilerSpec

        protected BasicCompilerSpec​(BasicCompilerSpec op2)
        Clone the spec so that program can safely extend it without affecting the base spec from Language.
        Parameters:
        op2 - is the spec to clone
    • Method Detail

      • getErrorHandler

        protected static org.xml.sax.ErrorHandler getErrorHandler​(java.lang.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
      • getXMLString

        public java.lang.String getXMLString()
        Convenience method to marshal this entire object, via saveXml, into a String object.
        Returns:
        a String containing this entire spec as an XML document.
      • 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
      • 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
      • getCallingConvention

        public PrototypeModel getCallingConvention​(java.lang.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.
      • 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
      • getAddressSpace

        public AddressSpace getAddressSpace​(java.lang.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 void modelXrefs​(java.util.List<PrototypeModel> modelList,
                                  java.lang.String defaultName,
                                  java.lang.String evalCurrent,
                                  java.lang.String evalCalled)
        Establish cross referencing to prototype models. All xrefs are regenerated from a single complete list of PrototypeModels
        Parameters:
        modelList - is the complete list of models
        defaultName - is the name to use for the default model (or null)
        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)
      • saveXml

        public void saveXml​(java.lang.StringBuilder buffer)
        Marshal this entire specification to an XML stream. An XML document is written with root tag \.
        Parameters:
        buffer - is the XML stream
      • matchConvention

        public PrototypeModel matchConvention​(GenericCallingConvention genericCallingConvention)
        Description copied from interface: CompilerSpec
        Get the PrototypeModel corresponding to the given generic calling convention
        Specified by:
        matchConvention in interface CompilerSpec
        Parameters:
        genericCallingConvention - is the given generic calling convention
        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.
        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 java.lang.String getProperty​(java.lang.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 java.util.Set<java.lang.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 java.lang.String getProperty​(java.lang.String key,
                                            java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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
      • removeProgramMechanismPayloads

        protected void removeProgramMechanismPayloads​(java.util.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​(java.util.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
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object