RGBLINK lists local symbols when encountering an unknown symbol reference (#1496)

This commit is contained in:
Sylvie
2024-09-06 21:31:13 -04:00
committed by GitHub
parent 7960a10228
commit 323028d9f2
17 changed files with 69 additions and 4 deletions

View File

@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <unordered_map>
#include <vector>
#include "helpers.hpp" // assume
@@ -11,6 +12,7 @@
#include "link/section.hpp"
std::unordered_map<std::string, Symbol *> symbols;
std::unordered_map<std::string, std::vector<Symbol *>> localSymbols;
void sym_ForEach(void (*callback)(Symbol &)) {
for (auto &it : symbols)
@@ -18,6 +20,12 @@ void sym_ForEach(void (*callback)(Symbol &)) {
}
void sym_AddSymbol(Symbol &symbol) {
if (symbol.type != SYMTYPE_EXPORT) {
if (symbol.type != SYMTYPE_IMPORT)
localSymbols[symbol.name].push_back(&symbol);
return;
}
Symbol *other = sym_GetSymbol(symbol.name);
int32_t *symValue = symbol.data.holds<int32_t>() ? &symbol.data.get<int32_t>() : nullptr;
int32_t *otherValue =
@@ -41,3 +49,30 @@ Symbol *sym_GetSymbol(std::string const &name) {
auto search = symbols.find(name);
return search != symbols.end() ? search->second : nullptr;
}
void sym_DumpLocalAliasedSymbols(std::string const &name) {
std::vector<Symbol *> const &locals = localSymbols[name];
int count = 0;
for (Symbol *local : locals) {
if (count++ == 3) {
size_t remaining = locals.size() - 3;
bool plural = remaining != 1;
fprintf(
stderr,
" ...and %zu more symbol%s with that name %s defined but not exported\n",
remaining,
plural ? "s" : "",
plural ? "are" : "is"
);
break;
}
fprintf(
stderr,
" A %s with that name is defined but not exported at ",
local->data.holds<Label>() ? "label" : "constant"
);
assume(local->src);
local->src->dump(local->lineNo);
putc('\n', stderr);
}
}