OpenASIP
2.0
|
#include <DataSectionCreator.hh>
Classes | |
struct | InternalSection |
Public Member Functions | |
DataSectionCreator (MachineResourceManager &resourceManager, AssemblyParserDiagnostic *parent) | |
~DataSectionCreator () | |
void | setAreaStartAddress (UValue address) |
void | addDataLine (const DataLine &origLine) |
void | finalize (TPEF::Binary &tpef, LabelManager &labels, bool littleEndian) |
void | cleanup () |
Private Member Functions | |
void | resolveDataAreaSizesAndLabelAddresses (std::map< std::string, UValue > &addressSpaceUsedMAUs, std::vector< std::string > &addedLabels, LabelManager &labels) |
UValue | writeDataLineToTPEF (DataLine *line, TPEF::DataSection *dataSection, LabelManager &labels, UValue currentMAUIndex) |
int | sizeInWords (UValue value, int MAUWidth, bool isSigned) const |
Private Attributes | |
MachineResourceManager & | resources_ |
TPEF Resources and strings. More... | |
UValue | currentStartAddress_ |
Start address of next line (if fixed address). More... | |
bool | isStartAddressDefined_ |
Is next data line address fixed. More... | |
std::vector< InternalSection > | sections_ |
Internal data sections. More... | |
Collects data area information and parses data to tpef data sections.
Definition at line 52 of file DataSectionCreator.hh.
DataSectionCreator::DataSectionCreator | ( | MachineResourceManager & | resourceManager, |
AssemblyParserDiagnostic * | parent | ||
) |
Constructor.
resourceManager | Resource manager for TPEF to create. |
Definition at line 55 of file DataSectionCreator.cc.
DataSectionCreator::~DataSectionCreator | ( | ) |
Destructor.
Definition at line 64 of file DataSectionCreator.cc.
References cleanup().
void DataSectionCreator::addDataLine | ( | const DataLine & | origLine | ) |
Adds data line.
origLine | Parsed data line to copy to creator. |
Definition at line 84 of file DataSectionCreator.cc.
References DataSectionCreator::InternalSection::addressSpace, DataLine::asmLineNumber, assert, currentStartAddress_, DataLine::dataSpace, DataSectionCreator::InternalSection::fixedStartAddress, DataLine::initData, DataSectionCreator::InternalSection::isInitialized, isStartAddressDefined_, DataLine::labels, DataSectionCreator::InternalSection::length, DataSectionCreator::InternalSection::lines, sections_, DataSectionCreator::InternalSection::startAddress, and DataLine::width.
Referenced by AddDataLineActor::operator()().
void DataSectionCreator::cleanup | ( | ) |
Frees all internally allocated data.
Definition at line 156 of file DataSectionCreator.cc.
References currentStartAddress_, isStartAddressDefined_, DataSectionCreator::InternalSection::lines, and sections_.
Referenced by AssemblerParser::cleanup(), finalize(), and ~DataSectionCreator().
void DataSectionCreator::finalize | ( | TPEF::Binary & | tpef, |
LabelManager & | labels, | ||
bool | littleEndian | ||
) |
Writes created sections to given binary.
All data stored inside creator are freed after this call, unless exception is thrown.
In case of exception the creator restores its state to what it was before calling this method, and this method can be run again.
tpef | Binary to which created sections should be added. |
labels | LabelManager where to add data labels and relocations. |
CompileError | If there is any errors during compiling. |
Definition at line 190 of file DataSectionCreator.cc.
References __func__, DataSectionCreator::InternalSection::addressSpace, TPEF::Binary::addSection(), assert, cleanup(), LabelManager::clearLastRelocations(), LabelManager::commitLastRelocations(), Exception::errorMessage(), MachineResourceManager::findDataAddressSpace(), DataSectionCreator::InternalSection::fixedStartAddress, DataSectionCreator::InternalSection::isInitialized, DataSectionCreator::InternalSection::length, DataSectionCreator::InternalSection::lines, LabelManager::removeLabel(), resolveDataAreaSizesAndLabelAddresses(), resources_, sections_, TPEF::Section::setASpace(), Exception::setCause(), CompileError::setCodeFileLineNumber(), TPEF::RawSection::setLengthInMAUs(), TPEF::Section::setName(), TPEF::Section::setStartingAddress(), DataSectionCreator::InternalSection::startAddress, MachineResourceManager::stringToChunk(), and writeDataLineToTPEF().
Referenced by AssemblerParser::finalize().
|
private |
Resolves data area definition sizes, addresses and writes resolved data labels to label manager.
addressSpaceUsedMAUs | Table for updating number of MAUs that are used for each section. |
addedLabels | List of all labels added to label manager for error cleanup. |
labels | Label bookkeeper. |
Definition at line 324 of file DataSectionCreator.cc.
References __func__, LabelManager::addLabel(), DataSectionCreator::InternalSection::addressSpace, DataLine::asmLineNumber, MapTools::containsKey(), Exception::errorMessage(), MachineResourceManager::findDataAddressSpace(), DataSectionCreator::InternalSection::fixedStartAddress, DataLine::labels, DataSectionCreator::InternalSection::length, DataSectionCreator::InternalSection::lines, resources_, sections_, Exception::setCause(), CompileError::setCodeFileLineNumber(), DataSectionCreator::InternalSection::startAddress, Conversion::toString(), and DataLine::width.
Referenced by finalize().
void DataSectionCreator::setAreaStartAddress | ( | UValue | address | ) |
Sets fixed address for the next data area definition.
address | Start address of next data area definition. |
Definition at line 73 of file DataSectionCreator.cc.
References currentStartAddress_, and isStartAddressDefined_.
Referenced by SetStartAddressActor::operator()().
|
private |
Compute the minimum number of words of given bit width that are necessary to encode an integer value.
value | Integer value to encode. |
width | Bit width of the words. |
isSigned | Tells whether the value had a sign ('+'/'-') in front of it. |
Definition at line 544 of file DataSectionCreator.cc.
References assert, BYTE_BITWIDTH, MathTools::requiredBits(), and MathTools::requiredBitsSigned().
Referenced by writeDataLineToTPEF().
|
private |
Write one data line definition to TPEF data section.
line | Data line to write. |
dataSection | Section where to write data. |
label | Label manager to resolve label values. |
currentMAUIndex | MAU index to start of data line in TPEF. |
CompileError | the data line contains errors. |
Definition at line 439 of file DataSectionCreator.cc.
References __func__, LabelManager::addRelocation(), DataLine::asmLineNumber, TPEF::Section::aSpace(), LabelManager::aSpaceElement(), TPEF::RawSection::chunk(), LiteralOrExpression::expression, DataLine::initData, LiteralOrExpression::isExpression, LiteralOrExpression::isSigned, Expression::label, InitDataField::litOrExpr, TPEF::ASpaceElement::MAU(), TPEF::RawSection::MAUsToBytes(), LabelManager::resolveExpressionValue(), CompileError::setCodeFileLineNumber(), sizeInWords(), Conversion::toString(), LiteralOrExpression::value, InitDataField::width, DataLine::width, and TPEF::DataSection::writeValue().
Referenced by finalize().
|
private |
Start address of next line (if fixed address).
Definition at line 104 of file DataSectionCreator.hh.
Referenced by addDataLine(), cleanup(), and setAreaStartAddress().
|
private |
Is next data line address fixed.
Definition at line 106 of file DataSectionCreator.hh.
Referenced by addDataLine(), cleanup(), and setAreaStartAddress().
|
private |
TPEF Resources and strings.
Definition at line 101 of file DataSectionCreator.hh.
Referenced by finalize(), and resolveDataAreaSizesAndLabelAddresses().
|
private |
Internal data sections.
Definition at line 109 of file DataSectionCreator.hh.
Referenced by addDataLine(), cleanup(), finalize(), and resolveDataAreaSizesAndLabelAddresses().