Package ghidra.program.util
Class LanguageTranslatorAdapter
java.lang.Object
ghidra.program.util.LanguageTranslatorAdapter
- All Implemented Interfaces:
LanguageTranslator
,ExtensionPoint
- Direct Known Subclasses:
ProgramArchitectureTranslator
LanguageTranslatorAdapter
provides a default language translator
behavior which may be extended to provide customized language translations.-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
LanguageTranslatorAdapter
(LanguageID oldLanguageID, int oldLanguageVersion, LanguageID newLanguageID, int newLanguageVersion) Constructor for customized language translators which want to leverage some of the default language mappings.protected
LanguageTranslatorAdapter
(Language oldLanguage, Language newLanguage) Constructor for default translator. -
Method Summary
Modifier and TypeMethodDescriptionprotected static AddressSpace
findSpaceSameName
(AddressSpace oldSpace, ArrayList<AddressSpace> newSpaces) void
fixupInstructions
(Program program, Language oldLanguage, TaskMonitor monitor) Invoked after Program language upgrade has completed.static LanguageTranslator
getDefaultLanguageTranslator
(Language oldLanguage, Language newLanguage) Return a validated default translator if one can be determined.getNewAddressSpace
(String oldSpaceName) Translate BASE address spaces (Overlay spaces are not handled)getNewCompilerSpecID
(CompilerSpecID oldCompilerSpecID) Obtain the new compiler specification ID given the old compiler spec ID.Returns the new processor context register or null if not definedReturns new languageReturns new language namegetNewRegister
(Register oldReg) Find new register which corresponds to the specified old register.getNewRegisterValue
(RegisterValue oldValue) Get the translated register valueint
Returns new language versiongetOldCompilerSpec
(CompilerSpecID oldCompilerSpecID) Get a compiler spec suitable for use with the old language.Returns the old processor context register or null if not definedReturns old languageReturns old language namegetOldRegister
(Address oldAddr, int size) Get the old register at the specified oldAddr.getOldRegisterContaining
(Address oldAddr) Get the largest old register which contains the specified oldAddrint
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.toString()
protected final void
Build and validate the default address space map.
-
Field Details
-
DEFAULT_COMPILER_SPEC_ID
- See Also:
-
-
Constructor Details
-
LanguageTranslatorAdapter
Constructor for default translator.- Parameters:
oldLanguage
-newLanguage
-
-
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:
-
-
Method Details
-
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
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:
-
findSpaceSameName
protected static AddressSpace findSpaceSameName(AddressSpace oldSpace, ArrayList<AddressSpace> newSpaces) throws IncompatibleLanguageException - Throws:
IncompatibleLanguageException
-
getOldLanguage
Description copied from interface:LanguageTranslator
Returns old language- Specified by:
getOldLanguage
in interfaceLanguageTranslator
- See Also:
-
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
Description copied from interface:LanguageTranslator
Returns new language- Specified by:
getNewLanguage
in interfaceLanguageTranslator
-
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
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:
-
getOldRegisterContaining
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
Description copied from interface:LanguageTranslator
Returns the old processor context register or null if not defined- Specified by:
getOldContextRegister
in interfaceLanguageTranslator
-
getNewRegister
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
Description copied from interface:LanguageTranslator
Returns the new processor context register or null if not defined- Specified by:
getNewContextRegister
in interfaceLanguageTranslator
-
getNewAddressSpace
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
Description copied from interface:LanguageTranslator
Returns true if register value translation required for program context.- Specified by:
isValueTranslationRequired
in interfaceLanguageTranslator
- Parameters:
oldReg
-- See Also:
-
isSameRegisterConstruction
-
getNewRegisterValue
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:
-
toString
-
getNewCompilerSpecID
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 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
- Parameters:
program
-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:
Exception
- if a bad exception occurs with the post upgrade fixupCancelledException
- if upgrade cancelled
-
getDefaultLanguageTranslator
public static LanguageTranslator getDefaultLanguageTranslator(Language oldLanguage, Language newLanguage) Return a validated default translator if one can be determined.- Parameters:
oldLanguage
-newLanguage
-- Returns:
- default translator or null if reasonable mappings can not be determined.
-