diff --git a/bin/asl2c.py b/bin/asl2c.py index 6e89e254..5c7af6d6 100755 --- a/bin/asl2c.py +++ b/bin/asl2c.py @@ -215,9 +215,13 @@ def report(x): if verbose: print(x) +# Run command (printing command first if verbose) and abort if command fails +# (The assumption is that the command printed a useful/meaningful error message already) def run(cmd): report(" ".join(cmd)) - subprocess.run(cmd, check=True) + r = subprocess.run(cmd) + if r.returncode != 0: + exit(r.returncode) ################################################################ # Compile/link flags diff --git a/demo/Makefile b/demo/Makefile index 0563e08b..8ea24a13 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -11,31 +11,50 @@ ASL_PATH = ..:. ASLI = ../_build/default/bin/asli.exe ASL2C = ../_build/default/bin/asl2c.py +################################################################ +# Test whether we have GNU as or clang emulating as +# (We can only build an elf file and run the test if we have +# GNU as.) +################################################################ + +HAVE_GNU_AS := `as --version | grep -q 'GNU assembler'` + +REPORT_NOT_GAS = "Unable to build ELF file to use in demo: GNU 'as' required - skipping demo" + ################################################################ # Build a test program using the demo ISA ################################################################ clean:: - $(RM) test.s test.o test.elf + $(RM) test.o test.elf -test.s : test.S assembly.s +# run preprocessor on test.S using default rule +test.s: test.S assembly.s test.o: test.s - as test.s -o test.o + @ if ${HAVE_GNU_AS}; then \ + as test.s -o test.o; \ + else echo ${REPORT_NOT_GAS}; fi test.elf: test.o - ld test.o -o test.elf - nm test.elf + @ if ${HAVE_GNU_AS}; then \ + ld test.o -o test.elf; \ + nm test.elf; \ + else echo ${REPORT_NOT_GAS}; fi ################################################################ # Run demo on interpreter ################################################################ test: test.elf test.prj - env ASL_PATH="${ASL_PATH}" ${ASLI} --nobanner --batchmode demo.asl --project test.prj | filecheck test.prj + @ if ${HAVE_GNU_AS}; then \ + env ASL_PATH="${ASL_PATH}" ${ASLI} --nobanner --batchmode demo.asl --project test.prj | filecheck test.prj ; \ + else echo ${REPORT_NOT_GAS}; fi demo: test.elf - env ASL_PATH="${ASL_PATH}" ${ASLI} --batchmode demo.asl --project test.prj + @ if ${HAVE_GNU_AS}; then \ + env ASL_PATH="${ASL_PATH}" ${ASLI} --batchmode demo.asl --project test.prj ; \ + else echo ${REPORT_NOT_GAS}; fi ################################################################ # Build simulator using C backend @@ -52,15 +71,21 @@ CC=clang-16 -std=c2x .PRECIOUS: simulator_% simulator_% : simulator.c exports.json demo.asl - $(ASL2C) --basename=sim --intermediates=log --backend=$* > sim.prj - env ASL_PATH="${ASL_PATH}" $(ASLI) --nobanner --batchmode --project=sim.prj --configuration=exports.json demo.asl - $(CC) ${CFLAGS} simulator.c -o $@ ${LDFLAGS} + @ if ${HAVE_GNU_AS}; then \ + $(ASL2C) --basename=sim --intermediates=log --backend=$* > sim.prj ; \ + env ASL_PATH="${ASL_PATH}" $(ASLI) --nobanner --batchmode --project=sim.prj --configuration=exports.json demo.asl ; \ + $(CC) ${CFLAGS} simulator.c -o $@ ${LDFLAGS} ; \ + else echo ${REPORT_NOT_GAS}; fi test_% : simulator_% test.elf test.prj - ./simulator_$* test.elf --steps=20 | filecheck test.prj + @ if ${HAVE_GNU_AS}; then \ + ./simulator_$* test.elf --steps=20 | filecheck test.prj ; \ + else echo ${REPORT_NOT_GAS}; fi demo_% : simulator_% test.elf test.prj - ./simulator_$* test.elf --steps=20 + @ if ${HAVE_GNU_AS}; then \ + ./simulator_$* test.elf --steps=20; \ + else echo ${REPORT_NOT_GAS}; fi clean :: $(RM) sim.prj diff --git a/runtime/.gitignore b/runtime/.gitignore new file mode 100644 index 00000000..378eac25 --- /dev/null +++ b/runtime/.gitignore @@ -0,0 +1 @@ +build diff --git a/runtime/lib/error.c b/runtime/lib/error.c index 573cd3be..5a577973 100644 --- a/runtime/lib/error.c +++ b/runtime/lib/error.c @@ -20,14 +20,14 @@ extern "C" { void ASL_error(const char* loc, const char* msg) { - fprintf(stderr, "%s: ASL error: %s\n\n", loc, msg); + printf("%s: ASL error: %s\n\n", loc, msg); exit(1); } void ASL_runtime_error(const char *msg) { - fprintf(stderr, "Runtime error: %s\n", msg); + printf("Runtime error: %s\n", msg); exit(1); } @@ -35,7 +35,7 @@ void ASL_assert(const char* loc, const char* expr, bool c) { if (!c) { - fprintf(stderr, "%s: Evaluation error: assertion failure: %s\n\n", loc, expr); + printf("%s: Evaluation error: assertion failure: %s\n\n", loc, expr); exit(1); } } diff --git a/tests/backends/stmt_assert_00.asl b/tests/backends/stmt_assert_00.asl index b711c17d..e0306b39 100644 --- a/tests/backends/stmt_assert_00.asl +++ b/tests/backends/stmt_assert_00.asl @@ -1,4 +1,4 @@ -// RUN: not %aslrun %s |& filecheck %s +// RUN: not %aslrun %s | filecheck %s // Copyright (C) 2023-2024 Intel Corporation func FUT(x : bits(4)) => bits(4) diff --git a/tests/backends/stmt_case_01.asl b/tests/backends/stmt_case_01.asl index 45e8f240..0b606eb6 100644 --- a/tests/backends/stmt_case_01.asl +++ b/tests/backends/stmt_case_01.asl @@ -1,4 +1,4 @@ -// RUN: not %aslrun %s |& filecheck %s +// RUN: not %aslrun %s | filecheck %s // Copyright (C) 2023-2024 Intel Corporation func Test(x : integer) => integer diff --git a/tests/backends/stmt_try_01.asl b/tests/backends/stmt_try_01.asl index f05f9f0c..e90f051a 100644 --- a/tests/backends/stmt_try_01.asl +++ b/tests/backends/stmt_try_01.asl @@ -1,4 +1,4 @@ -// RUN: not %aslrun %s |& filecheck %s +// RUN: not %aslrun %s | filecheck %s // Copyright (C) 2023-2024 Intel Corporation type E0 of exception;