Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further portability fixes (hopefully the last) #18

Merged
merged 6 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/asl2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 37 additions & 12 deletions demo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
6 changes: 3 additions & 3 deletions runtime/lib/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ 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);
}

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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/stmt_assert_00.asl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/stmt_case_01.asl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/stmt_try_01.asl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading