Fix local sym names not being expanded by PURGE

And an additional bug that broke the attached test
This commit is contained in:
ISSOtm
2020-05-03 19:06:48 +02:00
parent 12693081c9
commit c135e2c6a0
5 changed files with 19 additions and 2 deletions

View File

@@ -11,6 +11,7 @@
#define RGBDS_LINK_HASHMAP_H #define RGBDS_LINK_HASHMAP_H
#include <assert.h> #include <assert.h>
#include <stdbool.h>
#define HASH_NB_BITS 32 #define HASH_NB_BITS 32
#define HALF_HASH_NB_BITS 16 #define HALF_HASH_NB_BITS 16

View File

@@ -208,7 +208,7 @@ void sym_Purge(char const *symName)
yyerror("Symbol \"%s\" is referenced and thus cannot be purged", yyerror("Symbol \"%s\" is referenced and thus cannot be purged",
symName); symName);
} else { } else {
hash_RemoveElement(symbols, symName); hash_RemoveElement(symbols, symbol->name);
if (symbol->type == SYM_MACRO) if (symbol->type == SYM_MACRO)
free(symbol->macro); free(symbol->macro);
free(symbol); free(symbol);
@@ -476,11 +476,14 @@ struct Symbol *sym_Ref(char const *symName)
if (nsym == NULL) { if (nsym == NULL) {
char fullname[MAXSYMLEN + 1]; char fullname[MAXSYMLEN + 1];
struct Symbol const *scope = NULL;
if (*symName == '.') { if (symName[0] == '.') {
if (!symbolScope) if (!symbolScope)
fatalerror("Local label reference '%s' in main scope", fatalerror("Local label reference '%s' in main scope",
symName); symName);
scope = symbolScope->scope ? symbolScope->scope
: symbolScope;
fullSymbolName(fullname, sizeof(fullname), symName, fullSymbolName(fullname, sizeof(fullname), symName,
symbolScope); symbolScope);
symName = fullname; symName = fullname;
@@ -488,6 +491,7 @@ struct Symbol *sym_Ref(char const *symName)
nsym = createsymbol(symName); nsym = createsymbol(symName);
nsym->type = SYM_REF; nsym->type = SYM_REF;
nsym->scope = scope;
} }
return nsym; return nsym;

8
test/asm/local-purge.asm Normal file
View File

@@ -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

3
test/asm/local-purge.err Normal file
View File

@@ -0,0 +1,3 @@
ERROR: local-purge.asm(8):
'.loc' not defined
error: Assembly aborted (1 errors)!

1
test/asm/local-purge.out Normal file
View File

@@ -0,0 +1 @@
$0