From c135e2c6a0ec8db1fe0380d9c4cb84a5ef74eea1 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 3 May 2020 19:06:48 +0200 Subject: [PATCH] Fix local sym names not being expanded by `PURGE` And an additional bug that broke the attached test --- include/hashmap.h | 1 + src/asm/symbol.c | 8 ++++++-- test/asm/local-purge.asm | 8 ++++++++ test/asm/local-purge.err | 3 +++ test/asm/local-purge.out | 1 + 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/asm/local-purge.asm create mode 100644 test/asm/local-purge.err create mode 100644 test/asm/local-purge.out diff --git a/include/hashmap.h b/include/hashmap.h index 62ac4a32..1b5abbc0 100644 --- a/include/hashmap.h +++ b/include/hashmap.h @@ -11,6 +11,7 @@ #define RGBDS_LINK_HASHMAP_H #include +#include #define HASH_NB_BITS 32 #define HALF_HASH_NB_BITS 16 diff --git a/src/asm/symbol.c b/src/asm/symbol.c index e29e9ebb..3c5c60e0 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -208,7 +208,7 @@ void sym_Purge(char const *symName) yyerror("Symbol \"%s\" is referenced and thus cannot be purged", symName); } else { - hash_RemoveElement(symbols, symName); + hash_RemoveElement(symbols, symbol->name); if (symbol->type == SYM_MACRO) free(symbol->macro); free(symbol); @@ -476,11 +476,14 @@ struct Symbol *sym_Ref(char const *symName) if (nsym == NULL) { char fullname[MAXSYMLEN + 1]; + struct Symbol const *scope = NULL; - if (*symName == '.') { + if (symName[0] == '.') { if (!symbolScope) fatalerror("Local label reference '%s' in main scope", symName); + scope = symbolScope->scope ? symbolScope->scope + : symbolScope; fullSymbolName(fullname, sizeof(fullname), symName, symbolScope); symName = fullname; @@ -488,6 +491,7 @@ struct Symbol *sym_Ref(char const *symName) nsym = createsymbol(symName); nsym->type = SYM_REF; + nsym->scope = scope; } return nsym; diff --git a/test/asm/local-purge.asm b/test/asm/local-purge.asm new file mode 100644 index 00000000..889fdf1b --- /dev/null +++ b/test/asm/local-purge.asm @@ -0,0 +1,8 @@ +; At some point, the name of the local label was passed *unexpanded* to the +; function doing the removal. Ensure that this is fixed. + +SECTION "Test", ROM0[0] +Glob: +.loc + PURGE .loc + PRINTT "{.loc}\n" ; This should fail because the label doesn't exist anymore diff --git a/test/asm/local-purge.err b/test/asm/local-purge.err new file mode 100644 index 00000000..4fb44b6e --- /dev/null +++ b/test/asm/local-purge.err @@ -0,0 +1,3 @@ +ERROR: local-purge.asm(8): + '.loc' not defined +error: Assembly aborted (1 errors)! diff --git a/test/asm/local-purge.out b/test/asm/local-purge.out new file mode 100644 index 00000000..ebfabbe4 --- /dev/null +++ b/test/asm/local-purge.out @@ -0,0 +1 @@ +$0