Package ghidra.program.util
Class LanguageTranslatorAdapter
- java.lang.Object
-
- ghidra.program.util.LanguageTranslatorAdapter
-
- All Implemented Interfaces:
LanguageTranslator
,ExtensionPoint
public abstract class LanguageTranslatorAdapter extends java.lang.Object implements LanguageTranslator
LanguageTranslatorAdapter
provides a default language translator behavior which may be extended to provide customized language translations.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
DEFAULT_COMPILER_SPEC_ID
-
Constructor Summary
Constructors Modifier Constructor Description protected
LanguageTranslatorAdapter(LanguageID oldLanguageID, int oldLanguageVersion, LanguageID newLanguageID, int newLanguageVersion)
Constructor for customized language translators which want to leverage some of the default language mappings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static AddressSpace
findSpaceSameName(AddressSpace oldSpace, java.util.ArrayList<AddressSpace> newSpaces)
void
fixupInstructions(Program program, Language oldLanguage, TaskMonitor monitor)
Invoked after Program language upgrade has completed.AddressSpace
getNewAddressSpace(java.lang.String oldSpaceName)
Translate BASE address spaces (Overlay spaces are not handled)CompilerSpecID
getNewCompilerSpecID(CompilerSpecID oldCompilerSpecID)
Obtain the new compiler specification ID given the old compiler spec ID.Register
getNewContextRegister()
Returns the new processor context register or null if not definedLanguage
getNewLanguage()
Returns new languageLanguageID
getNewLanguageID()
Returns new language nameRegister
getNewRegister(Register oldReg)
Find new register which corresponds to the specified old register.RegisterValue
getNewRegisterValue(RegisterValue oldValue)
Get the translated register valueint
getNewVersion()
Returns new language versionCompilerSpec
getOldCompilerSpec(CompilerSpecID oldCompilerSpecID)
Get a compiler spec suitable for use with the old language.Register
getOldContextRegister()
Returns the old processor context register or null if not definedLanguage
getOldLanguage()
Returns old languageLanguageID
getOldLanguageID()
Returns old language nameRegister
getOldRegister(Address oldAddr, int size)
Get the old register at the specified oldAddr.Register
getOldRegisterContaining(Address oldAddr)
Get the largest old register which contains the specified oldAddrint
getOldVersion()
Returns old language versionprotected boolean
isSameRegisterConstruction(Register oldReg, Register newReg)
boolean
isValid()
Validate translator to complete initialization and ensure language compatibility.boolean
isValueTranslationRequired(Register oldReg)
Returns true if register value translation required for program context.java.lang.String
toString()
protected void
validateDefaultSpaceMap()
Build and validate the default address space map.
-
-
-
Field Detail
-
DEFAULT_COMPILER_SPEC_ID
protected static final java.lang.String DEFAULT_COMPILER_SPEC_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LanguageTranslatorAdapter
protected LanguageTranslatorAdapter(LanguageID oldLanguageID, int oldLanguageVersion, LanguageID newLanguageID, int newLanguageVersion)
Constructor for customized language translators which want to leverage some of the default language mappings. Successful construction does not guarantee the two languages can utilize the default address space mapping. This constructor- Parameters:
oldLanguageID
-oldLanguageVersion
-newLanguageID
-newLanguageVersion
-- See Also:
validateDefaultSpaceMap()
-
-
Method Detail
-
isValid
public boolean isValid()
Description copied from interface:LanguageTranslator
Validate translator to complete initialization and ensure language compatibility. This method will be invoked by the LanguageTranslatorFactory before handing out this translator.- Specified by:
isValid
in interfaceLanguageTranslator
- Returns:
- true if translator successfully validated
-
validateDefaultSpaceMap
protected final void validateDefaultSpaceMap() throws IncompatibleLanguageException
Build and validate the default address space map. This method must be invoked following instantiation if the default address space mapping will be used.- Throws:
IncompatibleLanguageException
- if a default mapping of the address spaces could not be identified.- See Also:
getNewAddressSpace(String)
-
findSpaceSameName
protected static AddressSpace findSpaceSameName(AddressSpace oldSpace, java.util.ArrayList<AddressSpace> newSpaces) throws IncompatibleLanguageException
- Throws:
IncompatibleLanguageException
-
getOldLanguage
public Language getOldLanguage()
Description copied from interface:LanguageTranslator
Returns old language- Specified by:
getOldLanguage
in interfaceLanguageTranslator
- See Also:
LanguageTranslator.isValid()
-
getOldLanguageID
public LanguageID getOldLanguageID()
Description copied from interface:LanguageTranslator
Returns old language name- Specified by:
getOldLanguageID
in interfaceLanguageTranslator
-
getOldVersion
public int getOldVersion()
Description copied from interface:LanguageTranslator
Returns old language version- Specified by:
getOldVersion
in interfaceLanguageTranslator
-
getNewLanguage
public Language getNewLanguage()
Description copied from interface:LanguageTranslator
Returns new language- Specified by:
getNewLanguage
in interfaceLanguageTranslator
-
getNewLanguageID
public LanguageID getNewLanguageID()
Description copied from interface:LanguageTranslator
Returns new language name- Specified by:
getNewLanguageID
in interfaceLanguageTranslator
-
getNewVersion
public int getNewVersion()
Description copied from interface:LanguageTranslator
Returns new language version- Specified by:
getNewVersion
in interfaceLanguageTranslator
-
getOldRegister
public Register getOldRegister(Address oldAddr, int size)
Description copied from interface:LanguageTranslator
Get the old register at the specified oldAddr. This will null if the specified address is offcut within the register. The smallest register will be returned which is greater than or equal to the specified size.- Specified by:
getOldRegister
in interfaceLanguageTranslator
- Parameters:
oldAddr
- old register address.size
- minimum register size- Returns:
- old register or null if suitable register can not be found.
- See Also:
LanguageTranslator.getOldRegisterContaining(Address)
-
getOldRegisterContaining
public Register getOldRegisterContaining(Address oldAddr)
Description copied from interface:LanguageTranslator
Get the largest old register which contains the specified oldAddr- Specified by:
getOldRegisterContaining
in interfaceLanguageTranslator
- Parameters:
oldAddr
- old register address which may be offcut- Returns:
- old register or null if suitable register can not be found.
-
getOldContextRegister
public Register getOldContextRegister()
Description copied from interface:LanguageTranslator
Returns the old processor context register or null if not defined- Specified by:
getOldContextRegister
in interfaceLanguageTranslator
-
getNewRegister
public Register getNewRegister(Register oldReg)
Description copied from interface:LanguageTranslator
Find new register which corresponds to the specified old register.- Specified by:
getNewRegister
in interfaceLanguageTranslator
- Parameters:
oldReg
- old register- Returns:
- new register or null if corresponding register not found.
-
getNewContextRegister
public Register getNewContextRegister()
Description copied from interface:LanguageTranslator
Returns the new processor context register or null if not defined- Specified by:
getNewContextRegister
in interfaceLanguageTranslator
-
getNewAddressSpace
public AddressSpace getNewAddressSpace(java.lang.String oldSpaceName)
Description copied from interface:LanguageTranslator
Translate BASE address spaces (Overlay spaces are not handled)- Specified by:
getNewAddressSpace
in interfaceLanguageTranslator
- Parameters:
oldSpaceName
- old space name- Returns:
- corresponding address space in new language
-
isValueTranslationRequired
public boolean isValueTranslationRequired(Register oldReg)
Description copied from interface:LanguageTranslator
Returns true if register value translation required for program context.- Specified by:
isValueTranslationRequired
in interfaceLanguageTranslator
- See Also:
LanguageTranslator.getNewRegisterValue(RegisterValue)
-
isSameRegisterConstruction
protected boolean isSameRegisterConstruction(Register oldReg, Register newReg)
-
getNewRegisterValue
public RegisterValue getNewRegisterValue(RegisterValue oldValue)
Description copied from interface:LanguageTranslator
Get the translated register value- Specified by:
getNewRegisterValue
in interfaceLanguageTranslator
- Parameters:
oldValue
- old register value (may not be null)- Returns:
- new register value or null if register not mapped
- See Also:
LanguageTranslator.isValueTranslationRequired(Register)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getNewCompilerSpecID
public CompilerSpecID getNewCompilerSpecID(CompilerSpecID oldCompilerSpecID)
Description copied from interface:LanguageTranslator
Obtain the new compiler specification ID given the old compiler spec ID.- Specified by:
getNewCompilerSpecID
in interfaceLanguageTranslator
- Parameters:
oldCompilerSpecID
- old compiler spec ID.- Returns:
- new compiler spec ID.
-
getOldCompilerSpec
public CompilerSpec getOldCompilerSpec(CompilerSpecID oldCompilerSpecID) throws CompilerSpecNotFoundException
Description copied from interface:LanguageTranslator
Get a compiler spec suitable for use with the old language. The compiler spec returned is intended for upgrade use only prior to the setLanguage and may be based upon compiler conventions specified in the new compiler spec returned by getNewCompilerSpec given the same compilerSpecID.- Specified by:
getOldCompilerSpec
in interfaceLanguageTranslator
- Parameters:
oldCompilerSpecID
- old compiler spec ID.- Returns:
- compiler spec for use with old language
- Throws:
CompilerSpecNotFoundException
- if new compiler spec not found based upon translator mappings.
-
fixupInstructions
public void fixupInstructions(Program program, Language oldLanguage, TaskMonitor monitor) throws java.lang.Exception, CancelledException
Description copied from interface:LanguageTranslator
Invoked after Program language upgrade has completed. Implementation of this method permits the final re-disassembled program to be examined/modified to address more complex language upgrades. This method will only be invoked on the latest translator, which means all complex multi-version post-upgrade concerns must factor in the complete language transition. The program's language information will still reflect the original pre-upgrade state, and if the program is undergoing a schema version upgrade as well, certain complex upgrades may not have been completed (e.g., Function and Variable changes). Program modifications should be restricted to instruction and instruction context changes only.- Specified by:
fixupInstructions
in interfaceLanguageTranslator
oldLanguage
- the oldest language involved in the current upgrade translation (this is passed since this is the only fixup invocation which must handle the any relevant fixup complexities when transitioning from the specified oldLanguage).monitor
- task monitor- Throws:
java.lang.Exception
- if a bad exception occurs with the post upgrade fixupCancelledException
- if upgrade cancelled
-
-