mirror of
https://github.com/gbdev/rgbds.git
synced 2026-11-21 21:48:39 +00:00
Encapsulate Symbol and Section ID checks into isReferenced methods
This commit is contained in:
1 parent
af192a95b1
commit
bf894bce6f
4 files changed
+14
-12
No files matched your search
@@ -32,8 +32,8 @@ struct FileStackNode {
|
||||
// Meaningless at the root level, but gets written to the object file anyway, so init it
|
||||
uint32_t lineNo = 0;
|
||||
|
||||
// Set only if referenced: ID within the object file, `UINT32_MAX` if not output yet
|
||||
uint32_t ID = UINT32_MAX;
|
||||
uint32_t ID = UINT32_MAX; // ID of the node in the object file (`UINT32_MAX` if none)
|
||||
bool isReferenced() const { return ID != UINT32_MAX; }
|
||||
|
||||
// REPT iteration counts since last named node, in reverse depth order
|
||||
std::vector<uint32_t> &iters() { return std::get<std::vector<uint32_t>>(data); }
|
||||
|
||||
@@ -45,7 +45,8 @@ struct Symbol {
|
||||
>
|
||||
data;
|
||||
|
||||
uint32_t ID; // ID of the symbol in the object file (`UINT32_MAX` if none)
|
||||
uint32_t ID; // ID of the symbol in the object file (`UINT32_MAX` if none)
|
||||
bool isReferenced() const { return ID != UINT32_MAX; }
|
||||
uint32_t defIndex; // Ordering of the symbol in the state file
|
||||
|
||||
bool isDefined() const { return type != SYM_REF; }
|
||||
|
||||
+8
-7
@@ -65,14 +65,14 @@ static void putString(std::string const &s, FILE *file) {
|
||||
|
||||
void out_RegisterNode(std::shared_ptr<FileStackNode> node) {
|
||||
// If node is not already registered, register it (and parents), and give it a unique ID
|
||||
for (; node && node->ID == UINT32_MAX; node = node->parent) {
|
||||
for (; node && !node->isReferenced(); node = node->parent) {
|
||||
node->ID = fileStackNodes.size();
|
||||
fileStackNodes.push_front(node);
|
||||
}
|
||||
}
|
||||
|
||||
static void writeSection(Section const §, FILE *file) {
|
||||
assume(sect.src->ID != UINT32_MAX);
|
||||
assume(sect.src->isReferenced());
|
||||
|
||||
putString(sect.name, file);
|
||||
|
||||
@@ -96,7 +96,7 @@ static void writeSection(Section const §, FILE *file) {
|
||||
putLong(sect.patches.size(), file);
|
||||
|
||||
for (Patch const &patch : sect.patches) {
|
||||
assume(patch.src->ID != UINT32_MAX);
|
||||
assume(patch.src->isReferenced());
|
||||
|
||||
putLong(patch.src->ID, file);
|
||||
putLong(patch.lineNo, file);
|
||||
@@ -111,13 +111,14 @@ static void writeSection(Section const §, FILE *file) {
|
||||
}
|
||||
|
||||
static void writeSymbol(Symbol const &sym, FILE *file) {
|
||||
assume(sym.ID != UINT32_MAX);
|
||||
assume(!sym.isBuiltin); // All builtin symbols are designed to be per-invocation, not unique.
|
||||
assume(sym.isReferenced()); // Expect that its `ID` has been set.
|
||||
|
||||
putString(sym.name.str(), file);
|
||||
if (!sym.isDefined()) {
|
||||
putc(SYMTYPE_IMPORT, file);
|
||||
} else {
|
||||
assume(sym.src->ID != UINT32_MAX);
|
||||
assume(sym.src->isReferenced());
|
||||
|
||||
Section *symSection = sym.getSection();
|
||||
|
||||
@@ -131,7 +132,7 @@ static void writeSymbol(Symbol const &sym, FILE *file) {
|
||||
|
||||
void out_RegisterSymbol(Symbol &sym) {
|
||||
// Check for `sym.src`, to skip any built-in symbol from rgbasm
|
||||
if (sym.src && sym.ID == UINT32_MAX && !sym_IsPC(&sym)) {
|
||||
if (sym.src && !sym.isReferenced() && !sym_IsPC(&sym)) {
|
||||
sym.ID = objectSymbols.size(); // Set the symbol's ID within the object file
|
||||
objectSymbols.push_back(&sym);
|
||||
out_RegisterNode(sym.src);
|
||||
@@ -178,7 +179,7 @@ void out_CreateAssert(
|
||||
}
|
||||
|
||||
static void writeAssert(Assertion const &assert, FILE *file) {
|
||||
assume(assert.src->ID != UINT32_MAX);
|
||||
assume(assert.src->isReferenced());
|
||||
|
||||
putLong(assert.src->ID, file);
|
||||
putLong(assert.lineNo, file);
|
||||
|
||||
+2
-2
@@ -164,7 +164,7 @@ static void updateSymbolFilename(Symbol &sym) {
|
||||
sym.fileLine = sym.src ? lexer_GetLineNo() : 0;
|
||||
|
||||
// If the old node was registered, ensure the new one is too
|
||||
if (oldSrc && oldSrc->ID != UINT32_MAX) {
|
||||
if (oldSrc && oldSrc->isReferenced()) {
|
||||
out_RegisterNode(sym.src);
|
||||
}
|
||||
}
|
||||
@@ -348,7 +348,7 @@ void sym_Purge(InternedStr symName) {
|
||||
}
|
||||
} else if (sym->isBuiltin) {
|
||||
error("Built-in symbol `%s` cannot be purged", symName.c_str());
|
||||
} else if (sym->ID != UINT32_MAX) {
|
||||
} else if (sym->isReferenced()) {
|
||||
error("Symbol `%s` is referenced and thus cannot be purged", symName.c_str());
|
||||
} else {
|
||||
if (sym->isExported) {
|
||||
|
||||
Reference in new issue
Block a user