57 resources_(resourceManager), currentStartAddress_(0),
58 isStartAddressDefined_(
false) {
100 for (
int foundIndex =
sections_.size() - 1;
101 foundIndex >= 0; foundIndex--) {
116 foundSection = §ion;
128 if (foundSection == NULL) {
146 assert(foundSection != NULL);
149 foundSection->
lines.push_back(line);
158 for (
unsigned int i = 0; i <
sections_.size(); i++) {
161 for (
unsigned int j = 0; j < section.
lines.size(); j++) {
162 section.
lines[j]->initData.clear();
163 section.
lines[j]->labels.clear();
164 delete section.
lines[j];
167 section.
lines.clear();
193 std::vector<TPEF::Section*> completed;
196 std::map<std::string, UValue> addressSpaceUsedMAUs;
197 std::vector<std::string> addedLabels;
202 addressSpaceUsedMAUs, addedLabels, labels);
206 for (
unsigned int i = 0; i <
sections_.size(); i++) {
223 completed.push_back(newSection);
250 "Can't write data to instruction memory.");
263 assert(rawSection != NULL);
272 UValue currentMAUIndex = 0;
274 for (
unsigned int j = 0; j < section.
lines.size(); j++) {
277 line, dataSection, labels, currentMAUIndex);
287 for (
unsigned int i = 0; i < addedLabels.size(); i++) {
292 for (
UValue j = 0; j < completed.size(); j++) {
306 for (
UValue i = 0; i < completed.size(); i++) {
325 std::map<std::string, UValue>& addressSpaceUsedMAUs,
326 std::vector<std::string>& addedLabels,
LabelManager& labels) {
330 for (
unsigned int i = 0; i <
sections_.size(); i++) {
341 spaceLastAddress = addressSpaceUsedMAUs[section.
addressSpace];
350 "Can't start data section from address: " +
352 " first unused address in address space: " +
369 for (
unsigned int j = 0; j < section.
lines.size(); j++) {
376 for (
unsigned int k = 0;
377 k < currentLine->
labels.size(); k++) {
382 currentLine->
labels[k], dataLineAddress);
385 addedLabels.push_back(currentLine->
labels[k]);
388 dataLineAddress += currentLine->
width;
393 "Can't write data to instruction memory.");
413 addressSpaceUsedMAUs[section.
addressSpace] = dataLineAddress;
416 std::cerr <<
"Section length: " << section.
length
445 for (
unsigned int k = 0; k < line->
initData.size(); k++) {
449 bool isSigned =
false;
464 if (data.
width != 0) {
465 if (usedMAUs > data.
width) {
469 "Init field contains too long value. Reserved MAUs: " +
479 usedMAUs = data.
width;
483 if (writtenMAUs + usedMAUs > line->
width) {
487 "Data line contains too much init data. Reserved MAUs: " +
489 " Already inited MAUs: " +
500 currentMAUIndex + writtenMAUs,
501 usedMAUs,
static_cast<SValue>(value));
505 currentMAUIndex + writtenMAUs, usedMAUs, value);
513 currentMAUIndex + writtenMAUs));
516 *dataSection, *srcChunk,
518 value, usedMAUs * dataSection->
aSpace()->
MAU());
521 writtenMAUs += usedMAUs;
524 if (writtenMAUs < line->width) {
525 dataSection->
writeValue(currentMAUIndex+writtenMAUs, 1,
526 static_cast<unsigned long>(0));
558 int wordCount =
static_cast<int>(
559 ceil(
static_cast<double>(neededBits) /
560 static_cast<double>(width)));
#define assert(condition)
find Finds info of the inner loops in the false
void setCodeFileLineNumber(int lineNum)
static std::string toString(const T &source)
UValue width
Number of MAUs initialized by this data line.
std::vector< InitDataField > initData
Init data fields of data line. Uninitilized data line, if empty.
std::vector< std::string > labels
Labels of this data line.
std::string dataSpace
Address space whose MAUs are initialized.
UValue asmLineNumber
Line number where in source code this DA line is found.
void resolveDataAreaSizesAndLabelAddresses(std::map< std::string, UValue > &addressSpaceUsedMAUs, std::vector< std::string > &addedLabels, LabelManager &labels)
void addDataLine(const DataLine &origLine)
UValue writeDataLineToTPEF(DataLine *line, TPEF::DataSection *dataSection, LabelManager &labels, UValue currentMAUIndex)
void finalize(TPEF::Binary &tpef, LabelManager &labels, bool littleEndian)
DataSectionCreator(MachineResourceManager &resourceManager, AssemblyParserDiagnostic *parent)
void setAreaStartAddress(UValue address)
UValue currentStartAddress_
Start address of next line (if fixed address).
MachineResourceManager & resources_
TPEF Resources and strings.
bool isStartAddressDefined_
Is next data line address fixed.
std::vector< InternalSection > sections_
Internal data sections.
int sizeInWords(UValue value, int MAUWidth, bool isSigned) const
std::string errorMessage() const
void setCause(const Exception &cause)
std::string label
Name of the label.
LiteralOrExpression litOrExpr
Initialisation value.
UValue width
Number of MAUs that are initialized by the init field.
void removeLabel(std::string &name)
void clearLastRelocations()
UValue resolveExpressionValue(UValue asmLineNumber, LiteralOrExpression &litOrExpr)
void commitLastRelocations()
TPEF::ASpaceElement & aSpaceElement(std::string &labelName)
void addRelocation(TPEF::Section &locationSect, TPEF::SectionElement &location, TPEF::ASpaceElement &dstASpace, UValue destination, UValue bitWidth)
void addLabel(TPEF::ASpaceElement &aSpace, std::string &name, UValue value)
bool isExpression
Does object contain expression or literal.
UValue value
If literal, the literal. Otherwise not used.
bool isSigned
Sign of the value.
Expression expression
If expression the expression, Otherwise not used.
TPEF::ASpaceElement * findDataAddressSpace(std::string name)
TPEF::Chunk * stringToChunk(const std::string aStr)
void addSection(Section *section)
virtual void writeValue(Word index, Word numOfMAUs, unsigned long value)
virtual void setLengthInMAUs(Word length)
virtual Chunk * chunk(SectionOffset offset) const
virtual Word MAUsToBytes(Word mauCount) const
static Section * createSection(SectionType type)
@ ST_DATA
Initialized data section.
@ ST_UDATA
Uninitialized data section.
@ ST_LEDATA
Initialized little endian data section.
void setStartingAddress(AddressImage address)
void setASpace(const ReferenceManager::SafePointer *addrSpace)
void setName(const ReferenceManager::SafePointer *sectionName)
ASpaceElement * aSpace() const
UValue length
Number of MAUs stored in section.
UValue startAddress
The start address of the section.
std::vector< DataLine * > lines
Initialization data of the section. (or uninitialization data;)
bool isInitialized
If section contains initialization data.
bool fixedStartAddress
Is start address of the section fixed.
std::string addressSpace
Address space of the section.