aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-08-18 20:48:27 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-08-18 21:07:11 +0300
commit4af5176d6377958a457da3e5f671ce21540fad70 (patch)
tree04e7f2fe66e7c2e05f6a47b0c8108cf407ee6c93
parentcdbe058f69f1db9c552e1b4a1ec5f94c12fc48a2 (diff)
downloadqbt-4af5176d6377958a457da3e5f671ce21540fad70.tar.gz
qbt-4af5176d6377958a457da3e5f671ce21540fad70.zip
add tests and fixes on top of 674438
-rw-r--r--.gitignore2
-rw-r--r--Makefile4
-rw-r--r--src/regalloc.c2
-rw-r--r--src/ssa.c8
-rw-r--r--tests/Makefile26
-rw-r--r--tests/addr/addr.qbt (renamed from tests/addr.qbt)0
-rw-r--r--tests/addr/source.mk1
-rw-r--r--tests/blit/blit.qbt (renamed from tests/blit.qbt)0
-rw-r--r--tests/blit/source.mk1
-rw-r--r--tests/empty/empty.qbt (renamed from tests/empty.qbt)0
-rw-r--r--tests/empty/source.mk1
-rw-r--r--tests/hello_world/hello_world.qbt (renamed from tests/hello_world.qbt)0
-rw-r--r--tests/hello_world/source.mk1
-rw-r--r--tests/save/save.qbt (renamed from tests/save.qbt)4
-rw-r--r--tests/save/source.mk1
-rwxr-xr-xtests/scripts/gen-simple14
-rwxr-xr-xtests/scripts/gen-simple-xfail29
-rw-r--r--tests/scripts/makefile16
-rw-r--r--tests/simple_args/simple_args.qbt (renamed from tests/simple_args.qbt)0
-rw-r--r--tests/simple_args/source.mk1
-rw-r--r--tests/simple_external_putchar/simple_external_putchar.qbt (renamed from tests/simple_external_putchar.qbt)0
-rw-r--r--tests/simple_external_putchar/source.mk1
-rw-r--r--tests/simple_loop/simple_loop.qbt (renamed from tests/simple_loop.qbt)0
-rw-r--r--tests/simple_loop/source.mk1
-rw-r--r--tests/unreachable/source.mk1
-rw-r--r--tests/unreachable/unreachable.qbt (renamed from tests/unreachable.qbt)0
26 files changed, 110 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 68c0d5d..55f811c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
deps.mk
+tests.mk
docs/output
+reports
build
gen
qbt
diff --git a/Makefile b/Makefile
index d4247f1..3a81560 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,10 @@ all: setup
analyze: setup
CC='gcc -fanalyzer' SKIP_ANALYZER='-fno-analyzer' $(MAKE) CROSS_COMPILE=
+.PHONY: check
+check: all
+ $(MAKE) -C tests -k check
+
.PHONY:
setup:
@echo -n > deps.mk
diff --git a/src/regalloc.c b/src/regalloc.c
index 6265c6d..61a90b1 100644
--- a/src/regalloc.c
+++ b/src/regalloc.c
@@ -184,7 +184,7 @@ static void build_active_between(struct vec *active, struct vec *prev_active, st
* the lifetimes vector */
if (prev_active)
foreach_lifetime(li, *prev_active) {
- struct lifetime l = lifetime_at(*lifetimes, li);
+ struct lifetime l = lifetime_at(*prev_active, li);
if (l.end <= start)
continue;
diff --git a/src/ssa.c b/src/ssa.c
index 7af342b..74ad59a 100644
--- a/src/ssa.c
+++ b/src/ssa.c
@@ -72,6 +72,9 @@ top:
}
b = vect_pop(struct blk *, stack);
+ if (done(b, visited))
+ goto top;
+
if (return_blk(b)) {
b->s1 = NULL;
b->s2 = NULL;
@@ -185,13 +188,16 @@ top:
}
b = vect_pop(struct blk *, stack);
+ if (done(b, visited))
+ goto top;
+
if (!entered(b, visited)) {
vec_append(&stack, &b);
if (b->s1)
vec_append(&stack, &b->s1);
- if (b->s2)
+ if (b->s2 && b->s2 != b->s1)
vec_append(&stack, &b->s2);
enter(b);
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..1f37445
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,26 @@
+check:
+ $(MAKE) -f scripts/makefile check
+
+.DEFAULT:
+ $(MAKE) -f scripts/makefile $<
+
+SOURCES != echo */source.mk
+DO != echo -n > tests.mk && rm -rf reports
+
+SIMPLE :=
+SIMPLE_XFAIL :=
+
+include $(SOURCES)
+
+# pass through xargs to 'trick' it into expanding each SIMPLE_XFAIL into a
+# separate argument for the script, as make would otherwise just split at each space
+# this way we can pass spaces as arguments to the generator scripts, pretty neat
+# huh?
+DO != echo "$(SIMPLE)" | xargs ./scripts/gen-simple
+DO != echo "$(SIMPLE_XFAIL)" | xargs ./scripts/gen-simple-xfail
+
+RM ?= rm
+
+.PHONY: clean
+clean:
+ $(RM) -rf reports
diff --git a/tests/addr.qbt b/tests/addr/addr.qbt
index efe149c..efe149c 100644
--- a/tests/addr.qbt
+++ b/tests/addr/addr.qbt
diff --git a/tests/addr/source.mk b/tests/addr/source.mk
new file mode 100644
index 0000000..bc4b83e
--- /dev/null
+++ b/tests/addr/source.mk
@@ -0,0 +1 @@
+SIMPLE_XFAIL += addr,'unimplemented insn: ADDR'
diff --git a/tests/blit.qbt b/tests/blit/blit.qbt
index b8fa0d3..b8fa0d3 100644
--- a/tests/blit.qbt
+++ b/tests/blit/blit.qbt
diff --git a/tests/blit/source.mk b/tests/blit/source.mk
new file mode 100644
index 0000000..6bc4045
--- /dev/null
+++ b/tests/blit/source.mk
@@ -0,0 +1 @@
+SIMPLE_XFAIL += blit,'unimplemented insn: BLIT'
diff --git a/tests/empty.qbt b/tests/empty/empty.qbt
index 9c63342..9c63342 100644
--- a/tests/empty.qbt
+++ b/tests/empty/empty.qbt
diff --git a/tests/empty/source.mk b/tests/empty/source.mk
new file mode 100644
index 0000000..ee6c598
--- /dev/null
+++ b/tests/empty/source.mk
@@ -0,0 +1 @@
+SIMPLE += empty
diff --git a/tests/hello_world.qbt b/tests/hello_world/hello_world.qbt
index 8419208..8419208 100644
--- a/tests/hello_world.qbt
+++ b/tests/hello_world/hello_world.qbt
diff --git a/tests/hello_world/source.mk b/tests/hello_world/source.mk
new file mode 100644
index 0000000..be3b9ae
--- /dev/null
+++ b/tests/hello_world/source.mk
@@ -0,0 +1 @@
+SIMPLE += hello_world
diff --git a/tests/save.qbt b/tests/save/save.qbt
index 71b7bb6..725d10b 100644
--- a/tests/save.qbt
+++ b/tests/save/save.qbt
@@ -3,9 +3,9 @@ main()
i27 r0 = 20;
i27 r1 = 30;
i27 r2 = 50;
- &_putchar (i9 'H') => (r4);
+ &_putchar ('H') => (r4);
i27 r0 = r0 + r1;
i27 r0 = r0 + r2;
- &_putchar (i9 'e') => (r5);
+ &_putchar ('e') => (r5);
=> (r0);
}
diff --git a/tests/save/source.mk b/tests/save/source.mk
new file mode 100644
index 0000000..60a2498
--- /dev/null
+++ b/tests/save/source.mk
@@ -0,0 +1 @@
+SIMPLE += save
diff --git a/tests/scripts/gen-simple b/tests/scripts/gen-simple
new file mode 100755
index 0000000..b8ddd9f
--- /dev/null
+++ b/tests/scripts/gen-simple
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+mkdir -p $(for d in "${@}"; do echo "$d"; done | uniq | sed "s|^|reports/|")
+
+for s in "${@}"
+do
+ echo ".PHONY: $s" >> tests.mk
+ echo "$s:" >> tests.mk
+ echo " @../qbt $s/$s.qbt > reports/$s/log 2>&1 \\" >> tests.mk
+ echo " && echo OK > reports/$s/OK \\" >> tests.mk
+ echo " || echo ERR > reports/$s/OK" >> tests.mk
+done
+
+echo "TESTS += " "${@}" >> tests.mk
diff --git a/tests/scripts/gen-simple-xfail b/tests/scripts/gen-simple-xfail
new file mode 100755
index 0000000..41c272a
--- /dev/null
+++ b/tests/scripts/gen-simple-xfail
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+mkdir -p $(for d in "${@}"; do echo "$d"; done \
+ | sed "s|,.*||" | uniq | sed "s|^|reports/|")
+
+for s in "${@}"
+do
+ NAME=${s%%,*}
+ EMSG=${s#${NAME},}
+ echo ".PHONY: $NAME" >> tests.mk
+ echo "$NAME:" >> tests.mk
+ echo " @../qbt $NAME/$NAME.qbt > reports/$NAME/log 2>&1 \\" >> tests.mk
+ echo " && echo 'Wrong retval' > reports/$NAME/OK \\" >> tests.mk
+ echo " || :" >> tests.mk
+ echo " @grep '$EMSG' reports/$NAME/log > /dev/null; \\" >> tests.mk
+ echo " [ \$\$? -eq 0 ] \\" >> tests.mk
+ echo " && echo OK > reports/$NAME/OK \\" >> tests.mk
+ echo " || echo EMSG > reports/$NAME/OK" >> tests.mk
+done
+
+echo -n "TESTS +=" >> tests.mk
+for s in "${@}"
+do
+ NAME=${s%%,*}
+ echo -n " $NAME" >> tests.mk
+done
+
+# append newline
+echo "" >> tests.mk
diff --git a/tests/scripts/makefile b/tests/scripts/makefile
new file mode 100644
index 0000000..a85d373
--- /dev/null
+++ b/tests/scripts/makefile
@@ -0,0 +1,16 @@
+.PHONY: all
+all: check
+
+TESTS :=
+include tests.mk
+
+.PHONY: check
+check: $(TESTS)
+ @cd reports; for d in * ; do \
+ if [ ! -f "$$d/OK" ]; then \
+ echo "BROKEN: $$d" ; \
+ elif [ "$$(tail -n1 $$d/OK)" != "OK" ]; then \
+ echo "FAIL: $$d" ; \
+ fi \
+ done
+ @echo "Done."
diff --git a/tests/simple_args.qbt b/tests/simple_args/simple_args.qbt
index 5dcb3d8..5dcb3d8 100644
--- a/tests/simple_args.qbt
+++ b/tests/simple_args/simple_args.qbt
diff --git a/tests/simple_args/source.mk b/tests/simple_args/source.mk
new file mode 100644
index 0000000..9422cb3
--- /dev/null
+++ b/tests/simple_args/source.mk
@@ -0,0 +1 @@
+SIMPLE += simple_args
diff --git a/tests/simple_external_putchar.qbt b/tests/simple_external_putchar/simple_external_putchar.qbt
index b76844c..b76844c 100644
--- a/tests/simple_external_putchar.qbt
+++ b/tests/simple_external_putchar/simple_external_putchar.qbt
diff --git a/tests/simple_external_putchar/source.mk b/tests/simple_external_putchar/source.mk
new file mode 100644
index 0000000..a226f93
--- /dev/null
+++ b/tests/simple_external_putchar/source.mk
@@ -0,0 +1 @@
+SIMPLE += simple_external_putchar
diff --git a/tests/simple_loop.qbt b/tests/simple_loop/simple_loop.qbt
index 32e544f..32e544f 100644
--- a/tests/simple_loop.qbt
+++ b/tests/simple_loop/simple_loop.qbt
diff --git a/tests/simple_loop/source.mk b/tests/simple_loop/source.mk
new file mode 100644
index 0000000..4ec9398
--- /dev/null
+++ b/tests/simple_loop/source.mk
@@ -0,0 +1 @@
+SIMPLE += simple_loop
diff --git a/tests/unreachable/source.mk b/tests/unreachable/source.mk
new file mode 100644
index 0000000..a647456
--- /dev/null
+++ b/tests/unreachable/source.mk
@@ -0,0 +1 @@
+SIMPLE += unreachable
diff --git a/tests/unreachable.qbt b/tests/unreachable/unreachable.qbt
index b97f9e1..b97f9e1 100644
--- a/tests/unreachable.qbt
+++ b/tests/unreachable/unreachable.qbt