Skip to content

Commit 8edaa2b

Browse files
committed
Update and separate snapshots for two linking modes
Because the current compiler supports static linking and dynamic linking modes, the snapshots differ between these modes. This commit updates the related shell scripts and the build system to adjust the snapshot generation process according to the target architecture and the linking mode.
1 parent a811375 commit 8edaa2b

13 files changed

+46
-23
lines changed

Makefile

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ OBJS := $(SRCS:%.c=$(OUT)/%.o)
6262
deps := $(OBJS:%.o=%.o.d)
6363
TESTS := $(wildcard tests/*.c)
6464
TESTBINS := $(TESTS:%.c=$(OUT)/%.elf)
65-
SNAPSHOTS := $(foreach SNAPSHOT_ARCH,$(ARCHS), $(patsubst tests/%.c, tests/snapshots/%-$(SNAPSHOT_ARCH).json, $(TESTS)))
65+
SNAPSHOTS = $(foreach SNAPSHOT_ARCH,$(ARCHS), $(patsubst tests/%.c, tests/snapshots/%-$(SNAPSHOT_ARCH)-static.json, $(TESTS)))
66+
SNAPSHOTS += $(patsubst tests/%.c, tests/snapshots/%-arm-dynamic.json, $(TESTS))
6667

6768
all: config bootstrap
6869

@@ -107,23 +108,25 @@ check-sanitizer: $(OUT)/$(STAGE0)-sanitizer tests/driver.sh
107108
$(Q)rm $(OUT)/shecc
108109

109110
check-snapshots: $(OUT)/$(STAGE0) $(SNAPSHOTS) tests/check-snapshots.sh
110-
$(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config check-snapshot ARCH=$(SNAPSHOT_ARCH) --silent;)
111-
$(VECHO) "Switching backend back to %s\n" $(ARCH)
112-
$(Q)$(MAKE) distclean config ARCH=$(ARCH) --silent
111+
$(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config check-snapshot ARCH=$(SNAPSHOT_ARCH) DYNLINK=0 --silent;)
112+
$(Q)$(MAKE) distclean config check-snapshot ARCH=arm DYNLINK=1 --silent
113+
$(VECHO) "Switching backend back to %s (DYNLINK=0)\n" arm
114+
$(Q)$(MAKE) distclean config ARCH=arm --silent
113115

114116
check-snapshot: $(OUT)/$(STAGE0) tests/check-snapshots.sh
115-
$(VECHO) "Checking snapshot for %s\n" $(ARCH)
116-
tests/check-snapshots.sh $(ARCH)
117+
$(VECHO) "Checking snapshot for %s (DYNLINK=%s)\n" $(ARCH) $(DYNLINK)
118+
tests/check-snapshots.sh $(ARCH) $(DYNLINK)
117119
$(VECHO) " OK\n"
118120

119121
update-snapshots: tests/update-snapshots.sh
120-
$(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config update-snapshot ARCH=$(SNAPSHOT_ARCH) --silent;)
121-
$(VECHO) "Switching backend back to %s\n" $(ARCH)
122-
$(Q)$(MAKE) distclean config ARCH=$(ARCH) --silent
122+
$(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config update-snapshot ARCH=$(SNAPSHOT_ARCH) DYNLINK=0 --silent;)
123+
$(Q)$(MAKE) distclean config update-snapshot ARCH=arm DYNLINK=1 --silent
124+
$(VECHO) "Switching backend back to %s (DYNLINK=0)\n" arm
125+
$(Q)$(MAKE) distclean config ARCH=arm --silent
123126

124127
update-snapshot: $(OUT)/$(STAGE0) tests/update-snapshots.sh
125-
$(VECHO) "Updating snapshot for %s\n" $(ARCH)
126-
tests/update-snapshots.sh $(ARCH)
128+
$(VECHO) "Updating snapshot for %s (DYNLINK=%s)\n" $(ARCH) $(DYNLINK)
129+
tests/update-snapshots.sh $(ARCH) $(DYNLINK)
127130
$(VECHO) " OK\n"
128131

129132
$(OUT)/%.o: %.c

tests/check-snapshots.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,29 @@ set -u
44

55
readonly SHECC="$PWD/out/shecc"
66

7-
if [ "$#" != 1 ]; then
8-
echo "Usage: $0 <architecture>"
7+
if [ "$#" != 2 ]; then
8+
echo "Usage: $0 <architecture> <dynlink>"
99
exit 1
1010
fi
1111

1212
readonly ARCH="$1"
13+
readonly DYNLINK="$2"
14+
15+
if [ "$DYNLINK" = "1" ]; then
16+
readonly SHECC_CFLAGS="--dynlink"
17+
readonly MODE="dynamic"
18+
else
19+
readonly SHECC_CFLAGS=""
20+
readonly MODE="static"
21+
fi
1322

1423
function check_snapshot() {
1524
local source="$1"
16-
local ref="tests/snapshots/$(basename $source .c)-$ARCH.json"
25+
local ref="tests/snapshots/$(basename $source .c)-$ARCH-$MODE.json"
1726
local temp_exe=$(mktemp)
1827
local temp_json=$(mktemp --suffix .json)
1928

20-
$SHECC --dump-ir -o $temp_exe $source &>/dev/null
29+
$SHECC $SHECC_CFLAGS --dump-ir -o $temp_exe $source &>/dev/null
2130
dot -Tdot_json -o $temp_json CFG.dot
2231
diff -q <(cat $ref) \
2332
<(sed -E "/0x[0-9a-f]+/d" $temp_json | \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_subgraph_cnt":13,"directed":true,"edges":[{"_gvid":0,"head":14,"headport":"n","tail":13,"tailport":"s"},{"_gvid":1,"head":15,"tail":14,"weight":"100"},{"_gvid":2,"head":16,"tail":15,"weight":"100"},{"_gvid":3,"head":17,"headport":"n","tail":16,"tailport":"sw"},{"_gvid":4,"head":22,"headport":"n","tail":16,"tailport":"se"},{"_gvid":5,"head":18,"tail":17,"weight":"100"},{"_gvid":6,"head":19,"headport":"n","tail":18,"tailport":"s"},{"_gvid":7,"head":19,"headport":"n","tail":20,"tailport":"s"},{"_gvid":8,"head":19,"headport":"n","tail":21,"tailport":"s"},{"_gvid":9,"head":23,"headport":"n","tail":22,"tailport":"s"},{"_gvid":10,"head":24,"tail":23,"weight":"100"},{"_gvid":11,"head":25,"tail":24,"weight":"100"},{"_gvid":12,"head":26,"headport":"n","tail":25,"tailport":"sw"},{"_gvid":13,"head":27,"headport":"n","tail":25,"tailport":"se"},{"_gvid":14,"head":20,"tail":26,"weight":"100"},{"_gvid":15,"head":28,"headport":"n","tail":27,"tailport":"s"},{"_gvid":16,"head":29,"tail":28,"weight":"100"},{"_gvid":17,"head":30,"tail":29,"weight":"100"},{"_gvid":18,"head":31,"tail":30,"weight":"100"},{"_gvid":19,"head":32,"tail":31,"weight":"100"},{"_gvid":20,"head":33,"tail":32,"weight":"100"},{"_gvid":21,"head":34,"tail":33,"weight":"100"},{"_gvid":22,"head":35,"tail":34,"weight":"100"},{"_gvid":23,"head":36,"tail":35,"weight":"100"},{"_gvid":24,"head":37,"tail":36,"weight":"100"},{"_gvid":25,"head":38,"tail":37,"weight":"100"},{"_gvid":26,"head":21,"tail":38,"weight":"100"},{"_gvid":27,"head":40,"tail":39,"weight":"100"},{"_gvid":28,"head":41,"tail":40,"weight":"100"},{"_gvid":29,"head":42,"tail":41,"weight":"100"},{"_gvid":30,"head":43,"tail":42,"weight":"100"},{"_gvid":31,"head":44,"tail":43,"weight":"100"},{"_gvid":32,"head":45,"tail":44,"weight":"100"},{"_gvid":33,"head":46,"tail":45,"weight":"100"},{"_gvid":34,"head":47,"tail":46,"weight":"100"},{"_gvid":35,"head":48,"tail":47,"weight":"100"},{"_gvid":36,"head":49,"headport":"n","tail":48,"tailport":"s"}],"label":"","name":"CFG","objects":[{"_gvid":0,"edges":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26],"nodes":[13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"subgraphs":[1,2,3,4,5,6,7,8,9]},{"_gvid":1,"edges":[],"nodes":[13],"subgraphs":[]},{"_gvid":2,"edges":[1,2],"nodes":[14,15,16],"subgraphs":[]},{"_gvid":3,"edges":[5],"nodes":[17,18],"subgraphs":[]},{"_gvid":4,"edges":[],"nodes":[19],"subgraphs":[]},{"_gvid":5,"edges":[],"nodes":[22],"subgraphs":[]},{"_gvid":6,"edges":[10,11],"nodes":[23,24,25],"subgraphs":[]},{"_gvid":7,"edges":[14],"nodes":[20,26],"subgraphs":[]},{"_gvid":8,"edges":[],"nodes":[27],"subgraphs":[]},{"_gvid":9,"edges":[16,17,18,19,20,21,22,23,24,25,26],"nodes":[21,28,29,30,31,32,33,34,35,36,37,38],"subgraphs":[]},{"_gvid":10,"edges":[27,28,29,30,31,32,33,34,35,36],"nodes":[39,40,41,42,43,44,45,46,47,48,49],"subgraphs":[11,12]},{"_gvid":11,"edges":[27,28,29,30,31,32,33,34,35],"nodes":[39,40,41,42,43,44,45,46,47,48],"subgraphs":[]},{"_gvid":12,"edges":[],"nodes":[49],"subgraphs":[]},{"_gvid":13,"edges":[],"label":"pseudo","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":14,"edges":[],"label":".t0<SUB>0</SUB> := CONST 0","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":15,"edges":[],"label":".t1<SUB>0</SUB> := n<SUB>0</SUB> == .t0<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":16,"edges":[],"label":"BRANCH .t1<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":17,"edges":[],"label":".t2<SUB>0</SUB> := CONST 0","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":18,"edges":[],"label":"RETURN .t2<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":19,"edges":[],"label":"pseudo","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":20,"edges":[],"label":"RETURN .t5<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":21,"edges":[],"label":"RETURN .t12<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":22,"edges":[],"label":"pseudo","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":23,"edges":[],"label":".t3<SUB>0</SUB> := CONST 1","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":24,"edges":[],"label":".t4<SUB>0</SUB> := n<SUB>0</SUB> == .t3<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":25,"edges":[],"label":"BRANCH .t4<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":26,"edges":[],"label":".t5<SUB>0</SUB> := CONST 1","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":27,"edges":[],"label":"pseudo","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":28,"edges":[],"label":".t6<SUB>0</SUB> := CONST 1","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":29,"edges":[],"label":".t7<SUB>0</SUB> := n<SUB>0</SUB> - .t6<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":30,"edges":[],"label":"PUSH .t7<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":31,"edges":[],"label":"CALL @fib","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":32,"edges":[],"label":".t8<SUB>0</SUB> := RETURN VALUE","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":33,"edges":[],"label":".t9<SUB>0</SUB> := CONST 2","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":34,"edges":[],"label":".t10<SUB>0</SUB> := n<SUB>0</SUB> - .t9<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":35,"edges":[],"label":"PUSH .t10<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":36,"edges":[],"label":"CALL @fib","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":37,"edges":[],"label":".t11<SUB>0</SUB> := RETURN VALUE","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":38,"edges":[],"label":".t12<SUB>0</SUB> := .t8<SUB>0</SUB> + .t11<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":39,"edges":[],"label":".t13<SUB>0</SUB> := [.rodata] + 0","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":40,"edges":[],"label":".t14<SUB>0</SUB> := CONST 10","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":41,"edges":[],"label":"PUSH .t14<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":42,"edges":[],"label":"CALL @fib","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":43,"edges":[],"label":".t15<SUB>0</SUB> := RETURN VALUE","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":44,"edges":[],"label":"PUSH .t13<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":45,"edges":[],"label":"PUSH .t15<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":46,"edges":[],"label":"CALL @printf","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":47,"edges":[],"label":".t16<SUB>0</SUB> := CONST 0","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":48,"edges":[],"label":"RETURN .t16<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":49,"edges":[],"label":"pseudo","nodes":[],"shape":"box","subgraphs":[]}],"strict":true}

tests/snapshots/fib-arm-static.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/snapshots/fib-arm.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/snapshots/fib-riscv-static.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/snapshots/fib-riscv.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_subgraph_cnt":3,"directed":true,"edges":[{"_gvid":0,"head":4,"tail":3,"weight":"100"},{"_gvid":1,"head":5,"tail":4,"weight":"100"},{"_gvid":2,"head":6,"tail":5,"weight":"100"},{"_gvid":3,"head":7,"tail":6,"weight":"100"},{"_gvid":4,"head":8,"tail":7,"weight":"100"},{"_gvid":5,"head":9,"tail":8,"weight":"100"},{"_gvid":6,"head":10,"tail":9,"weight":"100"},{"_gvid":7,"head":11,"tail":10,"weight":"100"},{"_gvid":8,"head":12,"headport":"n","tail":11,"tailport":"s"}],"label":"","name":"CFG","objects":[{"_gvid":0,"edges":[0,1,2,3,4,5,6,7,8],"nodes":[3,4,5,6,7,8,9,10,11,12],"subgraphs":[1,2]},{"_gvid":1,"edges":[0,1,2,3,4,5,6,7],"nodes":[3,4,5,6,7,8,9,10,11],"subgraphs":[]},{"_gvid":2,"edges":[],"nodes":[12],"subgraphs":[]},{"_gvid":3,"edges":[],"label":".t0<SUB>0</SUB> := [.rodata] + 0","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":4,"edges":[],"label":"PUSH .t0<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":5,"edges":[],"label":"PUSH argc<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":6,"edges":[],"label":"CALL @printf","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":7,"edges":[],"label":".t1<SUB>0</SUB> := [.rodata] + 4","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":8,"edges":[],"label":"PUSH .t1<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":9,"edges":[],"label":"CALL @printf","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":10,"edges":[],"label":".t2<SUB>0</SUB> := CONST 0","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":11,"edges":[],"label":"RETURN .t2<SUB>0</SUB>","nodes":[],"shape":"box","subgraphs":[]},{"_gvid":12,"edges":[],"label":"pseudo","nodes":[],"shape":"box","subgraphs":[]}],"strict":true}

tests/snapshots/hello-arm-static.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

tests/snapshots/hello-arm.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)