mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Use automatic allocation for section names
This commit is contained in:
@@ -30,7 +30,7 @@ struct Patch {
|
||||
|
||||
struct Section {
|
||||
// Info contained in the object files
|
||||
std::string *name;
|
||||
std::string name;
|
||||
uint16_t size;
|
||||
uint16_t offset;
|
||||
enum SectionType type;
|
||||
|
||||
@@ -318,17 +318,17 @@ static void placeSection(struct Section *section)
|
||||
// If a section failed to go to several places, nothing we can report
|
||||
if (!section->isBankFixed || !section->isAddressFixed)
|
||||
errx("Unable to place \"%s\" (%s section) %s",
|
||||
section->name->c_str(), sectionTypeInfo[section->type].name.c_str(), where);
|
||||
section->name.c_str(), sectionTypeInfo[section->type].name.c_str(), where);
|
||||
// If the section just can't fit the bank, report that
|
||||
else if (section->org + section->size > endaddr(section->type) + 1)
|
||||
errx("Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > $%04x)",
|
||||
section->name->c_str(), sectionTypeInfo[section->type].name.c_str(), where,
|
||||
section->name.c_str(), sectionTypeInfo[section->type].name.c_str(), where,
|
||||
section->org + section->size, endaddr(section->type) + 1);
|
||||
// Otherwise there is overlap with another section
|
||||
else
|
||||
errx("Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"",
|
||||
section->name->c_str(), sectionTypeInfo[section->type].name.c_str(), where,
|
||||
out_OverlappingSection(section)->name->c_str());
|
||||
section->name.c_str(), sectionTypeInfo[section->type].name.c_str(), where,
|
||||
out_OverlappingSection(section)->name.c_str());
|
||||
}
|
||||
|
||||
#define BANK_CONSTRAINED (1 << 2)
|
||||
@@ -396,7 +396,7 @@ void assign_AssignSections(void)
|
||||
constraints >= 0; constraints--) {
|
||||
for (struct Section *section : unassignedSections[constraints]) {
|
||||
fprintf(stderr, "%c \"%s\"", nbSections == 0 ? ';': ',',
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
nbSections++;
|
||||
if (nbSections == 10)
|
||||
goto max_out;
|
||||
|
||||
@@ -219,7 +219,7 @@ static void readSymbol(FILE *file, struct Symbol *symbol, char const *fileName,
|
||||
* @param fileName The filename to report in errors
|
||||
* @param i The number of the patch to report in errors
|
||||
*/
|
||||
static void readPatch(FILE *file, struct Patch *patch, char const *fileName, char const *sectName,
|
||||
static void readPatch(FILE *file, struct Patch *patch, char const *fileName, std::string const §Name,
|
||||
uint32_t i, std::vector<struct FileStackNode> const &fileNodes)
|
||||
{
|
||||
uint32_t nodeID, rpnSize;
|
||||
@@ -227,34 +227,34 @@ static void readPatch(FILE *file, struct Patch *patch, char const *fileName, cha
|
||||
|
||||
tryReadlong(nodeID, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s node ID: %s",
|
||||
fileName, sectName, i);
|
||||
fileName, sectName.c_str(), i);
|
||||
patch->src = &fileNodes[nodeID];
|
||||
tryReadlong(patch->lineNo, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s line number: %s",
|
||||
fileName, sectName, i);
|
||||
fileName, sectName.c_str(), i);
|
||||
tryReadlong(patch->offset, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s offset: %s",
|
||||
fileName, sectName, i);
|
||||
fileName, sectName.c_str(), i);
|
||||
tryReadlong(patch->pcSectionID, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s PC offset: %s",
|
||||
fileName, sectName, i);
|
||||
fileName, sectName.c_str(), i);
|
||||
tryReadlong(patch->pcOffset, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s PC offset: %s",
|
||||
fileName, sectName, i);
|
||||
fileName, sectName.c_str(), i);
|
||||
tryGetc(enum PatchType, type, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s type: %s",
|
||||
fileName, sectName, i);
|
||||
fileName, sectName.c_str(), i);
|
||||
patch->type = type;
|
||||
tryReadlong(rpnSize, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s RPN size: %s",
|
||||
fileName, sectName, i);
|
||||
fileName, sectName.c_str(), i);
|
||||
|
||||
patch->rpnExpression.resize(rpnSize);
|
||||
size_t nbElementsRead = fread(&patch->rpnExpression[0], 1, rpnSize, file);
|
||||
|
||||
if (nbElementsRead != rpnSize)
|
||||
errx("%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
|
||||
fileName, sectName, i,
|
||||
fileName, sectName.c_str(), i,
|
||||
feof(file) ? "Unexpected end of file" : strerror(errno));
|
||||
}
|
||||
|
||||
@@ -279,15 +279,18 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
{
|
||||
int32_t tmp;
|
||||
uint8_t byte;
|
||||
std::string *str;
|
||||
|
||||
tryReadstring(section->name, file, "%s: Cannot read section name: %s", fileName);
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s' size: %s", fileName, section->name->c_str());
|
||||
tryReadstring(str, file, "%s: Cannot read section name: %s", fileName);
|
||||
section->name = *str;
|
||||
delete str;
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s' size: %s", fileName, section->name.c_str());
|
||||
if (tmp < 0 || tmp > UINT16_MAX)
|
||||
errx("\"%s\"'s section size (%" PRId32 ") is invalid", section->name->c_str(), tmp);
|
||||
errx("\"%s\"'s section size (%" PRId32 ") is invalid", section->name.c_str(), tmp);
|
||||
section->size = tmp;
|
||||
section->offset = 0;
|
||||
tryGetc(uint8_t, byte, file, "%s: Cannot read \"%s\"'s type: %s", fileName,
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
section->type = (enum SectionType)(byte & 0x3F);
|
||||
if (byte >> 7)
|
||||
section->modifier = SECTION_UNION;
|
||||
@@ -295,27 +298,27 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
section->modifier = SECTION_FRAGMENT;
|
||||
else
|
||||
section->modifier = SECTION_NORMAL;
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s org: %s", fileName, section->name->c_str());
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s org: %s", fileName, section->name.c_str());
|
||||
section->isAddressFixed = tmp >= 0;
|
||||
if (tmp > UINT16_MAX) {
|
||||
error(NULL, 0, "\"%s\"'s org is too large (%" PRId32 ")", section->name->c_str(), tmp);
|
||||
error(NULL, 0, "\"%s\"'s org is too large (%" PRId32 ")", section->name.c_str(), tmp);
|
||||
tmp = UINT16_MAX;
|
||||
}
|
||||
section->org = tmp;
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s bank: %s", fileName, section->name->c_str());
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s bank: %s", fileName, section->name.c_str());
|
||||
section->isBankFixed = tmp >= 0;
|
||||
section->bank = tmp;
|
||||
tryGetc(uint8_t, byte, file, "%s: Cannot read \"%s\"'s alignment: %s", fileName,
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
if (byte > 16)
|
||||
byte = 16;
|
||||
section->isAlignFixed = byte != 0;
|
||||
section->alignMask = (1 << byte) - 1;
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s alignment offset: %s", fileName,
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
if (tmp > UINT16_MAX) {
|
||||
error(NULL, 0, "\"%s\"'s alignment offset is too large (%" PRId32 ")",
|
||||
section->name->c_str(), tmp);
|
||||
section->name.c_str(), tmp);
|
||||
tmp = UINT16_MAX;
|
||||
}
|
||||
section->alignOfs = tmp;
|
||||
@@ -323,11 +326,11 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
if (sect_HasData(section->type)) {
|
||||
section->data = new(std::nothrow) std::vector<uint8_t>(section->size);
|
||||
if (!section->data)
|
||||
err("%s: Unable to read \"%s\"'s data", fileName, section->name->c_str());
|
||||
err("%s: Unable to read \"%s\"'s data", fileName, section->name.c_str());
|
||||
if (section->size) {
|
||||
if (size_t nbRead = fread(&(*section->data)[0], 1, section->size, file);
|
||||
nbRead != section->size)
|
||||
errx("%s: Cannot read \"%s\"'s data: %s", fileName, section->name->c_str(),
|
||||
errx("%s: Cannot read \"%s\"'s data: %s", fileName, section->name.c_str(),
|
||||
feof(file) ? "Unexpected end of file" : strerror(errno));
|
||||
}
|
||||
|
||||
@@ -335,12 +338,12 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
|
||||
tryReadlong(nbPatches, file,
|
||||
"%s: Cannot read \"%s\"'s number of patches: %s", fileName,
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
|
||||
section->patches.resize(nbPatches);
|
||||
for (uint32_t i = 0; i < nbPatches; i++)
|
||||
readPatch(file, §ion->patches[i], fileName, section->name->c_str(),
|
||||
i, fileNodes);
|
||||
readPatch(file, §ion->patches[i], fileName, section->name, i,
|
||||
fileNodes);
|
||||
} else {
|
||||
section->data = NULL; // `mergeSections()` expects to be able to always read the ptr
|
||||
}
|
||||
@@ -387,7 +390,7 @@ static void readAssertion(FILE *file, struct Assertion *assert, char const *file
|
||||
static struct Section *getMainSection(struct Section *section)
|
||||
{
|
||||
if (section->modifier != SECTION_NORMAL)
|
||||
section = sect_GetSection(*section->name);
|
||||
section = sect_GetSection(section->name);
|
||||
|
||||
return section;
|
||||
}
|
||||
@@ -569,7 +572,6 @@ static void freeSection(struct Section *section)
|
||||
do {
|
||||
struct Section *next = section->nextu;
|
||||
|
||||
delete section->name;
|
||||
if (sect_HasData(section->type))
|
||||
delete section->data;
|
||||
delete section->symbols;
|
||||
|
||||
@@ -71,7 +71,7 @@ void out_AddSection(struct Section const *section)
|
||||
|
||||
if (minNbBanks > maxNbBanks[section->type])
|
||||
errx("Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")",
|
||||
section->name->c_str(), section->bank,
|
||||
section->name.c_str(), section->bank,
|
||||
maxNbBanks[section->type] - 1);
|
||||
|
||||
for (uint32_t i = sections[section->type].size(); i < minNbBanks; i++)
|
||||
@@ -408,10 +408,10 @@ static void writeMapBank(struct SortedSections const §List, enum SectionType
|
||||
fprintf(mapFile, "\tSECTION: $%04" PRIx16 "-$%04x ($%04" PRIx16
|
||||
" byte%s) [\"%s\"]\n",
|
||||
sect->org, prevEndAddr - 1, sect->size, sect->size == 1 ? "" : "s",
|
||||
sect->name->c_str());
|
||||
sect->name.c_str());
|
||||
else
|
||||
fprintf(mapFile, "\tSECTION: $%04" PRIx16 " (0 bytes) [\"%s\"]\n",
|
||||
sect->org, sect->name->c_str());
|
||||
sect->org, sect->name.c_str());
|
||||
|
||||
if (!noSymInMap) {
|
||||
// Also print symbols in the following "pieces"
|
||||
|
||||
@@ -451,7 +451,7 @@ void patch_CheckAssertions(std::deque<struct Assertion> &assertions)
|
||||
*/
|
||||
static void applyFilePatches(struct Section *section, struct Section *dataSection)
|
||||
{
|
||||
verbosePrint("Patching section \"%s\"...\n", section->name->c_str());
|
||||
verbosePrint("Patching section \"%s\"...\n", section->name.c_str());
|
||||
for (struct Patch &patch : section->patches) {
|
||||
int32_t value = computeRPNExpr(&patch, *section->fileSymbols);
|
||||
uint16_t offset = patch.offset + section->offset;
|
||||
|
||||
@@ -264,7 +264,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
assert(strlen(token) != 0); // This should be impossible, tokens are non-empty
|
||||
// The following is required for fragment offsets to be reliably predicted
|
||||
for (struct FileSection &entry : fileSections) {
|
||||
if (!strcmp(token, entry.section->name->c_str()))
|
||||
if (!strcmp(token, entry.section->name.c_str()))
|
||||
fatal(where, lineNo, "Area \"%s\" already defined earlier",
|
||||
token);
|
||||
}
|
||||
@@ -280,7 +280,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
|
||||
if (tmp > UINT16_MAX)
|
||||
fatal(where, lineNo, "Area \"%s\" is larger than the GB address space!?",
|
||||
curSection->name->c_str());
|
||||
curSection->name.c_str());
|
||||
curSection->size = tmp;
|
||||
|
||||
expectToken("flags", 'A');
|
||||
@@ -293,16 +293,12 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
curSection->isBankFixed = curSection->isAddressFixed;
|
||||
curSection->modifier = curSection->isAddressFixed || (tmp & (1 << AREA_TYPE))
|
||||
? SECTION_NORMAL : SECTION_FRAGMENT;
|
||||
curSection->name = new(std::nothrow) std::string();
|
||||
if (!curSection->name)
|
||||
fatal(where, lineNo, "Failed to alloc new area's name: %s",
|
||||
strerror(errno));
|
||||
// If the section is absolute, its name might not be unique; thus, mangle the name
|
||||
if (curSection->modifier == SECTION_NORMAL) {
|
||||
curSection->name->append(where->name());
|
||||
curSection->name->append(" ");
|
||||
curSection->name.append(where->name());
|
||||
curSection->name.append(" ");
|
||||
}
|
||||
curSection->name->append(sectionName);
|
||||
curSection->name.append(sectionName);
|
||||
|
||||
expectToken("addr", 'A');
|
||||
|
||||
@@ -470,7 +466,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
if (section->isAddressFixed) {
|
||||
if (addr < section->org)
|
||||
fatal(where, lineNo, "'T' line reports address $%04" PRIx16 " in \"%s\", which starts at $%04" PRIx16,
|
||||
addr, section->name->c_str(), section->org);
|
||||
addr, section->name.c_str(), section->org);
|
||||
addr -= section->org;
|
||||
}
|
||||
// Lines are emitted that violate this check but contain no "payload";
|
||||
@@ -484,7 +480,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
section->data = new(std::nothrow) std::vector<uint8_t>(section->size);
|
||||
if (!section->data)
|
||||
fatal(where, lineNo, "Failed to alloc data for \"%s\": %s",
|
||||
section->name->c_str(), strerror(errno));
|
||||
section->name.c_str(), strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,8 +609,8 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
// the section gets moved for any reason.
|
||||
if (fileSections[idx].section->isAddressFixed)
|
||||
baseValue -= fileSections[idx].section->org;
|
||||
std::string const *name = fileSections[idx].section->name;
|
||||
struct Section const *other = sect_GetSection(*name);
|
||||
std::string const &name = fileSections[idx].section->name;
|
||||
struct Section const *other = sect_GetSection(name);
|
||||
|
||||
// Unlike with `s_<AREA>`, referencing an area in this way
|
||||
// wants the beginning of this fragment, so we must add the
|
||||
@@ -626,10 +622,10 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
// current size.
|
||||
if (other)
|
||||
baseValue += other->size;
|
||||
patch.rpnExpression.resize(1 + name->length() + 1);
|
||||
patch.rpnExpression.resize(1 + name.length() + 1);
|
||||
patch.rpnExpression[0] = RPN_STARTOF_SECT;
|
||||
// The cast is fine, it's just different signedness
|
||||
memcpy((char *)&patch.rpnExpression[1], name->c_str(), name->length() + 1);
|
||||
memcpy((char *)&patch.rpnExpression[1], name.c_str(), name.length() + 1);
|
||||
}
|
||||
|
||||
patch.rpnExpression.push_back(RPN_CONST);
|
||||
@@ -645,7 +641,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
if (flags & 1 << RELOC_EXPR16) {
|
||||
if (*writeIndex + (offset - writtenOfs) > section->size)
|
||||
fatal(where, lineNo, "'T' line writes past \"%s\"'s end (%u > %" PRIu16 ")",
|
||||
section->name->c_str(), *writeIndex + (offset - writtenOfs), section->size);
|
||||
section->name.c_str(), *writeIndex + (offset - writtenOfs), section->size);
|
||||
// Copy all bytes up to those (plus the byte that we'll overwrite)
|
||||
memcpy(&(*section->data)[*writeIndex], &data[writtenOfs], offset - writtenOfs + 1);
|
||||
*writeIndex += offset - writtenOfs + 1;
|
||||
@@ -694,7 +690,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
assert(nbBytes > writtenOfs);
|
||||
if (*writeIndex + (nbBytes - writtenOfs) > section->size)
|
||||
fatal(where, lineNo, "'T' line writes past \"%s\"'s end (%zu > %" PRIu16 ")",
|
||||
section->name->c_str(), *writeIndex + (nbBytes - writtenOfs), section->size);
|
||||
section->name.c_str(), *writeIndex + (nbBytes - writtenOfs), section->size);
|
||||
memcpy(&(*section->data)[*writeIndex], &data[writtenOfs], nbBytes - writtenOfs);
|
||||
*writeIndex += nbBytes - writtenOfs;
|
||||
}
|
||||
@@ -727,7 +723,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
|
||||
// RAM sections can have a size, but don't get any data (they shouldn't have any)
|
||||
if (entry.writeIndex != section->size && entry.writeIndex != 0)
|
||||
fatal(where, lineNo, "\"%s\" was not fully written (%" PRIu16 " < %" PRIu16 ")",
|
||||
section->name->c_str(), entry.writeIndex, section->size);
|
||||
section->name.c_str(), entry.writeIndex, section->size);
|
||||
|
||||
// This must be done last, so that `->data` is not NULL anymore
|
||||
sect_AddSection(section);
|
||||
|
||||
@@ -27,12 +27,12 @@ static void checkSectUnionCompat(struct Section *target, struct Section *other)
|
||||
if (target->isAddressFixed) {
|
||||
if (target->org != other->org)
|
||||
errx("Section \"%s\" is defined with conflicting addresses $%04"
|
||||
PRIx16 " and $%04" PRIx16, other->name->c_str(), target->org,
|
||||
PRIx16 " and $%04" PRIx16, other->name.c_str(), target->org,
|
||||
other->org);
|
||||
} else if (target->isAlignFixed) {
|
||||
if ((other->org - target->alignOfs) & target->alignMask)
|
||||
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
PRIu16 ") and address $%04" PRIx16, other->name->c_str(),
|
||||
PRIu16 ") and address $%04" PRIx16, other->name.c_str(),
|
||||
target->alignMask + 1, target->alignOfs, other->org);
|
||||
}
|
||||
target->isAddressFixed = true;
|
||||
@@ -43,14 +43,14 @@ static void checkSectUnionCompat(struct Section *target, struct Section *other)
|
||||
if ((target->org - other->alignOfs) & other->alignMask)
|
||||
errx("Section \"%s\" is defined with conflicting address $%04"
|
||||
PRIx16 " and %d-byte alignment (offset %" PRIu16 ")",
|
||||
other->name->c_str(), target->org, other->alignMask + 1,
|
||||
other->name.c_str(), target->org, other->alignMask + 1,
|
||||
other->alignOfs);
|
||||
} else if (target->isAlignFixed
|
||||
&& (other->alignMask & target->alignOfs)
|
||||
!= (target->alignMask & other->alignOfs)) {
|
||||
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
PRIu16 ") and %d-byte alignment (offset %" PRIu16 ")",
|
||||
other->name->c_str(), target->alignMask + 1, target->alignOfs,
|
||||
other->name.c_str(), target->alignMask + 1, target->alignOfs,
|
||||
other->alignMask + 1, other->alignOfs);
|
||||
} else if (!target->isAlignFixed || (other->alignMask > target->alignMask)) {
|
||||
target->isAlignFixed = true;
|
||||
@@ -67,13 +67,13 @@ static void checkFragmentCompat(struct Section *target, struct Section *other)
|
||||
if (target->isAddressFixed) {
|
||||
if (target->org != org)
|
||||
errx("Section \"%s\" is defined with conflicting addresses $%04"
|
||||
PRIx16 " and $%04" PRIx16, other->name->c_str(), target->org,
|
||||
PRIx16 " and $%04" PRIx16, other->name.c_str(), target->org,
|
||||
other->org);
|
||||
|
||||
} else if (target->isAlignFixed) {
|
||||
if ((org - target->alignOfs) & target->alignMask)
|
||||
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
PRIu16 ") and address $%04" PRIx16, other->name->c_str(),
|
||||
PRIu16 ") and address $%04" PRIx16, other->name.c_str(),
|
||||
target->alignMask + 1, target->alignOfs, other->org);
|
||||
}
|
||||
target->isAddressFixed = true;
|
||||
@@ -89,14 +89,14 @@ static void checkFragmentCompat(struct Section *target, struct Section *other)
|
||||
if ((target->org - ofs) & other->alignMask)
|
||||
errx("Section \"%s\" is defined with conflicting address $%04"
|
||||
PRIx16 " and %d-byte alignment (offset %" PRIu16 ")",
|
||||
other->name->c_str(), target->org, other->alignMask + 1,
|
||||
other->name.c_str(), target->org, other->alignMask + 1,
|
||||
other->alignOfs);
|
||||
|
||||
} else if (target->isAlignFixed
|
||||
&& (other->alignMask & target->alignOfs) != (target->alignMask & ofs)) {
|
||||
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
PRIu16 ") and %d-byte alignment (offset %" PRIu16 ")",
|
||||
other->name->c_str(), target->alignMask + 1, target->alignOfs,
|
||||
other->name.c_str(), target->alignMask + 1, target->alignOfs,
|
||||
other->alignMask + 1, other->alignOfs);
|
||||
|
||||
} else if (!target->isAlignFixed || (other->alignMask > target->alignMask)) {
|
||||
@@ -113,7 +113,7 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
||||
|
||||
if (target->type != other->type)
|
||||
errx("Section \"%s\" is defined with conflicting types %s and %s",
|
||||
other->name->c_str(), sectionTypeInfo[target->type].name.c_str(),
|
||||
other->name.c_str(), sectionTypeInfo[target->type].name.c_str(),
|
||||
sectionTypeInfo[other->type].name.c_str());
|
||||
|
||||
if (other->isBankFixed) {
|
||||
@@ -122,7 +122,7 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
||||
target->bank = other->bank;
|
||||
} else if (target->bank != other->bank) {
|
||||
errx("Section \"%s\" is defined with conflicting banks %" PRIu32 " and %"
|
||||
PRIu32, other->name->c_str(), target->bank, other->bank);
|
||||
PRIu32, other->name.c_str(), target->bank, other->bank);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,20 +171,20 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
||||
void sect_AddSection(struct Section *section)
|
||||
{
|
||||
// Check if the section already exists
|
||||
if (struct Section *other = sect_GetSection(*section->name); other) {
|
||||
if (struct Section *other = sect_GetSection(section->name); other) {
|
||||
if (section->modifier != other->modifier)
|
||||
errx("Section \"%s\" defined as %s and %s", section->name->c_str(),
|
||||
errx("Section \"%s\" defined as %s and %s", section->name.c_str(),
|
||||
sectionModNames[section->modifier], sectionModNames[other->modifier]);
|
||||
else if (section->modifier == SECTION_NORMAL)
|
||||
errx("Section name \"%s\" is already in use", section->name->c_str());
|
||||
errx("Section name \"%s\" is already in use", section->name.c_str());
|
||||
else
|
||||
mergeSections(other, section, section->modifier);
|
||||
} else if (section->modifier == SECTION_UNION && sect_HasData(section->type)) {
|
||||
errx("Section \"%s\" is of type %s, which cannot be unionized",
|
||||
section->name->c_str(), sectionTypeInfo[section->type].name.c_str());
|
||||
section->name.c_str(), sectionTypeInfo[section->type].name.c_str());
|
||||
} else {
|
||||
// If not, add it
|
||||
sections[*section->name] = section;
|
||||
sections[section->name] = section;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,27 +203,27 @@ static void doSanityChecks(struct Section *section)
|
||||
{
|
||||
// Sanity check the section's type
|
||||
if (section->type < 0 || section->type >= SECTTYPE_INVALID) {
|
||||
error(NULL, 0, "Section \"%s\" has an invalid type", section->name->c_str());
|
||||
error(NULL, 0, "Section \"%s\" has an invalid type", section->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is32kMode && section->type == SECTTYPE_ROMX) {
|
||||
if (section->isBankFixed && section->bank != 1)
|
||||
error(NULL, 0, "%s: ROMX sections must be in bank 1 (if any) with option -t",
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
else
|
||||
section->type = SECTTYPE_ROM0;
|
||||
}
|
||||
if (isWRA0Mode && section->type == SECTTYPE_WRAMX) {
|
||||
if (section->isBankFixed && section->bank != 1)
|
||||
error(NULL, 0, "%s: WRAMX sections must be in bank 1 with options -w or -d",
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
else
|
||||
section->type = SECTTYPE_WRAM0;
|
||||
}
|
||||
if (isDmgMode && section->type == SECTTYPE_VRAM && section->bank == 1)
|
||||
error(NULL, 0, "%s: VRAM bank 1 can't be used with option -d",
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
|
||||
// Check if alignment is reasonable, this is important to avoid UB
|
||||
// An alignment of zero is equivalent to no alignment, basically
|
||||
@@ -233,7 +233,7 @@ static void doSanityChecks(struct Section *section)
|
||||
// Too large an alignment may not be satisfiable
|
||||
if (section->isAlignFixed && (section->alignMask & sectionTypeInfo[section->type].startAddr))
|
||||
error(NULL, 0, "%s: %s sections cannot be aligned to $%04x bytes",
|
||||
section->name->c_str(), sectionTypeInfo[section->type].name.c_str(),
|
||||
section->name.c_str(), sectionTypeInfo[section->type].name.c_str(),
|
||||
section->alignMask + 1);
|
||||
|
||||
uint32_t minbank = sectionTypeInfo[section->type].firstBank, maxbank = sectionTypeInfo[section->type].lastBank;
|
||||
@@ -242,13 +242,13 @@ static void doSanityChecks(struct Section *section)
|
||||
error(NULL, 0, minbank == maxbank
|
||||
? "Cannot place section \"%s\" in bank %" PRIu32 ", it must be %" PRIu32
|
||||
: "Cannot place section \"%s\" in bank %" PRIu32 ", it must be between %" PRIu32 " and %" PRIu32,
|
||||
section->name->c_str(), section->bank, minbank, maxbank);
|
||||
section->name.c_str(), section->bank, minbank, maxbank);
|
||||
|
||||
// Check if section has a chance to be placed
|
||||
if (section->size > sectionTypeInfo[section->type].size)
|
||||
error(NULL, 0, "Section \"%s\" is bigger than the max size for that type: $%"
|
||||
PRIx16 " > $%" PRIx16,
|
||||
section->name->c_str(), section->size, sectionTypeInfo[section->type].size);
|
||||
section->name.c_str(), section->size, sectionTypeInfo[section->type].size);
|
||||
|
||||
// Translate loose constraints to strong ones when they're equivalent
|
||||
|
||||
@@ -262,7 +262,7 @@ static void doSanityChecks(struct Section *section)
|
||||
if (section->isAlignFixed) {
|
||||
if ((section->org & section->alignMask) != section->alignOfs)
|
||||
error(NULL, 0, "Section \"%s\"'s fixed address doesn't match its alignment",
|
||||
section->name->c_str());
|
||||
section->name.c_str());
|
||||
section->isAlignFixed = false;
|
||||
}
|
||||
|
||||
@@ -270,12 +270,12 @@ static void doSanityChecks(struct Section *section)
|
||||
if (section->org < sectionTypeInfo[section->type].startAddr
|
||||
|| section->org > endaddr(section->type))
|
||||
error(NULL, 0, "Section \"%s\"'s fixed address $%04" PRIx16 " is outside of range [$%04"
|
||||
PRIx16 "; $%04" PRIx16 "]", section->name->c_str(), section->org,
|
||||
PRIx16 "; $%04" PRIx16 "]", section->name.c_str(), section->org,
|
||||
sectionTypeInfo[section->type].startAddr, endaddr(section->type));
|
||||
|
||||
if (section->org + section->size > endaddr(section->type) + 1)
|
||||
error(NULL, 0, "Section \"%s\"'s end address $%04x is greater than last address $%04x",
|
||||
section->name->c_str(), section->org + section->size,
|
||||
section->name.c_str(), section->org + section->size,
|
||||
endaddr(section->type) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user