aboutsummaryrefslogtreecommitdiffstats
path: root/backends/smt2/test_cells.sh
blob: 34adb7af3c19cf3f059413628eb49bd13618d011 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash

set -ex

rm -rf test_cells
mkdir test_cells
cd test_cells

../../../yosys -p 'test_cell -muxdiv -w test all /$alu /$macc /$fa /$lcu /$lut /$shift /$shiftx'

cat > miter.tpl <<- EOT
; #model# (set-option :produce-models true)
(set-logic QF_UFBV)
%%
(declare-fun s () miter_s)
(assert (|miter_n trigger| s))
(check-sat)
; #model# (get-value ((|miter_n in_A| s) (|miter_n in_B| s) (|miter_n gold_Y| s) (|miter_n gate_Y| s) (|miter_n trigger| s)))
EOT

for x in $(set +x; ls test_*.il | sort -R); do
	x=${x%.il}
	cat > $x.ys <<- EOT
		read_ilang $x.il
		copy gold gate

		cd gate
		techmap; opt; abc;;
		cd ..

		miter -equiv -flatten -make_outputs gold gate miter
		hierarchy -check -top miter

		dump
		write_smt2 -bv -tpl miter.tpl $x.smt2
	EOT
	../../../yosys -q $x.ys
	if ! cvc4 $x.smt2 > $x.result; then
		cat $x.result
		exit 1
	fi
	if ! grep unsat $x.result; then
		echo "Proof failed! Extracting model..."
		sed -i 's/^; #model# //' $x.smt2
		cvc4 $x.smt2
		exit 1
	fi
done

set +x
echo ""
echo "  All tests passed."
echo ""
exit 0