mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 18:52:07 +00:00
Replace NULL with nullptr (#1321)
This commit is contained in:
@@ -51,7 +51,7 @@ static void initFreeSpace(void)
|
||||
type, bank);
|
||||
memory[type][bank].next->address = sectionTypeInfo[type].startAddr;
|
||||
memory[type][bank].next->size = sectionTypeInfo[type].size;
|
||||
memory[type][bank].next->next = NULL;
|
||||
memory[type][bank].next->next = nullptr;
|
||||
memory[type][bank].next->prev = &memory[type][bank];
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ static void assignSection(Section *section, MemoryLocation const *location)
|
||||
|
||||
// Propagate the assigned location to all UNIONs/FRAGMENTs
|
||||
// so `jr` patches in them will have the correct offset
|
||||
for (Section *next = section->nextu; next != NULL; next = next->nextu) {
|
||||
for (Section *next = section->nextu; next != nullptr; next = next->nextu) {
|
||||
next->org = section->org;
|
||||
next->bank = section->bank;
|
||||
}
|
||||
@@ -94,22 +94,20 @@ static bool isLocationSuitable(Section const *section, FreeSpace const *freeSpac
|
||||
if (section->isAddressFixed && section->org != location->address)
|
||||
return false;
|
||||
|
||||
if (section->isAlignFixed
|
||||
&& ((location->address - section->alignOfs) & section->alignMask))
|
||||
if (section->isAlignFixed && ((location->address - section->alignOfs) & section->alignMask))
|
||||
return false;
|
||||
|
||||
if (location->address < freeSpace->address)
|
||||
return false;
|
||||
return location->address + section->size
|
||||
<= freeSpace->address + freeSpace->size;
|
||||
|
||||
return location->address + section->size <= freeSpace->address + freeSpace->size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds a suitable location to place a section at.
|
||||
* @param section The section to be placed
|
||||
* @param location A pointer to a memory location that will be filled
|
||||
* @return A pointer to the free space encompassing the location, or NULL if
|
||||
* none was found
|
||||
* @return A pointer to the free space encompassing the location, or `nullptr` if none was found
|
||||
*/
|
||||
static FreeSpace *getPlacement(Section const *section, MemoryLocation *location)
|
||||
{
|
||||
@@ -159,7 +157,7 @@ static FreeSpace *getPlacement(Section const *section, MemoryLocation *location)
|
||||
location->address = section->org;
|
||||
else
|
||||
// Try again in next bank
|
||||
space = NULL;
|
||||
space = nullptr;
|
||||
} else if (section->isAlignFixed) {
|
||||
// Move to next aligned location
|
||||
// Move back to alignment boundary
|
||||
@@ -187,32 +185,32 @@ static FreeSpace *getPlacement(Section const *section, MemoryLocation *location)
|
||||
// Try scrambled banks in descending order until no bank in the scrambled range is available.
|
||||
// Otherwise, try in ascending order.
|
||||
if (section->isBankFixed) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
} else if (scrambleROMX && section->type == SECTTYPE_ROMX && location->bank <= scrambleROMX) {
|
||||
if (location->bank > sectionTypeInfo[section->type].firstBank)
|
||||
location->bank--;
|
||||
else if (scrambleROMX < sectionTypeInfo[section->type].lastBank)
|
||||
location->bank = scrambleROMX + 1;
|
||||
else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
} else if (scrambleWRAMX && section->type == SECTTYPE_WRAMX && location->bank <= scrambleWRAMX) {
|
||||
if (location->bank > sectionTypeInfo[section->type].firstBank)
|
||||
location->bank--;
|
||||
else if (scrambleWRAMX < sectionTypeInfo[section->type].lastBank)
|
||||
location->bank = scrambleWRAMX + 1;
|
||||
else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
} else if (scrambleSRAM && section->type == SECTTYPE_SRAM && location->bank <= scrambleSRAM) {
|
||||
if (location->bank > sectionTypeInfo[section->type].firstBank)
|
||||
location->bank--;
|
||||
else if (scrambleSRAM < sectionTypeInfo[section->type].lastBank)
|
||||
location->bank = scrambleSRAM + 1;
|
||||
else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
} else if (location->bank < sectionTypeInfo[section->type].lastBank) {
|
||||
location->bank++;
|
||||
} else {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
#undef BANK_INDEX
|
||||
}
|
||||
|
||||
@@ -173,22 +173,22 @@ static const char *optstring = "dl:m:Mn:O:o:p:S:s:tVvWwx";
|
||||
* over short opt matching
|
||||
*/
|
||||
static option const longopts[] = {
|
||||
{ "dmg", no_argument, NULL, 'd' },
|
||||
{ "linkerscript", required_argument, NULL, 'l' },
|
||||
{ "map", required_argument, NULL, 'm' },
|
||||
{ "no-sym-in-map", no_argument, NULL, 'M' },
|
||||
{ "sym", required_argument, NULL, 'n' },
|
||||
{ "overlay", required_argument, NULL, 'O' },
|
||||
{ "output", required_argument, NULL, 'o' },
|
||||
{ "pad", required_argument, NULL, 'p' },
|
||||
{ "scramble", required_argument, NULL, 'S' },
|
||||
{ "smart", required_argument, NULL, 's' },
|
||||
{ "tiny", no_argument, NULL, 't' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "wramx", no_argument, NULL, 'w' },
|
||||
{ "nopad", no_argument, NULL, 'x' },
|
||||
{ NULL, no_argument, NULL, 0 }
|
||||
{ "dmg", no_argument, nullptr, 'd' },
|
||||
{ "linkerscript", required_argument, nullptr, 'l' },
|
||||
{ "map", required_argument, nullptr, 'm' },
|
||||
{ "no-sym-in-map", no_argument, nullptr, 'M' },
|
||||
{ "sym", required_argument, nullptr, 'n' },
|
||||
{ "overlay", required_argument, nullptr, 'O' },
|
||||
{ "output", required_argument, nullptr, 'o' },
|
||||
{ "pad", required_argument, nullptr, 'p' },
|
||||
{ "scramble", required_argument, nullptr, 'S' },
|
||||
{ "smart", required_argument, nullptr, 's' },
|
||||
{ "tiny", no_argument, nullptr, 't' },
|
||||
{ "version", no_argument, nullptr, 'V' },
|
||||
{ "verbose", no_argument, nullptr, 'v' },
|
||||
{ "wramx", no_argument, nullptr, 'w' },
|
||||
{ "nopad", no_argument, nullptr, 'x' },
|
||||
{ nullptr, no_argument, nullptr, 0 }
|
||||
};
|
||||
|
||||
static void printUsage(void)
|
||||
@@ -345,7 +345,7 @@ next:
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parse options
|
||||
for (int ch; (ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1;) {
|
||||
for (int ch; (ch = musl_getopt_long_only(argc, argv, optstring, longopts, nullptr)) != -1;) {
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
isDmgMode = true;
|
||||
@@ -399,7 +399,7 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
case 's':
|
||||
// TODO: implement "smart linking" with `-s`
|
||||
warning(NULL, 0, "Nobody has any idea what `-s` does");
|
||||
warning(nullptr, 0, "Nobody has any idea what `-s` does");
|
||||
break;
|
||||
case 't':
|
||||
is32kMode = true;
|
||||
|
||||
@@ -136,7 +136,7 @@ static void readFileStackNode(FILE *file, std::vector<FileStackNode> &fileNodes,
|
||||
|
||||
tryReadlong(parentID, file,
|
||||
"%s: Cannot read node #%" PRIu32 "'s parent ID: %s", fileName, i);
|
||||
node.parent = parentID != (uint32_t)-1 ? &fileNodes[parentID] : NULL;
|
||||
node.parent = parentID != (uint32_t)-1 ? &fileNodes[parentID] : nullptr;
|
||||
tryReadlong(node.lineNo, file,
|
||||
"%s: Cannot read node #%" PRIu32 "'s line number: %s", fileName, i);
|
||||
tryGetc(enum FileStackNodeType, node.type, file,
|
||||
@@ -159,7 +159,7 @@ static void readFileStackNode(FILE *file, std::vector<FileStackNode> &fileNodes,
|
||||
"%s: Cannot read node #%" PRIu32 "'s iter #%" PRIu32 ": %s",
|
||||
fileName, i, k);
|
||||
if (!node.parent)
|
||||
fatal(NULL, 0, "%s is not a valid object file: root node (#%"
|
||||
fatal(nullptr, 0, "%s is not a valid object file: root node (#%"
|
||||
PRIu32 ") may not be REPT", fileName, i);
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ static void readPatch(FILE *file, Patch *patch, char const *fileName, std::strin
|
||||
static void linkPatchToPCSect(Patch *patch, std::vector<Section *> const &fileSections)
|
||||
{
|
||||
patch->pcSection = patch->pcSectionID != (uint32_t)-1 ? fileSections[patch->pcSectionID]
|
||||
: NULL;
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -281,7 +281,7 @@ static void readSection(FILE *file, Section *section, char const *fileName,
|
||||
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(nullptr, 0, "\"%s\"'s org is too large (%" PRId32 ")", section->name.c_str(), tmp);
|
||||
tmp = UINT16_MAX;
|
||||
}
|
||||
section->org = tmp;
|
||||
@@ -297,7 +297,7 @@ static void readSection(FILE *file, Section *section, char const *fileName,
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s alignment offset: %s", fileName,
|
||||
section->name.c_str());
|
||||
if (tmp > UINT16_MAX) {
|
||||
error(NULL, 0, "\"%s\"'s alignment offset is too large (%" PRId32 ")",
|
||||
error(nullptr, 0, "\"%s\"'s alignment offset is too large (%" PRId32 ")",
|
||||
section->name.c_str(), tmp);
|
||||
tmp = UINT16_MAX;
|
||||
}
|
||||
@@ -391,7 +391,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
ungetc(c, file); // Guaranteed to work
|
||||
switch (c) {
|
||||
case EOF:
|
||||
fatal(NULL, 0, "File \"%s\" is empty!", fileName);
|
||||
fatal(nullptr, 0, "File \"%s\" is empty!", fileName);
|
||||
|
||||
case 'R':
|
||||
break;
|
||||
@@ -400,7 +400,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
// Since SDCC does not provide line info, everything will be reported as coming from the
|
||||
// object file. It's better than nothing.
|
||||
nodes[fileID].push_back({
|
||||
.parent = NULL,
|
||||
.parent = nullptr,
|
||||
.lineNo = 0,
|
||||
.type = NODE_FILE,
|
||||
.data = fileName
|
||||
@@ -463,7 +463,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
}
|
||||
|
||||
// This file's sections, stored in a table to link symbols to them
|
||||
std::vector<Section *> fileSections(nbSections, NULL);
|
||||
std::vector<Section *> fileSections(nbSections, nullptr);
|
||||
|
||||
verbosePrint("Reading %" PRIu32 " sections...\n", nbSections);
|
||||
for (uint32_t i = 0; i < nbSections; i++) {
|
||||
@@ -472,7 +472,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
if (!fileSections[i])
|
||||
err("%s: Failed to create new section", fileName);
|
||||
|
||||
fileSections[i]->nextu = NULL;
|
||||
fileSections[i]->nextu = nullptr;
|
||||
readSection(file, fileSections[i], fileName, nodes[fileID]);
|
||||
fileSections[i]->fileSymbols = &fileSymbols;
|
||||
fileSections[i]->symbols.reserve(nbSymPerSect[i]);
|
||||
@@ -493,7 +493,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
int32_t sectionID = fileSymbols[i].sectionID;
|
||||
|
||||
if (sectionID == -1) {
|
||||
fileSymbols[i].section = NULL;
|
||||
fileSymbols[i].section = nullptr;
|
||||
} else {
|
||||
Section *section = fileSections[sectionID];
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ Section const *out_OverlappingSection(Section const *section)
|
||||
if (ptr->org < section->org + section->size && section->org < ptr->org + ptr->size)
|
||||
return ptr;
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -222,7 +222,7 @@ static void writeROM(void)
|
||||
coverOverlayBanks(nbOverlayBanks);
|
||||
|
||||
if (outputFile) {
|
||||
writeBank(!sections[SECTTYPE_ROM0].empty() ? §ions[SECTTYPE_ROM0][0].sections : NULL,
|
||||
writeBank(!sections[SECTTYPE_ROM0].empty() ? §ions[SECTTYPE_ROM0][0].sections : nullptr,
|
||||
sectionTypeInfo[SECTTYPE_ROM0].startAddr, sectionTypeInfo[SECTTYPE_ROM0].size);
|
||||
|
||||
for (uint32_t i = 0 ; i < sections[SECTTYPE_ROMX].size(); i++)
|
||||
|
||||
@@ -106,7 +106,7 @@ optional: %empty { $$ = false; }
|
||||
%%
|
||||
|
||||
#define scriptError(context, fmt, ...) \
|
||||
::error(NULL, 0, "%s(%" PRIu32 "): " fmt, \
|
||||
::error(nullptr, 0, "%s(%" PRIu32 "): " fmt, \
|
||||
context.path.c_str(), context.lineNo __VA_OPT__(,) __VA_ARGS__)
|
||||
|
||||
// Lexer.
|
||||
@@ -577,7 +577,7 @@ void script_ProcessScript(char const *path) {
|
||||
auto &newContext = lexerStack.emplace_back(std::string(path));
|
||||
|
||||
if (!newContext.file.open(newContext.path, std::ios_base::in)) {
|
||||
error(NULL, 0, "Failed to open linker script \"%s\"", newContext.path.c_str());
|
||||
error(nullptr, 0, "Failed to open linker script \"%s\"", newContext.path.c_str());
|
||||
lexerStack.clear();
|
||||
} else {
|
||||
yy::parser linkerScriptParser;
|
||||
|
||||
@@ -143,12 +143,12 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
fatal(where, lineNo, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define expectEol(...) do { \
|
||||
token = strtok(NULL, delim); \
|
||||
token = strtok(nullptr, delim); \
|
||||
if (token) \
|
||||
fatal(where, lineNo, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define expectToken(expected, lineType) do { \
|
||||
getToken(NULL, "'%c' line is too short", (lineType)); \
|
||||
getToken(nullptr, "'%c' line is too short", (lineType)); \
|
||||
if (strcasecmp(token, (expected)) != 0) \
|
||||
fatal(where, lineNo, "Malformed '%c' line: expected \"%s\", got \"%s\"", \
|
||||
(lineType), (expected), token); \
|
||||
@@ -204,7 +204,7 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
|
||||
expectToken("areas", 'H');
|
||||
|
||||
getToken(NULL, "'H' line is too short");
|
||||
getToken(nullptr, "'H' line is too short");
|
||||
uint32_t expectedNbSymbols = parseNumber(where, lineNo, token, numberType);
|
||||
|
||||
expectToken("global", 'H');
|
||||
@@ -255,7 +255,7 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
|
||||
expectToken("size", 'A');
|
||||
|
||||
getToken(NULL, "'A' line is too short");
|
||||
getToken(nullptr, "'A' line is too short");
|
||||
|
||||
uint32_t tmp = parseNumber(where, lineNo, token, numberType);
|
||||
|
||||
@@ -266,7 +266,7 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
|
||||
expectToken("flags", 'A');
|
||||
|
||||
getToken(NULL, "'A' line is too short");
|
||||
getToken(nullptr, "'A' line is too short");
|
||||
tmp = parseNumber(where, lineNo, token, numberType);
|
||||
if (tmp & (1 << AREA_PAGING))
|
||||
fatal(where, lineNo, "Internal error: paging is not supported");
|
||||
@@ -283,7 +283,7 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
|
||||
expectToken("addr", 'A');
|
||||
|
||||
getToken(NULL, "'A' line is too short");
|
||||
getToken(nullptr, "'A' line is too short");
|
||||
tmp = parseNumber(where, lineNo, token, numberType);
|
||||
curSection->org = tmp; // Truncation keeps the address portion only
|
||||
curSection->bank = tmp >> 16;
|
||||
@@ -319,7 +319,7 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
}
|
||||
curSection->isAlignFixed = false; // No such concept!
|
||||
curSection->fileSymbols = &fileSymbols; // IDs are instead per-section
|
||||
curSection->nextu = NULL;
|
||||
curSection->nextu = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -335,12 +335,12 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
symbol.lineNo = lineNo;
|
||||
|
||||
// No need to set the `sectionID`, since we can directly set the pointer
|
||||
symbol.section = !fileSections.empty() ? fileSections.back().section : NULL;
|
||||
symbol.section = !fileSections.empty() ? fileSections.back().section : nullptr;
|
||||
|
||||
getToken(line.data(), "'S' line is too short");
|
||||
symbol.name = token;
|
||||
|
||||
getToken(NULL, "'S' line is too short");
|
||||
getToken(nullptr, "'S' line is too short");
|
||||
// It might be an `offset`, but both types are the same so type punning is fine
|
||||
symbol.value = parseNumber(where, lineNo, &token[3], numberType);
|
||||
if (symbol.section && symbol.section->isAddressFixed) {
|
||||
@@ -394,7 +394,7 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
warning(where, lineNo, "Previous 'T' line had no 'R' line (ignored)");
|
||||
|
||||
data.clear();
|
||||
for (token = strtok(line.data(), delim); token; token = strtok(NULL, delim))
|
||||
for (token = strtok(line.data(), delim); token; token = strtok(nullptr, delim))
|
||||
data.push_back(parseByte(where, lineNo, token, numberType));
|
||||
|
||||
if (data.size() < ADDR_SIZE)
|
||||
@@ -411,12 +411,12 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
|
||||
// First two bytes are ignored
|
||||
getToken(line.data(), "'R' line is too short");
|
||||
getToken(NULL, "'R' line is too short");
|
||||
getToken(nullptr, "'R' line is too short");
|
||||
uint16_t areaIdx;
|
||||
|
||||
getToken(NULL, "'R' line is too short");
|
||||
getToken(nullptr, "'R' line is too short");
|
||||
areaIdx = parseByte(where, lineNo, token, numberType);
|
||||
getToken(NULL, "'R' line is too short");
|
||||
getToken(nullptr, "'R' line is too short");
|
||||
areaIdx |= (uint16_t)parseByte(where, lineNo, token, numberType) << 8;
|
||||
if (areaIdx >= fileSections.size())
|
||||
fatal(where, lineNo, "'R' line references area #%" PRIu16 ", but there are only %zu (so far)",
|
||||
@@ -458,15 +458,15 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
// This all can be "translated" to RGBDS parlance by generating the
|
||||
// appropriate RPN expression (depending on flags), plus an addition for the
|
||||
// bytes being patched over.
|
||||
while ((token = strtok(NULL, delim)) != NULL) {
|
||||
while ((token = strtok(nullptr, delim)) != nullptr) {
|
||||
uint16_t flags = parseByte(where, lineNo, token, numberType);
|
||||
|
||||
if ((flags & 0xF0) == 0xF0) {
|
||||
getToken(NULL, "Incomplete relocation");
|
||||
getToken(nullptr, "Incomplete relocation");
|
||||
flags = (flags & 0x0F) | (uint16_t)parseByte(where, lineNo, token, numberType) << 4;
|
||||
}
|
||||
|
||||
getToken(NULL, "Incomplete relocation");
|
||||
getToken(nullptr, "Incomplete relocation");
|
||||
uint8_t offset = parseByte(where, lineNo, token, numberType);
|
||||
|
||||
if (offset < ADDR_SIZE)
|
||||
@@ -476,10 +476,10 @@ void sdobj_ReadFile(FileStackNode const *where, FILE *file, std::vector<Symbol>
|
||||
fatal(where, lineNo, "Relocation index is out of bounds (%" PRIu16 " >= %zu)",
|
||||
offset, data.size());
|
||||
|
||||
getToken(NULL, "Incomplete relocation");
|
||||
getToken(nullptr, "Incomplete relocation");
|
||||
uint16_t idx = parseByte(where, lineNo, token, numberType);
|
||||
|
||||
getToken(NULL, "Incomplete relocation");
|
||||
getToken(nullptr, "Incomplete relocation");
|
||||
idx |= (uint16_t)parseByte(where, lineNo, token, numberType);
|
||||
|
||||
// Loudly fail on unknown flags
|
||||
|
||||
@@ -182,33 +182,33 @@ void sect_AddSection(Section *section)
|
||||
Section *sect_GetSection(std::string const &name)
|
||||
{
|
||||
auto search = sections.find(name);
|
||||
return search != sections.end() ? search->second : NULL;
|
||||
return search != sections.end() ? search->second : nullptr;
|
||||
}
|
||||
|
||||
static void doSanityChecks(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(nullptr, 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",
|
||||
error(nullptr, 0, "%s: ROMX sections must be in bank 1 (if any) with option -t",
|
||||
section->name.c_str());
|
||||
else
|
||||
section->type = SECTTYPE_ROM0;
|
||||
}
|
||||
if (isWRAM0Mode && 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",
|
||||
error(nullptr, 0, "%s: WRAMX sections must be in bank 1 with options -w or -d",
|
||||
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",
|
||||
error(nullptr, 0, "%s: VRAM bank 1 can't be used with option -d",
|
||||
section->name.c_str());
|
||||
|
||||
// Check if alignment is reasonable, this is important to avoid UB
|
||||
@@ -218,21 +218,21 @@ static void doSanityChecks(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",
|
||||
error(nullptr, 0, "%s: %s sections cannot be aligned to $%04x bytes",
|
||||
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;
|
||||
|
||||
if (section->isBankFixed && section->bank < minbank && section->bank > maxbank)
|
||||
error(NULL, 0, minbank == maxbank
|
||||
error(nullptr, 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);
|
||||
|
||||
// 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: $%"
|
||||
error(nullptr, 0, "Section \"%s\" is bigger than the max size for that type: $%"
|
||||
PRIx16 " > $%" PRIx16,
|
||||
section->name.c_str(), section->size, sectionTypeInfo[section->type].size);
|
||||
|
||||
@@ -247,7 +247,7 @@ static void doSanityChecks(Section *section)
|
||||
// It doesn't make sense to have both org and alignment set
|
||||
if (section->isAlignFixed) {
|
||||
if ((section->org & section->alignMask) != section->alignOfs)
|
||||
error(NULL, 0, "Section \"%s\"'s fixed address doesn't match its alignment",
|
||||
error(nullptr, 0, "Section \"%s\"'s fixed address doesn't match its alignment",
|
||||
section->name.c_str());
|
||||
section->isAlignFixed = false;
|
||||
}
|
||||
@@ -255,12 +255,12 @@ static void doSanityChecks(Section *section)
|
||||
// Ensure the target address is valid
|
||||
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"
|
||||
error(nullptr, 0, "Section \"%s\"'s fixed address $%04" PRIx16 " is outside of range [$%04"
|
||||
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",
|
||||
error(nullptr, 0, "Section \"%s\"'s end address $%04x is greater than last address $%04x",
|
||||
section->name.c_str(), section->org + section->size,
|
||||
endaddr(section->type) + 1);
|
||||
}
|
||||
|
||||
@@ -32,5 +32,5 @@ void sym_AddSymbol(Symbol *symbol)
|
||||
Symbol *sym_GetSymbol(std::string const &name)
|
||||
{
|
||||
auto search = symbols.find(name);
|
||||
return search != symbols.end() ? search->second : NULL;
|
||||
return search != symbols.end() ? search->second : nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user