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 DecompilerLanguageDECOMPILER_OUTPUT_DEFstatic java.lang.StringDECOMPILER_OUTPUT_DESCstatic java.lang.StringDECOMPILER_OUTPUT_LANGUAGEstatic java.lang.StringDECOMPILER_PROPERTY_LIST_NAMEstatic java.lang.StringJOIN_SPACE_NAMEstatic java.lang.StringSTACK_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 voidapplyContextSettings(DefaultProgramContext programContext)Apply context settings to the ProgramContext as specified by the configurationbooleandoesCDataTypeConversions()Return true if function prototypes respect the C-language datatype conversion conventions.static voidenableJavaLanguageDecompilation(Program program)Adds and enables an option to have the decompiler display java.PrototypeModelfindBestCallingConvention(Parameter[] params)Find the best guess at a calling convention model from this compiler spec given an ordered list of (potential) parameters.AddressSpacegetAddressSpace(java.lang.String spaceName)Get an address space by name.PrototypeModelgetCallingConvention(java.lang.String name)Returns the Calling Convention Model with the given name.PrototypeModel[]getCallingConventions()Returns an array of the prototype models.intgetCallStackMod()Number of extra bytes popped from the stack on return -1 if it is unknown.intgetCallStackShift()Get the normal shift in the stack at the call to this routine.CompilerSpecDescriptiongetCompilerSpecDescription()Returns a brief description of the compiler specCompilerSpecIDgetCompilerSpecID()Returns the id string associated with this compiler spec;java.lang.StringgetCompilerSpecString()DataOrganizationgetDataOrganization()DecompilerLanguagegetDecompilerOutputLanguage(Program program)Get the language that the decompiler producesPrototypeModelgetDefaultCallingConvention()Returns the prototype model that is the default calling convention or else null.LanguagegetLanguage()Get the Language this compiler spec is based on.PrototypeModel[]getNamedCallingConventions()Returns an array of the named prototype models.PcodeInjectLibrarygetPcodeInjectLibrary()java.lang.StringgetProperty(java.lang.String key)Gets a property defined for this language, or null if that property isn't defined.java.lang.StringgetProperty(java.lang.String key, java.lang.String defaultString)Gets the value of a property as a String, returning defaultString if undefined.booleangetPropertyAsBoolean(java.lang.String key, boolean defaultBoolean)Gets the value of a property as a boolean, returning defaultBoolean if undefined.intgetPropertyAsInt(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.ObjectgetPrototypeEvaluationModel(Program program)Get the program-specific prototype evaluation model.AddressSpacegetStackBaseSpace()Get the physical space used for stack data storageRegistergetStackPointer()Get the default Stack Pointer register for this language if there is one.AddressSpacegetStackSpace()Get the stack address space defined by this specificationbooleanhasProperty(java.lang.String key)Returns whether this lanugage has a property defined.booleanisGlobal(Address addr)Returns true if specified address location has been designated globalbooleanisStackRightJustified()Indicates whether variables are right-justified within the stack alignment.PrototypeModelmatchConvention(GenericCallingConvention genericCallingConvention)Get the PrototypeModel based on the genericCallingConventionvoidregisterProgramOptions(Program program)Register program-specific compiler-spec optionsbooleanstackGrowsNegative()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
-
-
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.FileNotFoundExceptionjava.io.IOException
-
applyContextSettings
public void applyContextSettings(DefaultProgramContext programContext)
Description copied from interface:CompilerSpecApply context settings to the ProgramContext as specified by the configuration- Specified by:
applyContextSettingsin interfaceCompilerSpec- Parameters:
programContext- is the ProgramContext
-
getCompilerSpecID
public CompilerSpecID getCompilerSpecID()
Description copied from interface:CompilerSpecReturns the id string associated with this compiler spec;- Specified by:
getCompilerSpecIDin interfaceCompilerSpec- Returns:
- the id string associated with this compiler spec;
-
doesCDataTypeConversions
public boolean doesCDataTypeConversions()
Description copied from interface:CompilerSpecReturn 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:
doesCDataTypeConversionsin interfaceCompilerSpec- Returns:
-
getCallStackMod
public int getCallStackMod()
Description copied from interface:CompilerSpecNumber of extra bytes popped from the stack on return -1 if it is unknown.- Specified by:
getCallStackModin interfaceCompilerSpec- Returns:
- # of bytes popped from the stack by a called function on return.
-
getCallStackShift
public int getCallStackShift()
Description copied from interface:CompilerSpecGet the normal shift in the stack at the call to this routine. This will be the things pushed on the stack as part of the calling conventions. Normally the return value.- Specified by:
getCallStackShiftin interfaceCompilerSpec- Returns:
- entry stack shift or -1 if it is unknown
-
getCallingConventions
public PrototypeModel[] getCallingConventions()
Description copied from interface:CompilerSpecReturns an array of the prototype models. Each prototype model specifies a calling convention.- Specified by:
getCallingConventionsin interfaceCompilerSpec
-
getCallingConvention
public PrototypeModel getCallingConvention(java.lang.String name)
Description copied from interface:CompilerSpecReturns the Calling Convention Model with the given name.- Specified by:
getCallingConventionin 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:CompilerSpecReturns the prototype model that is the default calling convention or else null.- Specified by:
getDefaultCallingConventionin interfaceCompilerSpec- Returns:
- the default calling convention or null.
-
getStackPointer
public Register getStackPointer()
Description copied from interface:CompilerSpecGet the default Stack Pointer register for this language if there is one.- Specified by:
getStackPointerin interfaceCompilerSpec- Returns:
- default stack pointer register.
-
isStackRightJustified
public boolean isStackRightJustified()
Description copied from interface:CompilerSpecIndicates whether variables are right-justified within the stack alignment.- Specified by:
isStackRightJustifiedin interfaceCompilerSpec- Returns:
- true if right stack justification applies.
-
getStackSpace
public AddressSpace getStackSpace()
Description copied from interface:CompilerSpecGet the stack address space defined by this specification- Specified by:
getStackSpacein interfaceCompilerSpec- Returns:
- stack address space
-
getStackBaseSpace
public AddressSpace getStackBaseSpace()
Description copied from interface:CompilerSpecGet the physical space used for stack data storage- Specified by:
getStackBaseSpacein interfaceCompilerSpec- Returns:
- address space which contains the stack
-
getNamedCallingConventions
public PrototypeModel[] getNamedCallingConventions()
Description copied from interface:CompilerSpecReturns an array of the named prototype models. Each prototype model specifies a calling convention.- Specified by:
getNamedCallingConventionsin interfaceCompilerSpec
-
stackGrowsNegative
public boolean stackGrowsNegative()
Description copied from interface:CompilerSpecReturns true if stack grows with negative offsets- Specified by:
stackGrowsNegativein interfaceCompilerSpec
-
isGlobal
public boolean isGlobal(Address addr)
Description copied from interface:CompilerSpecReturns true if specified address location has been designated global- Specified by:
isGlobalin interfaceCompilerSpec- Parameters:
addr- address location
-
getLanguage
public Language getLanguage()
Description copied from interface:CompilerSpecGet 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:
getLanguagein interfaceCompilerSpec- Returns:
- the language this compiler spec is based on
-
getCompilerSpecDescription
public CompilerSpecDescription getCompilerSpecDescription()
Description copied from interface:CompilerSpecReturns a brief description of the compiler spec- Specified by:
getCompilerSpecDescriptionin interfaceCompilerSpec
-
getAddressSpace
public AddressSpace getAddressSpace(java.lang.String spaceName)
Description copied from interface:CompilerSpecGet 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:
getAddressSpacein interfaceCompilerSpec- Returns:
- the corresponding AddressSpace object
-
getDataOrganization
public DataOrganization getDataOrganization()
- Specified by:
getDataOrganizationin interfaceCompilerSpec
-
getPrototypeEvaluationModel
public java.lang.Object getPrototypeEvaluationModel(Program program)
Description copied from interface:CompilerSpecGet the program-specific prototype evaluation model.- Specified by:
getPrototypeEvaluationModelin interfaceCompilerSpec- Returns:
- prototype evaluation model
-
getDecompilerOutputLanguage
public DecompilerLanguage getDecompilerOutputLanguage(Program program)
Description copied from interface:CompilerSpecGet the language that the decompiler produces- Specified by:
getDecompilerOutputLanguagein interfaceCompilerSpec- Returns:
- an enum specifying the language
-
registerProgramOptions
public void registerProgramOptions(Program program)
Description copied from interface:CompilerSpecRegister program-specific compiler-spec options- Specified by:
registerProgramOptionsin interfaceCompilerSpec
-
matchConvention
public PrototypeModel matchConvention(GenericCallingConvention genericCallingConvention)
Description copied from interface:CompilerSpecGet the PrototypeModel based on the genericCallingConvention- Specified by:
matchConventionin interfaceCompilerSpec- Returns:
- the matching model or the defaultModel if nothing matches
-
findBestCallingConvention
public PrototypeModel findBestCallingConvention(Parameter[] params)
Description copied from interface:CompilerSpecFind the best guess at a calling convention model from this compiler spec given an ordered list of (potential) parameters.- Specified by:
findBestCallingConventionin interfaceCompilerSpec- Returns:
- prototype model corresponding to the specified function signature
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Description copied from interface:CompilerSpecGets a property defined for this language, or null if that property isn't defined.- Specified by:
getPropertyin 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:CompilerSpecReturns a read-only set view of the property keys defined on this language.- Specified by:
getPropertyKeysin 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:CompilerSpecGets the value of a property as a String, returning defaultString if undefined.- Specified by:
getPropertyin 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:CompilerSpecGets the value of a property as a boolean, returning defaultBoolean if undefined.- Specified by:
getPropertyAsBooleanin 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:CompilerSpecGets the value of a property as an int, returning defaultInt if undefined.- Specified by:
getPropertyAsIntin 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:CompilerSpecReturns whether this lanugage has a property defined.- Specified by:
hasPropertyin interfaceCompilerSpec- Parameters:
key- the property key- Returns:
- if the property is defined
-
getPcodeInjectLibrary
public PcodeInjectLibrary getPcodeInjectLibrary()
- Specified by:
getPcodeInjectLibraryin interfaceCompilerSpec
-
enableJavaLanguageDecompilation
public static void enableJavaLanguageDecompilation(Program program)
Adds and enables an option to have the decompiler display java.- Parameters:
program- to be enabled
-
-