diff --git a/src/asm/output.cpp b/src/asm/output.cpp index 2bff7a76..daae116e 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -37,7 +37,7 @@ static std::deque assertions; static std::deque> fileStackNodes; -static void putlong(uint32_t n, FILE *file) { +static void putLong(uint32_t n, FILE *file) { uint8_t bytes[] = { (uint8_t)n, (uint8_t)(n >> 8), @@ -47,7 +47,7 @@ static void putlong(uint32_t n, FILE *file) { fwrite(bytes, 1, sizeof(bytes), file); } -static void putstring(std::string const &s, FILE *file) { +static void putString(std::string const &s, FILE *file) { fputs(s.c_str(), file); putc('\0', file); } @@ -71,54 +71,55 @@ static uint32_t getSectIDIfAny(Section *sect) { fatalerror("Unknown section '%s'\n", sect->name.c_str()); } -static void writepatch(Patch const &patch, FILE *file) { +static void writePatch(Patch const &patch, FILE *file) { assume(patch.src->ID != (uint32_t)-1); - putlong(patch.src->ID, file); - putlong(patch.lineNo, file); - putlong(patch.offset, file); - putlong(getSectIDIfAny(patch.pcSection), file); - putlong(patch.pcOffset, file); + + putLong(patch.src->ID, file); + putLong(patch.lineNo, file); + putLong(patch.offset, file); + putLong(getSectIDIfAny(patch.pcSection), file); + putLong(patch.pcOffset, file); putc(patch.type, file); - putlong(patch.rpn.size(), file); + putLong(patch.rpn.size(), file); fwrite(patch.rpn.data(), 1, patch.rpn.size(), file); } -static void writesection(Section const §, FILE *file) { - putstring(sect.name, file); +static void writeSection(Section const §, FILE *file) { + putString(sect.name, file); - putlong(sect.size, file); + putLong(sect.size, file); bool isUnion = sect.modifier == SECTION_UNION; bool isFragment = sect.modifier == SECTION_FRAGMENT; putc(sect.type | isUnion << 7 | isFragment << 6, file); - putlong(sect.org, file); - putlong(sect.bank, file); + putLong(sect.org, file); + putLong(sect.bank, file); putc(sect.align, file); - putlong(sect.alignOfs, file); + putLong(sect.alignOfs, file); if (sect_HasData(sect.type)) { fwrite(sect.data.data(), 1, sect.size, file); - putlong(sect.patches.size(), file); + putLong(sect.patches.size(), file); for (Patch const &patch : sect.patches) - writepatch(patch, file); + writePatch(patch, file); } } -static void writesymbol(Symbol const &sym, FILE *file) { - putstring(sym.name, file); +static void writeSymbol(Symbol const &sym, FILE *file) { + putString(sym.name, file); if (!sym.isDefined()) { putc(SYMTYPE_IMPORT, file); } else { assume(sym.src->ID != (uint32_t)-1); putc(sym.isExported ? SYMTYPE_EXPORT : SYMTYPE_LOCAL, file); - putlong(sym.src->ID, file); - putlong(sym.fileLine, file); - putlong(getSectIDIfAny(sym.getSection()), file); - putlong(sym.getOutputValue(), file); + putLong(sym.src->ID, file); + putLong(sym.fileLine, file); + putLong(getSectIDIfAny(sym.getSection()), file); + putLong(sym.getOutputValue(), file); } } @@ -131,7 +132,7 @@ static void registerUnregisteredSymbol(Symbol &sym) { } } -static void writerpn(std::vector &rpnexpr, std::vector const &rpn) { +static void writeRpn(std::vector &rpnexpr, std::vector const &rpn) { std::string symName; size_t rpnptr = 0; @@ -229,7 +230,7 @@ static void writerpn(std::vector &rpnexpr, std::vector const & } } -static void initpatch(Patch &patch, uint32_t type, Expression const &expr, uint32_t ofs) { +static void initPatch(Patch &patch, uint32_t type, Expression const &expr, uint32_t ofs) { patch.type = type; patch.src = fstk_GetFileStack(); // All patches are assumed to eventually be written, so the file stack node is registered @@ -250,7 +251,7 @@ static void initpatch(Patch &patch, uint32_t type, Expression const &expr, uint3 patch.rpn[4] = val >> 24; } else { patch.rpn.resize(expr.rpnPatchSize); - writerpn(patch.rpn, expr.rpn); + writeRpn(patch.rpn, expr.rpn); } } @@ -258,7 +259,7 @@ void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32 // Add the patch to the list Patch &patch = currentSection->patches.emplace_front(); - initpatch(patch, type, expr, ofs); + initPatch(patch, type, expr, ofs); // If the patch had a quantity of bytes output before it, // PC is not at the patch's location, but at the location @@ -271,28 +272,28 @@ void out_CreateAssert( ) { Assertion &assertion = assertions.emplace_front(); - initpatch(assertion.patch, type, expr, ofs); + initPatch(assertion.patch, type, expr, ofs); assertion.message = message; } -static void writeassert(Assertion &assert, FILE *file) { - writepatch(assert.patch, file); - putstring(assert.message, file); +static void writeAssert(Assertion &assert, FILE *file) { + writePatch(assert.patch, file); + putString(assert.message, file); } static void writeFileStackNode(FileStackNode const &node, FILE *file) { - putlong(node.parent ? node.parent->ID : (uint32_t)-1, file); - putlong(node.lineNo, file); + putLong(node.parent ? node.parent->ID : (uint32_t)-1, file); + putLong(node.lineNo, file); putc(node.type, file); if (node.type != NODE_REPT) { - putstring(node.name(), file); + putString(node.name(), file); } else { std::vector const &nodeIters = node.iters(); - putlong(nodeIters.size(), file); + putLong(nodeIters.size(), file); // Iters are stored by decreasing depth, so reverse the order for output for (uint32_t i = nodeIters.size(); i--;) - putlong(nodeIters[i], file); + putLong(nodeIters[i], file); } } @@ -315,12 +316,12 @@ void out_WriteObject() { sym_ForEach(registerUnregisteredSymbol); fprintf(file, RGBDS_OBJECT_VERSION_STRING); - putlong(RGBDS_OBJECT_REV, file); + putLong(RGBDS_OBJECT_REV, file); - putlong(objectSymbols.size(), file); - putlong(sectionList.size(), file); + putLong(objectSymbols.size(), file); + putLong(sectionList.size(), file); - putlong(fileStackNodes.size(), file); + putLong(fileStackNodes.size(), file); for (auto it = fileStackNodes.begin(); it != fileStackNodes.end(); it++) { FileStackNode const &node = **it; @@ -337,15 +338,15 @@ void out_WriteObject() { } for (Symbol const *sym : objectSymbols) - writesymbol(*sym, file); + writeSymbol(*sym, file); for (auto it = sectionList.rbegin(); it != sectionList.rend(); it++) - writesection(*it, file); + writeSection(*it, file); - putlong(assertions.size(), file); + putLong(assertions.size(), file); for (Assertion &assert : assertions) - writeassert(assert, file); + writeAssert(assert, file); } void out_SetFileName(std::string const &name) { diff --git a/src/link/object.cpp b/src/link/object.cpp index 32ceb86d..8bb4ceaf 100644 --- a/src/link/object.cpp +++ b/src/link/object.cpp @@ -31,7 +31,7 @@ static std::vector> nodes; // Helper functions for reading object files // Internal, DO NOT USE. -// For helper wrapper macros defined below, such as `tryReadlong` +// For helper wrapper macros defined below, such as `tryReadLong` #define tryRead(func, type, errval, vartype, var, file, ...) \ do { \ FILE *tmpFile = file; \ @@ -48,7 +48,7 @@ static std::vector> nodes; * @param file The file to read from. This will read 4 bytes from the file. * @return The value read, cast to a int64_t, or -1 on failure. */ -static int64_t readlong(FILE *file) { +static int64_t readLong(FILE *file) { uint32_t value = 0; // Read the little-endian value byte by byte @@ -76,8 +76,8 @@ static int64_t readlong(FILE *file) { * @param ... A format string and related arguments; note that an extra string * argument is provided, the reason for failure */ -#define tryReadlong(var, file, ...) \ - tryRead(readlong, int64_t, INT64_MAX, long, var, file, __VA_ARGS__) +#define tryReadLong(var, file, ...) \ + tryRead(readLong, int64_t, INT64_MAX, long, var, file, __VA_ARGS__) // There is no `readbyte`, just use `fgetc` or `getc`. @@ -99,7 +99,7 @@ static int64_t readlong(FILE *file) { * @param ... A format string and related arguments; note that an extra string * argument is provided, the reason for failure */ -#define tryReadstring(var, file, ...) \ +#define tryReadString(var, file, ...) \ do { \ FILE *tmpFile = file; \ std::string &tmpVal = var; \ @@ -127,9 +127,9 @@ static void readFileStackNode( FileStackNode &node = fileNodes[i]; uint32_t parentID; - tryReadlong(parentID, file, "%s: Cannot read node #%" PRIu32 "'s parent ID: %s", fileName, i); + tryReadLong(parentID, file, "%s: Cannot read node #%" PRIu32 "'s parent ID: %s", fileName, i); node.parent = parentID != (uint32_t)-1 ? &fileNodes[parentID] : nullptr; - tryReadlong( + tryReadLong( node.lineNo, file, "%s: Cannot read node #%" PRIu32 "'s line number: %s", fileName, i ); tryGetc( @@ -144,17 +144,17 @@ static void readFileStackNode( case NODE_FILE: case NODE_MACRO: node.data = ""; - tryReadstring( + tryReadString( node.name(), file, "%s: Cannot read node #%" PRIu32 "'s file name: %s", fileName, i ); break; uint32_t depth; case NODE_REPT: - tryReadlong(depth, file, "%s: Cannot read node #%" PRIu32 "'s rept depth: %s", fileName, i); + tryReadLong(depth, file, "%s: Cannot read node #%" PRIu32 "'s rept depth: %s", fileName, i); node.data = std::vector(depth); for (uint32_t k = 0; k < depth; k++) - tryReadlong( + tryReadLong( node.iters()[k], file, "%s: Cannot read node #%" PRIu32 "'s iter #%" PRIu32 ": %s", @@ -182,7 +182,7 @@ static void readFileStackNode( static void readSymbol( FILE *file, Symbol &symbol, char const *fileName, std::vector const &fileNodes ) { - tryReadstring(symbol.name, file, "%s: Cannot read symbol name: %s", fileName); + tryReadString(symbol.name, file, "%s: Cannot read symbol name: %s", fileName); tryGetc( ExportLevel, symbol.type, @@ -195,11 +195,11 @@ static void readSymbol( if (symbol.type != SYMTYPE_IMPORT) { symbol.objFileName = fileName; uint32_t nodeID; - tryReadlong( + tryReadLong( nodeID, file, "%s: Cannot read \"%s\"'s node ID: %s", fileName, symbol.name.c_str() ); symbol.src = &fileNodes[nodeID]; - tryReadlong( + tryReadLong( symbol.lineNo, file, "%s: Cannot read \"%s\"'s line number: %s", @@ -207,14 +207,14 @@ static void readSymbol( symbol.name.c_str() ); int32_t sectionID, value; - tryReadlong( + tryReadLong( sectionID, file, "%s: Cannot read \"%s\"'s section ID: %s", fileName, symbol.name.c_str() ); - tryReadlong( + tryReadLong( value, file, "%s: Cannot read \"%s\"'s value: %s", fileName, symbol.name.c_str() ); if (sectionID == -1) { @@ -250,7 +250,7 @@ static void readPatch( uint32_t nodeID, rpnSize; PatchType type; - tryReadlong( + tryReadLong( nodeID, file, "%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s node ID: %s", @@ -259,7 +259,7 @@ static void readPatch( i ); patch.src = &fileNodes[nodeID]; - tryReadlong( + tryReadLong( patch.lineNo, file, "%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s line number: %s", @@ -267,7 +267,7 @@ static void readPatch( sectName.c_str(), i ); - tryReadlong( + tryReadLong( patch.offset, file, "%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s offset: %s", @@ -275,7 +275,7 @@ static void readPatch( sectName.c_str(), i ); - tryReadlong( + tryReadLong( patch.pcSectionID, file, "%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s PC offset: %s", @@ -283,7 +283,7 @@ static void readPatch( sectName.c_str(), i ); - tryReadlong( + tryReadLong( patch.pcOffset, file, "%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s PC offset: %s", @@ -301,7 +301,7 @@ static void readPatch( i ); patch.type = type; - tryReadlong( + tryReadLong( rpnSize, file, "%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s RPN size: %s", @@ -345,8 +345,8 @@ static void readSection( int32_t tmp; uint8_t byte; - 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(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()); if (tmp < 0 || tmp > UINT16_MAX) errx("\"%s\"'s section size (%" PRId32 ") is invalid", section.name.c_str(), tmp); section.size = tmp; @@ -365,14 +365,14 @@ static void readSection( 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(nullptr, 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( @@ -387,7 +387,7 @@ static void readSection( byte = 16; section.isAlignFixed = byte != 0; section.alignMask = (1 << byte) - 1; - tryReadlong( + tryReadLong( tmp, file, "%s: Cannot read \"%s\"'s alignment offset: %s", fileName, section.name.c_str() ); if (tmp > UINT16_MAX) { @@ -417,7 +417,7 @@ static void readSection( uint32_t nbPatches; - tryReadlong( + tryReadLong( nbPatches, file, "%s: Cannot read \"%s\"'s number of patches: %s", @@ -470,7 +470,7 @@ static void readAssertion( assertName += std::to_string(i); readPatch(file, assert.patch, fileName, assertName, 0, fileNodes); - tryReadstring(assert.message, file, "%s: Cannot read assertion's message: %s", fileName); + tryReadString(assert.message, file, "%s: Cannot read assertion's message: %s", fileName); } void obj_ReadFile(char const *fileName, unsigned int fileID) { @@ -525,7 +525,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) { uint32_t revNum; - tryReadlong(revNum, file, "%s: Cannot read revision number: %s", fileName); + tryReadLong(revNum, file, "%s: Cannot read revision number: %s", fileName); if (revNum != RGBDS_OBJECT_REV) errx( "%s: Unsupported object file for rgblink %s; try rebuilding \"%s\"%s" @@ -542,12 +542,12 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) { uint32_t nbSymbols; uint32_t nbSections; - tryReadlong(nbSymbols, file, "%s: Cannot read number of symbols: %s", fileName); - tryReadlong(nbSections, file, "%s: Cannot read number of sections: %s", fileName); + tryReadLong(nbSymbols, file, "%s: Cannot read number of symbols: %s", fileName); + tryReadLong(nbSections, file, "%s: Cannot read number of sections: %s", fileName); nbSectionsToAssign += nbSections; - tryReadlong(nbNodes, file, "%s: Cannot read number of nodes: %s", fileName); + tryReadLong(nbNodes, file, "%s: Cannot read number of nodes: %s", fileName); nodes[fileID].resize(nbNodes); verbosePrint("Reading %u nodes...\n", nbNodes); for (uint32_t i = nbNodes; i--;) @@ -584,7 +584,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) { uint32_t nbAsserts; - tryReadlong(nbAsserts, file, "%s: Cannot read number of assertions: %s", fileName); + tryReadLong(nbAsserts, file, "%s: Cannot read number of assertions: %s", fileName); verbosePrint("Reading %" PRIu32 " assertions...\n", nbAsserts); for (uint32_t i = 0; i < nbAsserts; i++) { Assertion &assertion = assertions.emplace_front();