mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Allow multiple identical exported numeric constants (#1341)
This still doesn't allow identical exported label constants. That can be addressed when or if it's requested for a real use case. Symbols only store one source filename + line number, so this arbitrarily keeps the last read symbol as the reported one.
This commit is contained in:
@@ -26,8 +26,12 @@ Label const &Symbol::label() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sym_AddSymbol(Symbol &symbol) {
|
void sym_AddSymbol(Symbol &symbol) {
|
||||||
// Check if the symbol already exists
|
Symbol *other = sym_GetSymbol(symbol.name);
|
||||||
if (Symbol *other = sym_GetSymbol(symbol.name); other) {
|
int32_t const *symValue = std::get_if<int32_t>(&symbol.data);
|
||||||
|
int32_t const *otherValue = other ? std::get_if<int32_t>(&other->data) : nullptr;
|
||||||
|
|
||||||
|
// Check if the symbol already exists with a different value
|
||||||
|
if (other && !(symValue && otherValue && *symValue == *otherValue)) {
|
||||||
fprintf(stderr, "error: \"%s\" both in %s from ", symbol.name.c_str(), symbol.objFileName);
|
fprintf(stderr, "error: \"%s\" both in %s from ", symbol.name.c_str(), symbol.objFileName);
|
||||||
symbol.src->dump(symbol.lineNo);
|
symbol.src->dump(symbol.lineNo);
|
||||||
fprintf(stderr, " and in %s from ", other->objFileName);
|
fprintf(stderr, " and in %s from ", other->objFileName);
|
||||||
@@ -36,7 +40,7 @@ void sym_AddSymbol(Symbol &symbol) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not, add it
|
// If not, add it (potentially replacing the previous same-value symbol)
|
||||||
symbols[symbol.name] = &symbol;
|
symbols[symbol.name] = &symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
test/link/same-consts/a.asm
Normal file
2
test/link/same-consts/a.asm
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def constant equ 42
|
||||||
|
export constant
|
||||||
2
test/link/same-consts/b.asm
Normal file
2
test/link/same-consts/b.asm
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def constant equ 42
|
||||||
|
export constant
|
||||||
0
test/link/same-consts/out.err
Normal file
0
test/link/same-consts/out.err
Normal file
@@ -190,6 +190,15 @@ tryDiff "$test"/out.err "$outtemp"
|
|||||||
tryCmp "$test"/out.gb "$gbtemp"
|
tryCmp "$test"/out.gb "$gbtemp"
|
||||||
evaluateTest
|
evaluateTest
|
||||||
|
|
||||||
|
test="same-consts"
|
||||||
|
startTest
|
||||||
|
"$RGBASM" -o "$otemp" "$test"/a.asm
|
||||||
|
"$RGBASM" -o "$gbtemp2" "$test"/b.asm
|
||||||
|
continueTest
|
||||||
|
rgblinkQuiet -o "$gbtemp" "$gbtemp2" "$otemp" 2>"$outtemp"
|
||||||
|
tryDiff "$test"/out.err "$outtemp"
|
||||||
|
evaluateTest
|
||||||
|
|
||||||
test="scramble-romx"
|
test="scramble-romx"
|
||||||
startTest
|
startTest
|
||||||
"$RGBASM" -o "$otemp" "$test"/a.asm
|
"$RGBASM" -o "$otemp" "$test"/a.asm
|
||||||
|
|||||||
Reference in New Issue
Block a user