From 5f333d9753e2c18045fa028a6d0ae1739f907636 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Mon, 21 Jul 2025 19:22:10 -0400 Subject: [PATCH] More refactoring around `extern` variables --- include/asm/output.hpp | 1 - src/asm/fstack.cpp | 5 ++--- src/asm/lexer.cpp | 3 +-- src/asm/main.cpp | 27 +++++++++++++++------------ src/asm/output.cpp | 8 -------- src/asm/symbol.cpp | 2 +- src/gfx/pal_packing.cpp | 3 +-- src/link/assign.cpp | 7 ++----- 8 files changed, 22 insertions(+), 34 deletions(-) diff --git a/include/asm/output.hpp b/include/asm/output.hpp index 89c0154a..310f78a0 100644 --- a/include/asm/output.hpp +++ b/include/asm/output.hpp @@ -17,7 +17,6 @@ struct FileStackNode; enum StateFeature { STATE_EQU, STATE_VAR, STATE_EQUS, STATE_CHAR, STATE_MACRO, NB_STATE_FEATURES }; void out_RegisterNode(std::shared_ptr node); -void out_SetFileName(std::string const &name); void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift); void out_CreateAssert( AssertionType type, Expression const &expr, std::string const &message, uint32_t ofs diff --git a/src/asm/fstack.cpp b/src/asm/fstack.cpp index 78e564be..3dc371de 100644 --- a/src/asm/fstack.cpp +++ b/src/asm/fstack.cpp @@ -44,9 +44,8 @@ struct Context { static std::stack contextStack; // The first include path for `fstk_FindFile` to try is none at all -static std::vector includePaths = {""}; - -static std::deque preIncludeNames; +static std::vector includePaths = {""}; // -I +static std::deque preIncludeNames; // -P std::string FileStackNode::reptChain() const { std::string chain; diff --git a/src/asm/lexer.cpp b/src/asm/lexer.cpp index cdc9505b..b4e4c488 100644 --- a/src/asm/lexer.cpp +++ b/src/asm/lexer.cpp @@ -501,8 +501,7 @@ LexerState::~LexerState() { bool Expansion::advance() { assume(offset <= size()); - ++offset; - return offset > size(); + return ++offset > size(); } BufferedContent::~BufferedContent() { diff --git a/src/asm/main.cpp b/src/asm/main.cpp index fda3b356..72ecd3e2 100644 --- a/src/asm/main.cpp +++ b/src/asm/main.cpp @@ -182,7 +182,6 @@ int main(int argc, char *argv[]) { uint32_t maxDepth = 64; char const *dependFileName = nullptr; std::unordered_map> stateFileSpecs; - std::string newTarget; // Maximum of 100 errors only applies if rgbasm is printing errors to a terminal. if (isatty(STDERR_FILENO)) { options.maxErrors = 100; @@ -252,7 +251,11 @@ int main(int argc, char *argv[]) { break; case 'o': - out_SetFileName(musl_optarg); + if (!options.objectFileName.empty()) { + warnx("Overriding output filename %s", options.objectFileName.c_str()); + } + options.objectFileName = musl_optarg; + verbosePrint("Output filename %s\n", options.objectFileName.c_str()); // LCOV_EXCL_LINE break; case 'P': @@ -274,14 +277,12 @@ int main(int argc, char *argv[]) { opt_P(padByte); break; - unsigned long precision; - char const *precisionArg; - case 'Q': - precisionArg = musl_optarg; + case 'Q': { + char const *precisionArg = musl_optarg; if (precisionArg[0] == '.') { ++precisionArg; } - precision = strtoul(precisionArg, &endptr, 0); + unsigned long precision = strtoul(precisionArg, &endptr, 0); if (musl_optarg[0] == '\0' || *endptr != '\0') { fatal("Invalid argument for option 'Q'"); @@ -293,6 +294,7 @@ int main(int argc, char *argv[]) { opt_Q(precision); break; + } case 'r': maxDepth = strtoul(musl_optarg, &endptr, 0); @@ -338,9 +340,8 @@ int main(int argc, char *argv[]) { warnings.state.warningsEnabled = false; break; - unsigned long maxErrors; - case 'X': - maxErrors = strtoul(musl_optarg, &endptr, 0); + case 'X': { + unsigned long maxErrors = strtoul(musl_optarg, &endptr, 0); if (musl_optarg[0] == '\0' || *endptr != '\0') { fatal("Invalid argument for option 'X'"); @@ -352,6 +353,7 @@ int main(int argc, char *argv[]) { options.maxErrors = maxErrors; break; + } // Long-only options case 0: @@ -369,8 +371,8 @@ int main(int argc, char *argv[]) { break; case 'Q': - case 'T': - newTarget = musl_optarg; + case 'T': { + std::string newTarget = musl_optarg; if (depType == 'Q') { newTarget = make_escape(newTarget); } @@ -380,6 +382,7 @@ int main(int argc, char *argv[]) { options.targetFileName += newTarget; break; } + } break; // Unrecognized options diff --git a/src/asm/output.cpp b/src/asm/output.cpp index a84049d8..f154a99b 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -369,14 +369,6 @@ void out_WriteObject() { } } -void out_SetFileName(std::string const &name) { - if (!options.objectFileName.empty()) { - warnx("Overriding output filename %s", options.objectFileName.c_str()); - } - options.objectFileName = name; - verbosePrint("Output filename %s\n", options.objectFileName.c_str()); // LCOV_EXCL_LINE -} - static void dumpString(std::string const &escape, FILE *file) { for (char c : escape) { // Escape characters that need escaping diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index 6a9b7a7f..6bd7b8b3 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -36,7 +36,7 @@ static char savedTIME[256]; static char savedDATE[256]; static char savedTIMESTAMP_ISO8601_LOCAL[256]; static char savedTIMESTAMP_ISO8601_UTC[256]; -static bool exportAll; +static bool exportAll; // -E bool sym_IsPC(Symbol const *sym) { return sym == PCSymbol; diff --git a/src/gfx/pal_packing.cpp b/src/gfx/pal_packing.cpp index e88a0fc9..64361de1 100644 --- a/src/gfx/pal_packing.cpp +++ b/src/gfx/pal_packing.cpp @@ -330,9 +330,8 @@ static void decant( members.push_back(iter - processed.begin()); *iter = true; // Mark that proto-pal as processed } - ++iter; ++attrs; - } while (iter != processed.end()); + } while (++iter != processed.end()); if (to.combinedVolume(RANGE(colors)) <= options.maxOpaqueColors()) { // Iterate through the component's proto-palettes, and transfer them diff --git a/src/link/assign.cpp b/src/link/assign.cpp index 828c40c1..5af20068 100644 --- a/src/link/assign.cpp +++ b/src/link/assign.cpp @@ -149,12 +149,9 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) { location.address &= ~section.alignMask; // Go to next align boundary and add offset location.address += section.alignMask + 1 + section.alignOfs; - } else { + } else if (++spaceIdx < bankMem.size()) { // Any location is fine, so, next free block - ++spaceIdx; - if (spaceIdx < bankMem.size()) { - location.address = bankMem[spaceIdx].address; - } + location.address = bankMem[spaceIdx].address; } // If that location is past the current block's end,