10 frontend
="verilog -noblackbox"
11 backend_opts
="-noattr -noexpr -siminit"
18 toolsdir
="$(cd $(dirname $0); pwd)"
19 warn_iverilog_git
=false
20 # The following are used in verilog to firrtl regression tests.
21 # Typically these will be passed as environment variables:
22 #EXTRA_FLAGS="--firrtl2verilog 'java -cp /.../firrtl/utils/bin/firrtl.jar firrtl.Driver'"
23 # The tests are skipped if firrtl2verilog is the empty string (the default).
26 abcprog
="$toolsdir/../../yosys-abc"
28 if [ ! -f $toolsdir/cmp_tbdata
-o $toolsdir/cmp_tbdata.c
-nt $toolsdir/cmp_tbdata
]; then
29 ( set -ex; ${CC:-gcc} -Wall -o $toolsdir/cmp_tbdata
$toolsdir/cmp_tbdata.c
; ) ||
exit 1
32 while getopts xmGl
:wkjvref
:s
:p
:n
:S
:I
:A
:-: opt
; do
39 warn_iverilog_git
=true
;;
41 libs
="$libs $(cd $(dirname $OPTARG); pwd)/$(basename $OPTARG)";;
51 backend_opts
="$backend_opts -norename" ;;
53 backend_opts
="$( echo " $backend_opts " | sed 's, -noexpr , ,; s,^ ,,; s, $,,;'; )" ;;
57 [[ "$OPTARG" == /* ]] || OPTARG
="$PWD/$OPTARG"
58 scriptfiles
="$scriptfiles $OPTARG" ;;
60 scriptopt
="$OPTARG" ;;
62 autotb_opts
="$autotb_opts -n $OPTARG" ;;
64 autotb_opts
="$autotb_opts -seed $OPTARG" ;;
66 include_opts
="$include_opts -I $OPTARG"
67 xinclude_opts
="$xinclude_opts -i $OPTARG"
68 minclude_opts
="$minclude_opts +incdir+$OPTARG" ;;
75 OPTIND
=$
(( $OPTIND + 1 ))
78 firrtl2verilog
="${!OPTIND}"
79 OPTIND
=$
(( $OPTIND + 1 ))
82 if [ "$OPTERR" == 1 ] && [ "${optspec:0:1}" != ":" ]; then
83 echo "Unknown option --${OPTARG}" >&2
88 echo "Usage: $0 [-x|-m] [-G] [-w] [-k] [-j] [-v] [-r] [-e] [-l libs] [-f frontend] [-s script] [-p cmdstring] [-n iters] [-S seed] [-I incdir] [--xfirrtl FIRRTL test exclude file] [--firrtl2verilog command to generate verilog from firrtl] verilog-files\n" >&2
94 exe
="$1"; output
="$2"; shift 2
95 if [ "${2##*.}" == "sv" ]; then
101 if $use_modelsim; then
102 altver
=$
( ls -v /opt
/altera
/ |
grep '^[0-9]' |
tail -n1; )
103 /opt
/altera
/$altver/modelsim_ase
/bin
/vlib work
104 /opt
/altera
/$altver/modelsim_ase
/bin
/vlog
$minclude_opts +define
+outfile
=\"$output\" "$@"
105 /opt
/altera
/$altver/modelsim_ase
/bin
/vsim
-c -do 'run -all; exit;' testbench
107 xilver
=$
( ls -v /opt
/Xilinx
/Vivado
/ |
grep '^[0-9]' |
tail -n1; )
108 /opt
/Xilinx
/Vivado
/$xilver/bin
/xvlog
$xinclude_opts -d outfile
=\"$output\" "$@"
109 /opt
/Xilinx
/Vivado
/$xilver/bin
/xelab
-R work.testbench
111 iverilog
$language_gen $include_opts -Doutfile=\"$output\" -s testbench
-o "$exe" "$@"
116 shift $
((OPTIND
- 1))
122 if [[ "$ext" != "v" ]] && [[ "$ext" != "sv" ]] && [[ "$ext" != "aag" ]] && [[ "$ext" != "aig" ]]; then
123 echo "Invalid argument: $fn" >&2
126 [[ "$bn" == *_tb
]] && continue
129 status_prefix
="Test: $bn "
135 if [ "$ext" == sv
]; then
136 frontend
="$frontend -sv"
139 rm -f ${bn}.
{err
,log
,skip
}
150 if [[ "$ext" == "v" ]]; then
151 egrep -v '^\s*`timescale' ..
/$fn > ${bn}_ref.
${ext}
152 elif [[ "$ext" == "aig" ]] ||
[[ "$ext" == "aag" ]]; then
153 $abcprog -c "read_aiger ../${fn}; write ${bn}_ref.${refext}"
156 cp ..
/${fn} ${bn}_ref.${refext}
159 if [ ! -f ..
/${bn}_tb.v
]; then
160 "$toolsdir"/..
/..
/yosys
-f "$frontend $include_opts -D_AUTOTB" -b "test_autotb $autotb_opts" -o ${bn}_tb.v ${bn}_ref.${refext}
162 cp ..
/${bn}_tb.v
${bn}_tb.v
164 if $genvcd; then sed -i 's,// \$dump,$dump,g' ${bn}_tb.v
; fi
165 compile_and_run
${bn}_tb_ref ${bn}_out_ref ${bn}_tb.v ${bn}_ref.${refext} $libs \
166 "$toolsdir"/..
/..
/techlibs
/common
/simlib.v \
167 "$toolsdir"/..
/..
/techlibs
/common
/simcells.v
168 if $genvcd; then mv testbench.vcd
${bn}_ref.vcd
; fi
172 "$toolsdir"/..
/..
/yosys
-b "verilog $backend_opts" -o ${bn}_syn
${test_count}.v
"$@"
173 compile_and_run
${bn}_tb_syn${test_count} ${bn}_out_syn${test_count} \
174 ${bn}_tb.v ${bn}_syn${test_count}.v
$libs \
175 "$toolsdir"/..
/..
/techlibs
/common
/simlib.v \
176 "$toolsdir"/..
/..
/techlibs
/common
/simcells.v
177 if $genvcd; then mv testbench.vcd
${bn}_syn
${test_count}.vcd
; fi
178 $toolsdir/cmp_tbdata
${bn}_out_ref ${bn}_out_syn${test_count}
179 test_count
=$
(( test_count
+ 1 ))
182 if [ "$frontend" = "verific" -o "$frontend" = "verific_gates" ] && grep -q VERIFIC-SKIP
${bn}_ref.
${refext}; then
187 if [ -n "$scriptfiles" ]; then
188 test_passes
-f "$frontend $include_opts" ${bn}_ref.
${refext} $scriptfiles
189 elif [ -n "$scriptopt" ]; then
190 test_passes
-f "$frontend $include_opts" -p "$scriptopt" ${bn}_ref.
${refext}
191 elif [ "$frontend" = "verific" ]; then
192 test_passes
-p "verific -vlog2k ${bn}_ref.${refext}; verific -import -all; opt; memory;;"
193 elif [ "$frontend" = "verific_gates" ]; then
194 test_passes
-p "verific -vlog2k ${bn}_ref.${refext}; verific -import -gates -all; opt; memory;;"
196 test_passes
-f "$frontend $include_opts" -p "hierarchy; proc; opt; memory; opt; fsm; opt -full -fine" ${bn}_ref.
${refext}
197 test_passes
-f "$frontend $include_opts" -p "hierarchy; synth -run coarse; techmap; opt; abc -dff" ${bn}_ref.
${refext}
198 if [ -n "$firrtl2verilog" ]; then
199 if test -z "$xfirrtl" ||
! grep "$fn" "$xfirrtl" ; then
200 "$toolsdir"/..
/..
/yosys
-b "firrtl" -o ${bn}_ref.fir -f "$frontend $include_opts" -p "prep -nordff; proc; opt; memory; opt; fsm; opt -full -fine; pmuxtree" ${bn}_ref.${refext}
201 $firrtl2verilog -i ${bn}_ref.fir
-o ${bn}_ref.fir.v
202 test_passes
-f "$frontend $include_opts" -p "hierarchy; proc; opt; memory; opt; fsm; opt -full -fine" ${bn}_ref.fir.v
211 echo "Output written to console." > ${bn}.err
214 ( set -ex; body
; ) > ${bn}.err
2>&1
218 if [ -f ${bn}.out
/${bn}_ref.fir
]; then
219 did_firrtl
="+FIRRTL "
221 if [ -f ${bn}.log
]; then
222 mv ${bn}.err
${bn}.log
223 echo "${status_prefix}${did_firrtl}-> ok"
224 elif [ -f ${bn}.skip
]; then
225 mv ${bn}.err
${bn}.skip
226 echo "${status_prefix}-> skip"
228 echo "${status_prefix}${did_firrtl}-> ERROR!"
229 if $warn_iverilog_git; then
230 echo "Note: Make sure that 'iverilog' is an up-to-date git checkout of Icarus Verilog."
232 $keeprunning ||
exit 1