From b763ec745340f8c19617b033844e2e63fa927b36 Mon Sep 17 00:00:00 2001 From: Kyle Lin Date: Fri, 6 Dec 2024 21:06:01 +0800 Subject: [PATCH] Refactor make rules, fix stage 0 sizeof test --- .github/workflows/main.yml | 6 +++--- Makefile | 6 +++--- tests/driver.sh | 14 ++++++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4001c73..631cc7e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,9 +22,9 @@ jobs: make clean config make check-snapshots || exit 1 make distclean config ARCH=arm - make check-all || exit 1 + make check || exit 1 make distclean config ARCH=riscv - make check-all || exit 1 + make check || exit 1 host-arm: runs-on: ubuntu-22.04 @@ -44,7 +44,7 @@ jobs: apt-get install -q -y build-essential run: | make config ARCH=arm - make check-all || exit 1 + make check || exit 1 coding-style: runs-on: ubuntu-22.04 diff --git a/Makefile b/Makefile index 27d60a5..0bbeb98 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,9 @@ $(OUT)/tests/%.elf: tests/%.c $(OUT)/$(STAGE0) chmod +x $@ ; $(PRINTF) "Running $@ ...\n" $(Q)$(TARGET_EXEC) $@ && $(call pass) -check: $(OUT)/$(STAGE0) $(TESTBINS) tests/driver.sh +check: check-stage1 check-stage2 check-snapshots + +check-stage1: $(OUT)/$(STAGE0) $(TESTBINS) tests/driver.sh $(VECHO) " TEST STAGE 0\n" tests/driver.sh @@ -64,8 +66,6 @@ check-snapshots: $(OUT)/$(STAGE0) $(SNAPSHOTS) tests/check-snapshots.sh $(VECHO) " TEST SNAPSHOTS\n" tests/check-snapshots.sh -check-all: $(OUT)/$(STAGE2) $(TESTBINS) check check-stage2 - $(OUT)/%.o: %.c $(VECHO) " CC\t$@\n" $(Q)$(CC) -o $@ $(CFLAGS) -c -MMD -MF $@.d $< diff --git a/tests/driver.sh b/tests/driver.sh index c8473ef..017b1ca 100755 --- a/tests/driver.sh +++ b/tests/driver.sh @@ -4,6 +4,12 @@ set -u readonly SHECC="$PWD/out/shecc" +if [ "$(getconf LONG_BIT)" == "64" ]; then + readonly HOST_PTR_SIZE=8 +else + readonly HOST_PTR_SIZE=4 +fi + # try - test shecc with given code # Usage: # - try exit_code input_code @@ -408,10 +414,10 @@ items 20 "int *p; int a[3]; a[0] = 10; a[1] = 20; a[2] = 30; p = a; p+=1; return expr 4 "sizeof(int)"; expr 1 "sizeof(char)"; # sizeof pointers -expr 8 "sizeof(void*)"; -expr 8 "sizeof(_Bool*)"; -expr 8 "sizeof(char*)"; -expr 8 "sizeof(int*)"; +expr $HOST_PTR_SIZE "sizeof(void*)"; +expr $HOST_PTR_SIZE "sizeof(_Bool*)"; +expr $HOST_PTR_SIZE "sizeof(char*)"; +expr $HOST_PTR_SIZE "sizeof(int*)"; # switch-case items 10 "int a; a = 0; switch (3) { case 0: return 2; case 3: a = 10; break; case 1: return 0; } return a;"