OpenASIP
2.0
|
#include <LabelManager.hh>
Classes | |
struct | InternalLabel |
struct | InternalRelocation |
Public Member Functions | |
LabelManager (TPEF::Binary &bin, MachineResourceManager &resources, AssemblyParserDiagnostic *parent) | |
~LabelManager () | |
UValue | value (std::string &name) |
TPEF::ASpaceElement & | aSpaceElement (std::string &labelName) |
std::string | aSpaceName (std::string &labelName) |
void | addLabel (TPEF::ASpaceElement &aSpace, std::string &name, UValue value) |
void | removeLabel (std::string &name) |
void | addProcedure (std::string &name, UValue value) |
void | setGlobal (std::string &labelName) |
void | addRelocation (TPEF::Section &locationSect, TPEF::SectionElement &location, TPEF::ASpaceElement &dstASpace, UValue destination, UValue bitWidth) |
void | clearLastRelocations () |
void | commitLastRelocations () |
void | finalize () |
void | cleanup () |
UValue | resolveExpressionValue (UValue asmLineNumber, LiteralOrExpression &litOrExpr) |
Private Types | |
typedef std::map< std::string, InternalLabel * > | SymbolMap |
Private Member Functions | |
TPEF::Section * | findSectionByAddress (InternalLabel *currLabel) |
TPEF::SymbolElement * | createSymbolWithReference (InternalLabel *currLabel, TPEF::Section *ownerSection) |
void | writeProcedureSymbols (TPEF::CodeSection *codeSect, TPEF::SymbolSection *symbolSect, TPEF::StringSection *strings) |
TPEF::RelocSection * | findOrCreateRelocationSection (InternalRelocation *currReloc, TPEF::SymbolSection *symbolSect) |
TPEF::Section * | findRelocationDstSection (InternalRelocation *currReloc) |
Private Attributes | |
SymbolMap | labels_ |
Contains stored symbols by their name. More... | |
std::set< InternalRelocation * > | relocs_ |
Added relocations. More... | |
std::set< InternalRelocation * > | uncommittedRelocs_ |
Uncommitted relocations. More... | |
std::set< std::string > | globals_ |
Names of global symbols. More... | |
std::map< std::string, UValue > | procedures_ |
Names and addresses of procedure starts. More... | |
TPEF::Binary & | bin_ |
For finding sections containing relocated elements. More... | |
MachineResourceManager & | resources_ |
Common resources of TPEF. More... | |
Keeps track of labels, symbols and relocations.
After all label and relocation information if added, class knows how to write SymbolSection and RelocationSectios to TPEF.
Definition at line 64 of file LabelManager.hh.
|
private |
Definition at line 148 of file LabelManager.hh.
LabelManager::LabelManager | ( | TPEF::Binary & | bin, |
MachineResourceManager & | resources, | ||
AssemblyParserDiagnostic * | parent | ||
) |
Constructor.
bin | Binary containing data and code sections of relocations. |
resources | Resource manager for getting TPEF resources. |
parent | Assembler root class. |
Definition at line 83 of file LabelManager.cc.
LabelManager::~LabelManager | ( | ) |
Destructor.
Definition at line 93 of file LabelManager.cc.
References MapTools::deleteAllValues(), labels_, and relocs_.
void LabelManager::addLabel | ( | TPEF::ASpaceElement & | aSpace, |
std::string & | name, | ||
UValue | value | ||
) |
Adds a label to manager.
aSpace | Address space of the label to add. |
name | Name of the label. |
value | Value for the label. |
ObjectAlreadyExists | Label by the same name already exists. |
Definition at line 160 of file LabelManager.cc.
References __func__, LabelManager::InternalLabel::aSpace, MapTools::containsKey(), labels_, LabelManager::InternalLabel::name, value(), and LabelManager::InternalLabel::value.
Referenced by AddLabelActor::operator()(), and DataSectionCreator::resolveDataAreaSizesAndLabelAddresses().
void LabelManager::addProcedure | ( | std::string & | name, |
UValue | address | ||
) |
Adds a procedure to manager.
name | Name of the procedure |
address | Start address of the procedure. |
ObjectAlreadyExists | Procedure with a same name is already added. |
Definition at line 201 of file LabelManager.cc.
References __func__, MapTools::containsKey(), and procedures_.
Referenced by AddProcedureActor::operator()().
void LabelManager::addRelocation | ( | TPEF::Section & | locationSect, |
TPEF::SectionElement & | location, | ||
TPEF::ASpaceElement & | dstASpace, | ||
UValue | destination, | ||
UValue | bitWidth | ||
) |
Adds relocated immediate or data chunk.
locationSect | Section where relocated element is stored. |
location | Immediate or Chunk containing value to relocate. |
dstASpace | Destination address space of relocation. |
destination | Destination address of relocation. |
bitWidth | Size of the relocated field. |
Definition at line 231 of file LabelManager.cc.
References LabelManager::InternalRelocation::bitWidth, LabelManager::InternalRelocation::destination, LabelManager::InternalRelocation::dstASpace, LabelManager::InternalRelocation::location, LabelManager::InternalRelocation::locationSect, and uncommittedRelocs_.
Referenced by CodeSectionCreator::finalize(), and DataSectionCreator::writeDataLineToTPEF().
ASpaceElement & LabelManager::aSpaceElement | ( | std::string & | labelName | ) |
Returns a TPEF address space element for a label by name.
labelName | Name of the requested label. |
SymbolNotFound | If there is not symbol for requested name. |
Definition at line 129 of file LabelManager.cc.
References __func__, MapTools::containsKey(), and labels_.
Referenced by aSpaceName(), CodeSectionCreator::finalize(), and DataSectionCreator::writeDataLineToTPEF().
std::string LabelManager::aSpaceName | ( | std::string & | labelName | ) |
Returns the name of the address space for a label.
labelName | Name of the requested label. |
SymbolNotFound | If there is not symbol for requested name. |
Definition at line 147 of file LabelManager.cc.
References aSpaceElement(), and bin_.
Referenced by CodeSectionCreator::finalize().
void LabelManager::cleanup | ( | ) |
Frees all internally allocated data.
Definition at line 263 of file LabelManager.cc.
References SequenceTools::deleteAllItems(), MapTools::deleteAllValues(), globals_, labels_, procedures_, relocs_, and uncommittedRelocs_.
Referenced by AssemblerParser::cleanup(), and finalize().
void LabelManager::clearLastRelocations | ( | ) |
Removes relocations that are added but not committed to manager.
Used for cleaning up in error cases.
Definition at line 255 of file LabelManager.cc.
References SequenceTools::deleteAllItems(), and uncommittedRelocs_.
Referenced by DataSectionCreator::finalize(), and CodeSectionCreator::finalize().
void LabelManager::commitLastRelocations | ( | ) |
Adds permanently relocations that are added but not yet committed to manager.
Definition at line 276 of file LabelManager.cc.
References relocs_, and uncommittedRelocs_.
Referenced by DataSectionCreator::finalize(), and CodeSectionCreator::finalize().
|
private |
Creates new TPEF SymbolElement and sets reference field of symbol.
currLabel | Label which for symbol element is created. |
ownerSection | Section who contains element referred by label. |
Definition at line 507 of file LabelManager.cc.
References TPEF::RawSection::chunk(), TPEF::CodeSection::instruction(), TPEF::Section::isCodeSection(), TPEF::RawSection::MAUsToBytes(), TPEF::DataSymElement::setReference(), TPEF::CodeSymElement::setReference(), TPEF::Section::startingAddress(), and LabelManager::InternalLabel::value.
Referenced by finalize().
void LabelManager::finalize | ( | ) |
Creates symbol and relocation tables corresponding to input information.
All destinations must exist in TPEF before this method can be executed, otherwise finalize will throw exception. If exception is thrown finalize method will not do any changes to TPEF. When error that caused the exception is fixed, method can be re-executed and it continues from the same phase until the end.
CompileError | There was problems during the resolving. |
Definition at line 301 of file LabelManager.cc.
References __func__, abortWithError, TPEF::Section::addElement(), TPEF::Binary::addSection(), assert, bin_, LabelManager::InternalRelocation::bitWidth, TPEF::RawSection::chunk(), cleanup(), ContainerTools::containsValue(), createSymbolWithReference(), LabelManager::InternalRelocation::destination, LabelManager::InternalRelocation::dstASpace, findOrCreateRelocationSection(), findRelocationDstSection(), findSectionByAddress(), globals_, TPEF::CodeSection::instruction(), TPEF::Section::isCodeSection(), labels_, LabelManager::InternalRelocation::location, TPEF::RawSection::MAUsToBytes(), LabelManager::InternalLabel::name, procedures_, relocs_, resources_, TPEF::Binary::section(), TPEF::Binary::sectionCount(), TPEF::SymbolElement::setAbsolute(), TPEF::RelocElement::setASpace(), TPEF::Section::setASpace(), TPEF::SymbolElement::setBinding(), TPEF::RelocElement::setChunked(), TPEF::RelocElement::setDestination(), TPEF::Section::setLink(), TPEF::RelocElement::setLocation(), TPEF::SymbolElement::setName(), TPEF::SymbolElement::setSection(), TPEF::RelocElement::setSize(), TPEF::RelocElement::setSymbol(), TPEF::RelocElement::setType(), TPEF::Section::startingAddress(), TPEF::StringSection::string2Chunk(), MachineResourceManager::stringSection(), Conversion::toString(), TPEF::Section::type(), MachineResourceManager::undefinedAddressSpace(), and writeProcedureSymbols().
Referenced by AssemblerParser::finalize().
|
private |
Finds or creates relocation section for relocation.
currReloc | Relocation whose section is looked for. |
symbolSect | Strings for created section. |
Definition at line 590 of file LabelManager.cc.
References TPEF::Binary::addSection(), bin_, LabelManager::InternalRelocation::locationSect, TPEF::RelocSection::referencedSection(), resources_, TPEF::Binary::section(), TPEF::Binary::sectionCount(), TPEF::Section::setASpace(), TPEF::Section::setLink(), TPEF::RelocSection::setReferencedSection(), and MachineResourceManager::undefinedAddressSpace().
Referenced by finalize().
|
private |
Returns destination section of the relocation.
currReloc | Relocation whose destination is wanted. |
Definition at line 628 of file LabelManager.cc.
References TPEF::Section::aSpace(), bin_, LabelManager::InternalRelocation::destination, LabelManager::InternalRelocation::dstASpace, TPEF::CodeSection::instructionCount(), TPEF::Section::isCodeSection(), TPEF::RawSection::lengthInMAUs(), TPEF::Binary::section(), TPEF::Binary::sectionCount(), TPEF::Section::startingAddress(), and TPEF::Section::type().
Referenced by finalize().
|
private |
Returns section that contains the address stored in label.
currLabel | Label whose destination section is returned. |
Definition at line 452 of file LabelManager.cc.
References abortWithError, LabelManager::InternalLabel::aSpace, TPEF::Section::aSpace(), assert, bin_, TPEF::CodeSection::instructionCount(), TPEF::Section::isCodeSection(), TPEF::RawSection::lengthInMAUs(), TPEF::Binary::section(), TPEF::Binary::sectionCount(), TPEF::Section::startingAddress(), TPEF::Section::type(), and LabelManager::InternalLabel::value.
Referenced by finalize().
void LabelManager::removeLabel | ( | std::string & | name | ) |
Removes a label from manager.
name | Name of the label. |
SymbolNotFound | Label is not found. |
Definition at line 183 of file LabelManager.cc.
References __func__, MapTools::containsKey(), and labels_.
Referenced by DataSectionCreator::finalize().
UValue LabelManager::resolveExpressionValue | ( | UValue | asmLineNumber, |
LiteralOrExpression & | litOrExpr | ||
) |
Resolves value of label expression.
asmLineNumber | Current assembly code line number error information. |
litOrExpr | Expression whose value to resolve. |
labels | Label manager for resolving label values. |
CompileError | There was error with resolving value. |
Definition at line 678 of file LabelManager.cc.
References __func__, Exception::errorMessage(), LiteralOrExpression::expression, Expression::hasOffset, Expression::hasValue, Expression::isMinus, Expression::label, Expression::offset, Exception::setCause(), CompileError::setCodeFileLineNumber(), Conversion::toString(), value(), and Expression::value.
Referenced by CodeSectionCreator::addAnnotationes(), CodeSectionCreator::finalize(), and DataSectionCreator::writeDataLineToTPEF().
void LabelManager::setGlobal | ( | std::string & | labelName | ) |
Set's label to be global label.
labelName | Name of label to set global. |
Definition at line 217 of file LabelManager.cc.
References globals_.
Referenced by SetGlobalActor::operator()().
UValue LabelManager::value | ( | std::string & | name | ) |
Returns value of a label by name.
name | Name of the requested label. |
SymbolNotFound | If there is not symbol for requested name. |
Definition at line 110 of file LabelManager.cc.
References __func__, MapTools::containsKey(), and labels_.
Referenced by addLabel(), and resolveExpressionValue().
|
private |
Writes all procedure symbols of code section to symbol section.
codeSect | Section whose symbols are written. |
symbolSect | Section where to symbols are written. |
string | Sectiong where symbol strings are stored. |
CompileError | Procedure declaration is is not in code section. |
Definition at line 548 of file LabelManager.cc.
References __func__, TPEF::Section::addElement(), TPEF::CodeSection::instruction(), TPEF::CodeSection::instructionCount(), procedures_, TPEF::SymbolElement::setAbsolute(), TPEF::SymbolElement::setBinding(), TPEF::SymbolElement::setName(), TPEF::CodeSymElement::setReference(), TPEF::SymbolElement::setSection(), TPEF::Section::startingAddress(), and TPEF::StringSection::string2Chunk().
Referenced by finalize().
|
private |
For finding sections containing relocated elements.
Definition at line 166 of file LabelManager.hh.
Referenced by aSpaceName(), finalize(), findOrCreateRelocationSection(), findRelocationDstSection(), and findSectionByAddress().
|
private |
Names of global symbols.
Definition at line 160 of file LabelManager.hh.
Referenced by cleanup(), finalize(), and setGlobal().
|
private |
Contains stored symbols by their name.
Definition at line 151 of file LabelManager.hh.
Referenced by addLabel(), aSpaceElement(), cleanup(), finalize(), removeLabel(), value(), and ~LabelManager().
|
private |
Names and addresses of procedure starts.
Definition at line 163 of file LabelManager.hh.
Referenced by addProcedure(), cleanup(), finalize(), and writeProcedureSymbols().
|
private |
Added relocations.
Definition at line 154 of file LabelManager.hh.
Referenced by cleanup(), commitLastRelocations(), finalize(), and ~LabelManager().
|
private |
Common resources of TPEF.
Definition at line 169 of file LabelManager.hh.
Referenced by finalize(), and findOrCreateRelocationSection().
|
private |
Uncommitted relocations.
Definition at line 157 of file LabelManager.hh.
Referenced by addRelocation(), cleanup(), clearLastRelocations(), and commitLastRelocations().