Package ghidra.program.model.lang
Class BasicCompilerSpec
- java.lang.Object
-
- ghidra.program.model.lang.BasicCompilerSpec
-
- All Implemented Interfaces:
CompilerSpec
public class BasicCompilerSpec extends java.lang.Object implements CompilerSpec
-
-
Field Summary
Fields Modifier and Type Field Description static int
CONSTANT_SPACE_INDEX
static DecompilerLanguage
DECOMPILER_OUTPUT_DEF
static java.lang.String
DECOMPILER_OUTPUT_DESC
static java.lang.String
DECOMPILER_OUTPUT_LANGUAGE
static java.lang.String
DECOMPILER_PROPERTY_LIST_NAME
static java.lang.String
JOIN_SPACE_NAME
static int
OTHER_SPACE_INDEX
static java.lang.String
OTHER_SPACE_NAME
static java.lang.String
STACK_SPACE_NAME
-
Fields inherited from interface ghidra.program.model.lang.CompilerSpec
CALLING_CONVENTION_cdecl, CALLING_CONVENTION_fastcall, CALLING_CONVENTION_pascal, CALLING_CONVENTION_stdcall, CALLING_CONVENTION_thiscall, CALLING_CONVENTION_vectorcall
-
-
Constructor Summary
Constructors Constructor Description BasicCompilerSpec(CompilerSpecDescription description, SleighLanguage language, ResourceFile cspecFile)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyContextSettings(DefaultProgramContext programContext)
Apply context settings to the ProgramContext as specified by the configurationboolean
doesCDataTypeConversions()
Return true if function prototypes respect the C-language datatype conversion conventions.static void
enableJavaLanguageDecompilation(Program program)
Adds and enables an option to have the decompiler display java.PrototypeModel
findBestCallingConvention(Parameter[] params)
Find the best guess at a calling convention model from this compiler spec given an ordered list of (potential) parameters.AddressSpace
getAddressSpace(java.lang.String spaceName)
Get an address space by name.PrototypeModel
getCallingConvention(java.lang.String name)
Returns the Calling Convention Model with the given name.PrototypeModel[]
getCallingConventions()
Returns an array of the prototype models.CompilerSpecDescription
getCompilerSpecDescription()
Returns a brief description of the compiler specCompilerSpecID
getCompilerSpecID()
Returns the id string associated with this compiler spec;java.lang.String
getCompilerSpecString()
DataOrganization
getDataOrganization()
DecompilerLanguage
getDecompilerOutputLanguage(Program program)
Get the language that the decompiler producesPrototypeModel
getDefaultCallingConvention()
Returns the prototype model that is the default calling convention or else null.Language
getLanguage()
Get the Language this compiler spec is based on.PrototypeModel[]
getNamedCallingConventions()
Returns an array of the named prototype models.PcodeInjectLibrary
getPcodeInjectLibrary()
java.lang.String
getProperty(java.lang.String key)
Gets a property defined for this language, or null if that property isn't defined.java.lang.String
getProperty(java.lang.String key, java.lang.String defaultString)
Gets the value of a property as a String, returning defaultString if undefined.boolean
getPropertyAsBoolean(java.lang.String key, boolean defaultBoolean)
Gets the value of a property as a boolean, returning defaultBoolean if undefined.int
getPropertyAsInt(java.lang.String key, int defaultInt)
Gets the value of a property as an int, returning defaultInt if undefined.java.util.Set<java.lang.String>
getPropertyKeys()
Returns a read-only set view of the property keys defined on this language.java.lang.Object
getPrototypeEvaluationModel(Program program)
Get the program-specific prototype evaluation model.AddressSpace
getStackBaseSpace()
Get the physical space used for stack data storageRegister
getStackPointer()
Get the default Stack Pointer register for this language if there is one.AddressSpace
getStackSpace()
Get the stack address space defined by this specificationboolean
hasProperty(java.lang.String key)
Returns whether this lanugage has a property defined.boolean
isGlobal(Address addr)
Returns true if specified address location has been designated globalboolean
isStackRightJustified()
Indicates whether variables are right-justified within the stack alignment.PrototypeModel
matchConvention(GenericCallingConvention genericCallingConvention)
Get the PrototypeModel based on the genericCallingConventionvoid
registerProgramOptions(Program program)
Register program-specific compiler-spec optionsboolean
stackGrowsNegative()
Returns true if stack grows with negative offsets
-
-
-
Field Detail
-
DECOMPILER_PROPERTY_LIST_NAME
public static final java.lang.String DECOMPILER_PROPERTY_LIST_NAME
- See Also:
- Constant Field Values
-
DECOMPILER_OUTPUT_LANGUAGE
public static final java.lang.String DECOMPILER_OUTPUT_LANGUAGE
- See Also:
- Constant Field Values
-
DECOMPILER_OUTPUT_DEF
public static final DecompilerLanguage DECOMPILER_OUTPUT_DEF
-
DECOMPILER_OUTPUT_DESC
public static final java.lang.String DECOMPILER_OUTPUT_DESC
- See Also:
- Constant Field Values
-
STACK_SPACE_NAME
public static final java.lang.String STACK_SPACE_NAME
- See Also:
- Constant Field Values
-
JOIN_SPACE_NAME
public static final java.lang.String JOIN_SPACE_NAME
- See Also:
- Constant Field Values
-
OTHER_SPACE_NAME
public static final java.lang.String OTHER_SPACE_NAME
- See Also:
- Constant Field Values
-
CONSTANT_SPACE_INDEX
public static final int CONSTANT_SPACE_INDEX
- See Also:
- Constant Field Values
-
OTHER_SPACE_INDEX
public static final int OTHER_SPACE_INDEX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BasicCompilerSpec
public BasicCompilerSpec(CompilerSpecDescription description, SleighLanguage language, ResourceFile cspecFile) throws CompilerSpecNotFoundException
- Throws:
CompilerSpecNotFoundException
-
-
Method Detail
-
getCompilerSpecString
public java.lang.String getCompilerSpecString() throws java.io.FileNotFoundException, java.io.IOException
- Throws:
java.io.FileNotFoundException
java.io.IOException
-
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 interfaceCompilerSpec
- Parameters:
programContext
- is the ProgramContext
-
getCompilerSpecID
public CompilerSpecID getCompilerSpecID()
Description copied from interface:CompilerSpec
Returns the id string associated with this compiler spec;- Specified by:
getCompilerSpecID
in interfaceCompilerSpec
- 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 datatype conversion conventions. This amounts to converting array datatypes to pointer-to-element datatypes. In C, arrays are passed by reference (structures are still passed by value)- Specified by:
doesCDataTypeConversions
in interfaceCompilerSpec
- Returns:
-
getCallingConventions
public PrototypeModel[] getCallingConventions()
Description copied from interface:CompilerSpec
Returns an array of the prototype models. Each prototype model specifies a calling convention.- Specified by:
getCallingConventions
in interfaceCompilerSpec
-
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 interfaceCompilerSpec
- 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.
-
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 interfaceCompilerSpec
- Returns:
- the default calling convention or null.
-
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 interfaceCompilerSpec
- 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 interfaceCompilerSpec
- 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 interfaceCompilerSpec
- 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 interfaceCompilerSpec
- Returns:
- address space which contains the stack
-
getNamedCallingConventions
public PrototypeModel[] getNamedCallingConventions()
Description copied from interface:CompilerSpec
Returns an array of the named prototype models. Each prototype model specifies a calling convention.- Specified by:
getNamedCallingConventions
in interfaceCompilerSpec
-
stackGrowsNegative
public boolean stackGrowsNegative()
Description copied from interface:CompilerSpec
Returns true if stack grows with negative offsets- Specified by:
stackGrowsNegative
in interfaceCompilerSpec
-
isGlobal
public boolean isGlobal(Address addr)
Description copied from interface:CompilerSpec
Returns true if specified address location has been designated global- Specified by:
isGlobal
in interfaceCompilerSpec
- Parameters:
addr
- address location
-
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 interfaceCompilerSpec
- Returns:
- the language this compiler spec is based on
-
getCompilerSpecDescription
public CompilerSpecDescription getCompilerSpecDescription()
Description copied from interface:CompilerSpec
Returns a brief description of the compiler spec- Specified by:
getCompilerSpecDescription
in interfaceCompilerSpec
-
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 interfaceCompilerSpec
- Returns:
- the corresponding AddressSpace object
-
getDataOrganization
public DataOrganization getDataOrganization()
- Specified by:
getDataOrganization
in interfaceCompilerSpec
-
getPrototypeEvaluationModel
public java.lang.Object getPrototypeEvaluationModel(Program program)
Description copied from interface:CompilerSpec
Get the program-specific prototype evaluation model.- Specified by:
getPrototypeEvaluationModel
in interfaceCompilerSpec
- Returns:
- prototype evaluation model
-
getDecompilerOutputLanguage
public DecompilerLanguage getDecompilerOutputLanguage(Program program)
Description copied from interface:CompilerSpec
Get the language that the decompiler produces- Specified by:
getDecompilerOutputLanguage
in interfaceCompilerSpec
- Returns:
- an enum specifying the language
-
registerProgramOptions
public void registerProgramOptions(Program program)
Description copied from interface:CompilerSpec
Register program-specific compiler-spec options- Specified by:
registerProgramOptions
in interfaceCompilerSpec
-
matchConvention
public PrototypeModel matchConvention(GenericCallingConvention genericCallingConvention)
Description copied from interface:CompilerSpec
Get the PrototypeModel based on the genericCallingConvention- Specified by:
matchConvention
in interfaceCompilerSpec
- 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 interfaceCompilerSpec
- 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 interfaceCompilerSpec
- 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 interfaceCompilerSpec
- 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 interfaceCompilerSpec
- Parameters:
key
- the property keydefaultString
- 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 interfaceCompilerSpec
- Parameters:
key
- the property keydefaultBoolean
- 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 interfaceCompilerSpec
- Parameters:
key
- the property keydefaultInt
- 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 lanugage has a property defined.- Specified by:
hasProperty
in interfaceCompilerSpec
- Parameters:
key
- the property key- Returns:
- if the property is defined
-
getPcodeInjectLibrary
public PcodeInjectLibrary getPcodeInjectLibrary()
- Specified by:
getPcodeInjectLibrary
in interfaceCompilerSpec
-
enableJavaLanguageDecompilation
public static void enableJavaLanguageDecompilation(Program program)
Adds and enables an option to have the decompiler display java.- Parameters:
program
- to be enabled
-
-