drop imul rewriting
[qbe.git] / tools / abifuzz.sh
blobadd56ebb37e479b189c7ec833cbd976e7f24ee8e
1 #!/bin/sh
3 OCAMLC=${OCAMLC:-/usr/bin/ocamlc}
4 DIR=`cd $(dirname "$0"); pwd`
5 QBE=$DIR/../qbe
7 failure() {
8 echo "Failure at stage:" $1 >&2
9 exit 1
12 cleanup() {
13 rm -fr $TMP
16 init() {
17 cp $DIR/callgen.ml $TMP
18 pushd $TMP > /dev/null
20 cat > Makefile << EOM
22 .PHONY: test
23 test: caller.o callee.o
24 c99 -o \$@ caller.o callee.o
25 %.o: %.c
26 c99 -c -o \$@ \$<
27 %.o: %.ssa
28 $QBE -o \$*.s \$<
29 c99 -c -o \$@ \$*.s
31 EOM
33 if ! $OCAMLC callgen.ml -o callgen
34 then
35 popd > /dev/null
36 cleanup
37 failure "abifuzz compilation"
39 popd > /dev/null
42 once() {
43 if test -z "$3"
44 then
45 $TMP/callgen $TMP $1 $2
46 else
47 $TMP/callgen -s $3 $TMP $1 $2
49 make -C $TMP test > /dev/null || failure "building"
50 $TMP/test || failure "runtime"
53 usage() {
54 echo "usage: abitest.sh [-callssa] [-callc] [-s SEED] [-n ITERATIONS]" >&2
55 exit 1
58 N=1
59 CALLER=c
60 CALLEE=ssa
62 while test -n "$1"
64 case "$1" in
65 "-callssa")
66 CALLER=c
67 CALLEE=ssa
69 "-callc")
70 CALLER=ssa
71 CALLEE=c
73 "-s")
74 test -n "$2" || usage
75 shift
76 SEED="$1"
78 "-n")
79 test -n "$2" || usage
80 shift
81 N="$1"
84 usage
86 esac
87 shift
88 done
90 TMP=`mktemp -d abifuzz.XXXXXX`
92 init
94 if test -n "$S"
95 then
96 once $CALLER $CALLEE $SEED
97 else
98 for n in `seq $N`
100 once $CALLER $CALLEE
101 echo "$n" | grep "00$"
102 done
105 echo "All done."
107 cleanup