From c83b87e0a05803370131899f339db3cdb5ad850d Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Mon, 21 Jul 2025 20:14:09 -0400 Subject: [PATCH] Make all non-`extern` globals `static` --- src/asm/charmap.cpp | 2 +- src/asm/section.cpp | 12 ++++++++---- src/asm/symbol.cpp | 7 +++++-- src/link/assign.cpp | 4 ++-- src/link/main.cpp | 2 -- src/link/output.cpp | 8 ++++---- src/link/patch.cpp | 4 ++-- src/link/section.cpp | 4 ++-- src/link/symbol.cpp | 4 ++-- 9 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/asm/charmap.cpp b/src/asm/charmap.cpp index 65ed513c..d4920f63 100644 --- a/src/asm/charmap.cpp +++ b/src/asm/charmap.cpp @@ -58,7 +58,7 @@ static std::deque charmapList; static std::unordered_map charmapMap; // Indexes into `charmapList` static Charmap *currentCharmap; -std::stack charmapStack; +static std::stack charmapStack; bool charmap_ForEach( void (*mapFunc)(std::string const &), diff --git a/src/asm/section.cpp b/src/asm/section.cpp index cb0a18fb..df5013eb 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -38,15 +38,19 @@ struct SectionStackEntry { std::stack unionStack; }; -std::stack currentUnionStack; -std::deque sectionStack; std::deque
sectionList; std::unordered_map sectionMap; // Indexes into `sectionList` -uint32_t curOffset; // Offset into the current section (see sect_GetSymbolOffset) Section *currentSection = nullptr; + +static uint32_t curOffset; // Offset into the current section (see `sect_GetSymbolOffset`) + +static std::deque sectionStack; + static Section *currentLoadSection = nullptr; static std::pair currentLoadLabelScopes = {nullptr, nullptr}; -int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutputOffset) +static int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutputOffset) + +static std::stack currentUnionStack; [[nodiscard]] static bool requireSection() { diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index 710ab5a4..59aaccae 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -22,20 +22,23 @@ using namespace std::literals; -std::unordered_map symbols; -std::unordered_set purgedSymbols; +static std::unordered_map symbols; +static std::unordered_set purgedSymbols; static Symbol const *globalScope = nullptr; // Current section's global label scope static Symbol const *localScope = nullptr; // Current section's local label scope + static Symbol *PCSymbol; static Symbol *NARGSymbol; static Symbol *globalScopeSymbol; static Symbol *localScopeSymbol; static Symbol *RSSymbol; + static char savedTIME[256]; static char savedDATE[256]; static char savedTIMESTAMP_ISO8601_LOCAL[256]; static char savedTIMESTAMP_ISO8601_UTC[256]; + static bool exportAll = false; // -E bool sym_IsPC(Symbol const *sym) { diff --git a/src/link/assign.cpp b/src/link/assign.cpp index 5af20068..3728fc35 100644 --- a/src/link/assign.cpp +++ b/src/link/assign.cpp @@ -32,9 +32,9 @@ struct FreeSpace { }; // Table of free space for each bank -std::vector> memory[SECTTYPE_INVALID]; +static std::vector> memory[SECTTYPE_INVALID]; -uint64_t nbSectionsToAssign; +static uint64_t nbSectionsToAssign; // Init the free space-modelling structs static void initFreeSpace() { diff --git a/src/link/main.cpp b/src/link/main.cpp index 34b5ecb2..8f97a02b 100644 --- a/src/link/main.cpp +++ b/src/link/main.cpp @@ -27,8 +27,6 @@ Options options; -FILE *linkerScript; - std::string const &FileStackNode::dump(uint32_t curLineNo) const { if (std::holds_alternative>(data)) { assume(parent); // REPT nodes use their parent's name diff --git a/src/link/output.cpp b/src/link/output.cpp index c610997a..bea9d467 100644 --- a/src/link/output.cpp +++ b/src/link/output.cpp @@ -25,10 +25,10 @@ static constexpr size_t BANK_SIZE = 0x4000; -FILE *outputFile; -FILE *overlayFile; -FILE *symFile; -FILE *mapFile; +static FILE *outputFile; +static FILE *overlayFile; +static FILE *symFile; +static FILE *mapFile; struct SortedSymbol { Symbol const *sym; diff --git a/src/link/patch.cpp b/src/link/patch.cpp index c7d60c84..758ab61c 100644 --- a/src/link/patch.cpp +++ b/src/link/patch.cpp @@ -16,14 +16,14 @@ #include "link/symbol.hpp" #include "link/warning.hpp" -std::deque assertions; +static std::deque assertions; struct RPNStackEntry { int32_t value; bool errorFlag; // Whether the value is a placeholder inserted for error recovery }; -std::deque rpnStack; +static std::deque rpnStack; static void pushRPN(int32_t value, bool comesFromError) { rpnStack.push_front({.value = value, .errorFlag = comesFromError}); diff --git a/src/link/section.cpp b/src/link/section.cpp index a3cd6497..a469b7bf 100644 --- a/src/link/section.cpp +++ b/src/link/section.cpp @@ -12,8 +12,8 @@ #include "link/warning.hpp" -std::vector> sectionList; -std::unordered_map sectionMap; // Indexes into `sectionList` +static std::vector> sectionList; +static std::unordered_map sectionMap; // Indexes into `sectionList` void sect_ForEach(void (*callback)(Section &)) { for (std::unique_ptr
&ptr : sectionList) { diff --git a/src/link/symbol.cpp b/src/link/symbol.cpp index 9f2e81a0..2c75aa4b 100644 --- a/src/link/symbol.cpp +++ b/src/link/symbol.cpp @@ -13,8 +13,8 @@ #include "link/section.hpp" #include "link/warning.hpp" -std::unordered_map symbols; -std::unordered_map> localSymbols; +static std::unordered_map symbols; +static std::unordered_map> localSymbols; void sym_ForEach(void (*callback)(Symbol &)) { for (auto &it : symbols) {