From 521ca1c34a35c16f08cb077875e773330c26390a Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Wed, 21 Feb 2024 10:43:43 -0500 Subject: [PATCH] Use `std::vector` for symbols --- include/asm/symbol.hpp | 1 - src/asm/output.cpp | 19 +++++++------------ src/asm/symbol.cpp | 1 - 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/asm/symbol.hpp b/include/asm/symbol.hpp index 60b28c88..4ff38633 100644 --- a/include/asm/symbol.hpp +++ b/include/asm/symbol.hpp @@ -50,7 +50,6 @@ struct Symbol { }; uint32_t ID; // ID of the symbol in the object file (-1 if none) - struct Symbol *next; // Next object to output in the object file }; bool sym_IsPC(struct Symbol const *sym); diff --git a/src/asm/output.cpp b/src/asm/output.cpp index 76c5f228..f9036ec8 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "asm/charmap.hpp" #include "asm/fstack.hpp" @@ -48,10 +49,8 @@ const char *objectName; std::deque sectionList; -// Linked list of symbols to put in the object file -static struct Symbol *objectSymbols = NULL; -static struct Symbol **objectSymbolsTail = &objectSymbols; -static uint32_t nbSymbols = 0; // Length of the above list +// List of symbols to put in the object file +static std::vector objectSymbols; static struct Assertion *assertions = NULL; @@ -233,13 +232,9 @@ static void writesymbol(struct Symbol const *sym, FILE *f) static void registerSymbol(struct Symbol *sym) { - *objectSymbolsTail = sym; - objectSymbolsTail = &sym->next; + sym->ID = objectSymbols.size(); + objectSymbols.push_back(sym); out_RegisterNode(sym->src); - if (nbSymbols == (uint32_t)-1) - fatalerror("Registered too many symbols (%" PRIu32 - "); try splitting up your files\n", (uint32_t)-1); - sym->ID = nbSymbols++; } // Returns a symbol's ID within the object file @@ -482,7 +477,7 @@ void out_WriteObject(void) fprintf(f, RGBDS_OBJECT_VERSION_STRING); putlong(RGBDS_OBJECT_REV, f); - putlong(nbSymbols, f); + putlong(objectSymbols.size(), f); putlong(sectionList.size(), f); putlong(getNbFileStackNodes(), f); @@ -494,7 +489,7 @@ void out_WriteObject(void) node->next->ID, node->ID); } - for (struct Symbol const *sym = objectSymbols; sym; sym = sym->next) + for (struct Symbol const *sym : objectSymbols) writesymbol(sym, f); for (struct Section *sect : sectionList) { diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index baf5bd0c..e2cd32af 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -137,7 +137,6 @@ static struct Symbol *createsymbol(char const *symName) sym->section = NULL; setSymbolFilename(sym); sym->ID = -1; - sym->next = NULL; hash_AddElement(symbols, sym->name, sym); return sym;