Skip to content

Commit

Permalink
[ASM] Fix undefined symbol in define symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed Jun 9, 2024
1 parent 4c84a0b commit ebdecf5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions driver/asm_directive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ Error AsmDirective::defineSymbol(
context.value.clear();
return setError(scan, error);
}
if (context.reportUndefined && context.value.isUndefined())
return setError(symbol, UNDEFINED_SYMBOL);
if (context.reportUndefined && error.getError() == UNDEFINED_SYMBOL)
return setError(error);

setErrorIf(symbol, context.symbols.internSymbol(context.value.getUnsigned(), symbol, variable));
return getError();
Expand Down
36 changes: 36 additions & 0 deletions test/driver/test_asm_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,41 @@ z80:9:1: error: Duplicate label: "var1"
)");
}

void test_undefined() {
PREP_ASM(mc6809::AsmMc6809, MotorolaDirective);

driver.setUpperHex(true);

ASM("mc6809",
R"( org $1000
label1: lda #0 ; comment
label2: bra label1 comment
lda #1 * comment
)",
R"( 1000 : org $1000
1000 : 86 00 label1: lda #0 ; comment
1002 : 20 FC label2: bra label1 comment
mc6809:4:25: error: Undefined symbol: "comment"
1004 : 86 00 lda #1 * comment
)");

driver.clearSymbols();

ASM("mc6809",
R"( org $1000
label1: equ $1000 ; comment
label2: equ label1 comment
label3: equ 1 * comment
)",
R"( 1000 : org $1000
1000 : =1000 label1: equ $1000 ; comment
1000 : =1000 label2: equ label1 comment
mc6809:4:25: error: Undefined symbol: "comment"
1000 : =0 label3: equ 1 * comment
)");

}

void test_switch_cpu() {
mc6809::AsmMc6809 asm6809;
MotorolaDirective dir6809(asm6809);
Expand Down Expand Up @@ -363,6 +398,7 @@ void run_tests() {
RUN_TEST(test_symbols_mc6809);
RUN_TEST(test_symbols_ins8060);
RUN_TEST(test_symbols_z80);
RUN_TEST(test_undefined);
RUN_TEST(test_switch_cpu);
RUN_TEST(test_list_radix);
RUN_TEST(test_function);
Expand Down

0 comments on commit ebdecf5

Please sign in to comment.