diff --git a/driver/asm_directive.cpp b/driver/asm_directive.cpp index 90ffe45d..22206065 100644 --- a/driver/asm_directive.cpp +++ b/driver/asm_directive.cpp @@ -216,8 +216,11 @@ Error AsmDirective::includeFile(StrScanner &scan, Context &context) { } else { p = filename.takeWhile([](char s) { return !isspace(s); }); } + const auto error = context.sources.open(filename); + if (error) + setErrorIf(filename, error); scan = p; - return setError(context.sources.open(filename)); + return error; } Error AsmDirective::defineFunction(StrScanner &scan, Context &context) { diff --git a/driver/asm_formatter.cpp b/driver/asm_formatter.cpp index 1b16b316..d9965eb2 100644 --- a/driver/asm_formatter.cpp +++ b/driver/asm_formatter.cpp @@ -76,7 +76,7 @@ StrBuffer &AsmFormatter::getLine(StrBuffer &out) { _formatter.formatDec(out, column); } out.rtext_P(PSTR(": error: ")).rtext_P(_error.errorText_P()); - if (*_error.errorAt()) + if (_error.errorAt() && *_error.errorAt()) out.rtext_P(PSTR(": \"")).rtext(_error.errorAt()).rletter('"'); _nextLine = -1; } else { diff --git a/test/driver/test_asm_formatter.cpp b/test/driver/test_asm_formatter.cpp index 14e488e9..27594665 100644 --- a/test/driver/test_asm_formatter.cpp +++ b/test/driver/test_asm_formatter.cpp @@ -318,6 +318,32 @@ void test_forward_labels() { " 9/ 1009 : =4 label5 equ 4\n"); } +void test_include() { + PREP_ASM(mc6809::AsmMc6809, MotorolaDirective); + + TestReader exist("data/exist.inc"); + sources.add(exist); + exist.add(" fcc /exist/\n"); + + driver.setUpperHex(true); + driver.setLineNumber(true); + driver.setOption("smart-branch", "on"); + + ASM("mc6809", + " cpu mc6809\n" + "* comment line\n" + " org $abcd\n" + " include \"data/exist.inc\"\n" + " include \"data/not-exist.inc\"\n", + " 1/ 0 : cpu mc6809\n" + " 2/ 0 : * comment line\n" + " 3/ ABCD : org $abcd\n" + " 4/ ABCD : include \"data/exist.inc\"\n" + "(1) 1/ ABCD : 65 78 69 73 74 fcc /exist/\n" + "mc6809:5:18: error: Include file not found: \"data/not-exist.inc\"\"\n" + " 5/ ABD2 : include \"data/not-exist.inc\"\n"); +} + void run_tests() { RUN_TEST(test_symbols_mc6809); RUN_TEST(test_symbols_ins8060); @@ -326,6 +352,7 @@ void run_tests() { RUN_TEST(test_list_radix); RUN_TEST(test_function); RUN_TEST(test_forward_labels); + RUN_TEST(test_include); } } // namespace test