Skip to content

Commit d7896a1

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 4a532e6 commit d7896a1

9 files changed

+39
-19
lines changed

Makefile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ ARCH ?= $(firstword $(ARCHS))
4242
HOST_ARCH = $(shell arch 2>/dev/null)
4343
SRCDIR := $(shell find src -type d)
4444
LIBDIR := $(shell find lib -type d)
45+
LINK_MODES = static dynamic
4546

4647
BUILTIN_LIBC ?= c.c
4748
STAGE0_FLAGS ?= --dump-ir
@@ -61,7 +62,8 @@ OBJS := $(SRCS:%.c=$(OUT)/%.o)
6162
deps := $(OBJS:%.o=%.o.d)
6263
TESTS := $(wildcard tests/*.c)
6364
TESTBINS := $(TESTS:%.c=$(OUT)/%.elf)
64-
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))
6567

6668
all: config bootstrap
6769

@@ -106,23 +108,25 @@ check-sanitizer: $(OUT)/$(STAGE0)-sanitizer tests/driver.sh
106108
$(Q)rm $(OUT)/shecc
107109

108110
check-snapshots: $(OUT)/$(STAGE0) $(SNAPSHOTS) tests/check-snapshots.sh
109-
$(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config check-snapshot ARCH=$(SNAPSHOT_ARCH) --silent;)
110-
$(VECHO) "Switching backend back to %s\n" $(ARCH)
111-
$(Q)$(MAKE) distclean config ARCH=$(ARCH) --silent
111+
$(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config check-snapshot ARCH=$(SNAPSHOT_ARCH) LINK_MODE=static --silent;)
112+
$(Q)$(MAKE) distclean config check-snapshot ARCH=arm LINK_MODE=dynamic --silent
113+
$(VECHO) "Switching backend back to %s (%s mode)\n" arm static
114+
$(Q)$(MAKE) distclean config ARCH=arm --silent
112115

113116
check-snapshot: $(OUT)/$(STAGE0) tests/check-snapshots.sh
114-
$(VECHO) "Checking snapshot for %s\n" $(ARCH)
115-
tests/check-snapshots.sh $(ARCH)
117+
$(VECHO) "Checking snapshot for %s (%s mode)\n" $(ARCH) $(LINK_MODE)
118+
tests/check-snapshots.sh $(ARCH) $(LINK_MODE)
116119
$(VECHO) " OK\n"
117120

118121
update-snapshots: tests/update-snapshots.sh
119-
$(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config update-snapshot ARCH=$(SNAPSHOT_ARCH) --silent;)
120-
$(VECHO) "Switching backend back to %s\n" $(ARCH)
121-
$(Q)$(MAKE) distclean config ARCH=$(ARCH) --silent
122+
$(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config update-snapshot ARCH=$(SNAPSHOT_ARCH) LINK_MODE=static --silent;)
123+
$(Q)$(MAKE) distclean config update-snapshot ARCH=arm LINK_MODE=dynamic --silent
124+
$(VECHO) "Switching backend back to %s (%s mode)\n" arm static
125+
$(Q)$(MAKE) distclean config ARCH=arm --silent
122126

123127
update-snapshot: $(OUT)/$(STAGE0) tests/update-snapshots.sh
124-
$(VECHO) "Updating snapshot for %s\n" $(ARCH)
125-
tests/update-snapshots.sh $(ARCH)
128+
$(VECHO) "Updating snapshot for %s (%s mode)\n" $(ARCH) $(LINK_MODE)
129+
tests/update-snapshots.sh $(ARCH) $(LINK_MODE)
126130
$(VECHO) " OK\n"
127131

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

tests/check-snapshots.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@ 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> <link_mode>"
99
exit 1
1010
fi
1111

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

1421
function check_snapshot() {
1522
local source="$1"
16-
local ref="tests/snapshots/$(basename $source .c)-$ARCH.json"
23+
local ref="tests/snapshots/$(basename $source .c)-$ARCH-$MODE.json"
1724
local temp_exe=$(mktemp)
1825
local temp_json=$(mktemp --suffix .json)
1926

20-
$SHECC --dump-ir -o $temp_exe $source &>/dev/null
27+
$SHECC $SHECC_CFLAGS --dump-ir -o $temp_exe $source &>/dev/null
2128
dot -Tdot_json -o $temp_json CFG.dot
2229
diff -q <(cat $ref) \
2330
<(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}
File renamed without changes.
File renamed without changes.
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}
File renamed without changes.
File renamed without changes.

tests/update-snapshots.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@ 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> <link_mode>"
99
exit 1
1010
fi
1111

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

1421
function update_snapshot() {
1522
local source="$1"
16-
local dest="tests/snapshots/$(basename $source .c)-$ARCH.json"
23+
local dest="tests/snapshots/$(basename $source .c)-$ARCH-$MODE.json"
1724
local temp_exe=$(mktemp)
1825
local temp_json=$(mktemp --suffix .json)
1926

20-
$SHECC --dump-ir -o $temp_exe $source &>/dev/null
27+
$SHECC $SHECC_CFLAGS --dump-ir -o $temp_exe $source &>/dev/null
2128
dot -Tdot_json -o $temp_json CFG.dot
2229
sed -i -E "/0x[0-9a-f]+/d" $temp_json
2330
jq -S -c '.edges |= sort_by(._gvid) | .objects |= sort_by(._gvid) |

0 commit comments

Comments
 (0)