2018-05-06 08:26:23 -05:00
|
|
|
#!/usr/bin/env bash
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
libs=""
|
|
|
|
genvcd=false
|
2014-02-03 06:00:55 -06:00
|
|
|
use_xsim=false
|
2013-11-24 08:10:43 -06:00
|
|
|
use_modelsim=false
|
2013-01-05 04:13:26 -06:00
|
|
|
verbose=false
|
|
|
|
keeprunning=false
|
2014-07-30 12:21:52 -05:00
|
|
|
makejmode=false
|
2019-04-21 04:40:20 -05:00
|
|
|
frontend="verilog -noblackbox"
|
2019-02-28 16:56:55 -06:00
|
|
|
backend_opts="-noattr -noexpr -siminit"
|
2014-07-31 20:55:51 -05:00
|
|
|
autotb_opts=""
|
2016-09-20 02:29:56 -05:00
|
|
|
include_opts=""
|
|
|
|
xinclude_opts=""
|
|
|
|
minclude_opts=""
|
2013-01-05 04:13:26 -06:00
|
|
|
scriptfiles=""
|
2014-01-02 10:51:30 -06:00
|
|
|
scriptopt=""
|
2013-01-05 04:13:26 -06:00
|
|
|
toolsdir="$(cd $(dirname $0); pwd)"
|
2014-07-16 03:03:07 -05:00
|
|
|
warn_iverilog_git=false
|
2019-02-15 13:14:17 -06:00
|
|
|
# The following are used in verilog to firrtl regression tests.
|
|
|
|
# Typically these will be passed as environment variables:
|
|
|
|
#EXTRA_FLAGS="--firrtl2verilog 'java -cp /.../firrtl/utils/bin/firrtl.jar firrtl.Driver'"
|
|
|
|
# The tests are skipped if firrtl2verilog is the empty string (the default).
|
|
|
|
firrtl2verilog=""
|
|
|
|
xfirrtl="../xfirrtl"
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
if [ ! -f $toolsdir/cmp_tbdata -o $toolsdir/cmp_tbdata.c -nt $toolsdir/cmp_tbdata ]; then
|
2016-05-20 09:58:02 -05:00
|
|
|
( set -ex; ${CC:-gcc} -Wall -o $toolsdir/cmp_tbdata $toolsdir/cmp_tbdata.c; ) || exit 1
|
2013-01-05 04:13:26 -06:00
|
|
|
fi
|
|
|
|
|
2019-02-21 11:22:29 -06:00
|
|
|
while getopts xmGl:wkjvref:s:p:n:S:I:-: opt; do
|
2013-01-05 04:13:26 -06:00
|
|
|
case "$opt" in
|
2014-02-03 06:00:55 -06:00
|
|
|
x)
|
|
|
|
use_xsim=true ;;
|
2013-11-24 08:10:43 -06:00
|
|
|
m)
|
|
|
|
use_modelsim=true ;;
|
2014-07-16 03:03:07 -05:00
|
|
|
G)
|
|
|
|
warn_iverilog_git=true ;;
|
2013-01-05 04:13:26 -06:00
|
|
|
l)
|
|
|
|
libs="$libs $(cd $(dirname $OPTARG); pwd)/$(basename $OPTARG)";;
|
|
|
|
w)
|
|
|
|
genvcd=true ;;
|
|
|
|
k)
|
|
|
|
keeprunning=true ;;
|
2014-07-30 12:21:52 -05:00
|
|
|
j)
|
|
|
|
makejmode=true ;;
|
2013-01-05 04:13:26 -06:00
|
|
|
v)
|
|
|
|
verbose=true ;;
|
|
|
|
r)
|
2014-01-02 10:51:30 -06:00
|
|
|
backend_opts="$backend_opts -norename" ;;
|
2014-08-30 11:34:07 -05:00
|
|
|
e)
|
2019-02-28 22:26:54 -06:00
|
|
|
backend_opts="$( echo " $backend_opts " | sed 's, -noexpr , ,; s,^ ,,; s, $,,;'; )" ;;
|
2014-02-15 08:40:17 -06:00
|
|
|
f)
|
|
|
|
frontend="$OPTARG" ;;
|
2013-01-05 04:13:26 -06:00
|
|
|
s)
|
|
|
|
[[ "$OPTARG" == /* ]] || OPTARG="$PWD/$OPTARG"
|
|
|
|
scriptfiles="$scriptfiles $OPTARG" ;;
|
2014-01-02 10:51:30 -06:00
|
|
|
p)
|
|
|
|
scriptopt="$OPTARG" ;;
|
2014-07-31 20:55:51 -05:00
|
|
|
n)
|
|
|
|
autotb_opts="$autotb_opts -n $OPTARG" ;;
|
2016-08-06 06:32:29 -05:00
|
|
|
S)
|
|
|
|
autotb_opts="$autotb_opts -seed $OPTARG" ;;
|
2016-09-20 02:29:56 -05:00
|
|
|
I)
|
|
|
|
include_opts="$include_opts -I $OPTARG"
|
|
|
|
xinclude_opts="$xinclude_opts -i $OPTARG"
|
|
|
|
minclude_opts="$minclude_opts +incdir+$OPTARG" ;;
|
2019-02-15 13:14:17 -06:00
|
|
|
-)
|
|
|
|
case "${OPTARG}" in
|
|
|
|
xfirrtl)
|
|
|
|
xfirrtl="${!OPTIND}"
|
|
|
|
OPTIND=$(( $OPTIND + 1 ))
|
|
|
|
;;
|
|
|
|
firrtl2verilog)
|
|
|
|
firrtl2verilog="${!OPTIND}"
|
|
|
|
OPTIND=$(( $OPTIND + 1 ))
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ "$OPTERR" == 1 ] && [ "${optspec:0:1}" != ":" ]; then
|
|
|
|
echo "Unknown option --${OPTARG}" >&2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac;;
|
2013-01-05 04:13:26 -06:00
|
|
|
*)
|
2019-02-21 11:22:29 -06:00
|
|
|
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
|
2013-01-05 04:13:26 -06:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
compile_and_run() {
|
|
|
|
exe="$1"; output="$2"; shift 2
|
2013-11-24 08:10:43 -06:00
|
|
|
if $use_modelsim; then
|
|
|
|
altver=$( ls -v /opt/altera/ | grep '^[0-9]' | tail -n1; )
|
|
|
|
/opt/altera/$altver/modelsim_ase/bin/vlib work
|
2016-09-20 02:29:56 -05:00
|
|
|
/opt/altera/$altver/modelsim_ase/bin/vlog $minclude_opts +define+outfile=\"$output\" "$@"
|
2016-05-19 03:34:38 -05:00
|
|
|
/opt/altera/$altver/modelsim_ase/bin/vsim -c -do 'run -all; exit;' testbench
|
2014-02-03 06:00:55 -06:00
|
|
|
elif $use_xsim; then
|
2016-09-20 02:29:56 -05:00
|
|
|
xilver=$( ls -v /opt/Xilinx/Vivado/ | grep '^[0-9]' | tail -n1; )
|
|
|
|
/opt/Xilinx/Vivado/$xilver/bin/xvlog $xinclude_opts -d outfile=\"$output\" "$@"
|
|
|
|
/opt/Xilinx/Vivado/$xilver/bin/xelab -R work.testbench
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
2016-09-20 02:29:56 -05:00
|
|
|
iverilog $include_opts -Doutfile=\"$output\" -s testbench -o "$exe" "$@"
|
2016-05-19 03:34:38 -05:00
|
|
|
vvp -n "$exe"
|
2013-01-05 04:13:26 -06:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
|
|
|
|
for fn
|
|
|
|
do
|
2019-02-04 18:46:24 -06:00
|
|
|
bn=${fn%.*}
|
|
|
|
ext=${fn##*.}
|
2019-02-08 14:41:59 -06:00
|
|
|
if [[ "$ext" != "v" ]] && [[ "$ext" != "aag" ]] && [[ "$ext" != "aig" ]]; then
|
2013-01-05 04:13:26 -06:00
|
|
|
echo "Invalid argument: $fn" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
[[ "$bn" == *_tb ]] && continue
|
2014-07-30 12:21:52 -05:00
|
|
|
|
|
|
|
if $makejmode; then
|
|
|
|
status_prefix="Test: $bn "
|
|
|
|
else
|
|
|
|
status_prefix=""
|
|
|
|
echo -n "Test: $bn "
|
|
|
|
fi
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2018-06-05 09:52:36 -05:00
|
|
|
rm -f ${bn}.{err,log,skip}
|
2013-01-05 04:13:26 -06:00
|
|
|
mkdir -p ${bn}.out
|
|
|
|
rm -rf ${bn}.out/*
|
|
|
|
|
|
|
|
body() {
|
|
|
|
cd ${bn}.out
|
2014-09-06 05:10:57 -05:00
|
|
|
fn=$(basename $fn)
|
|
|
|
bn=$(basename $bn)
|
|
|
|
|
2019-05-28 11:38:58 -05:00
|
|
|
rm -f ${bn}_ref.fir
|
2019-02-04 18:46:24 -06:00
|
|
|
if [[ "$ext" == "v" ]]; then
|
|
|
|
egrep -v '^\s*`timescale' ../$fn > ${bn}_ref.${ext}
|
|
|
|
else
|
2019-02-06 16:30:19 -06:00
|
|
|
"$toolsdir"/../../yosys -f "$frontend $include_opts" -b "verilog" -o ${bn}_ref.v ../${fn}
|
2019-04-21 04:40:20 -05:00
|
|
|
frontend="verilog -noblackbox"
|
2019-02-04 18:46:24 -06:00
|
|
|
fi
|
2016-07-02 06:32:20 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if [ ! -f ../${bn}_tb.v ]; then
|
2019-02-06 16:30:19 -06:00
|
|
|
"$toolsdir"/../../yosys -f "$frontend $include_opts" -b "test_autotb $autotb_opts" -o ${bn}_tb.v ${bn}_ref.v
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
|
|
|
cp ../${bn}_tb.v ${bn}_tb.v
|
|
|
|
fi
|
|
|
|
if $genvcd; then sed -i 's,// \$dump,$dump,g' ${bn}_tb.v; fi
|
2019-02-06 16:30:19 -06:00
|
|
|
compile_and_run ${bn}_tb_ref ${bn}_out_ref ${bn}_tb.v ${bn}_ref.v $libs \
|
2019-05-03 16:03:51 -05:00
|
|
|
"$toolsdir"/../../techlibs/common/simlib.v \
|
|
|
|
"$toolsdir"/../../techlibs/common/simcells.v
|
2013-01-05 04:13:26 -06:00
|
|
|
if $genvcd; then mv testbench.vcd ${bn}_ref.vcd; fi
|
|
|
|
|
|
|
|
test_count=0
|
|
|
|
test_passes() {
|
2014-03-14 05:46:13 -05:00
|
|
|
"$toolsdir"/../../yosys -b "verilog $backend_opts" -o ${bn}_syn${test_count}.v "$@"
|
2013-01-05 04:13:26 -06:00
|
|
|
compile_and_run ${bn}_tb_syn${test_count} ${bn}_out_syn${test_count} \
|
|
|
|
${bn}_tb.v ${bn}_syn${test_count}.v $libs \
|
2013-09-15 04:52:57 -05:00
|
|
|
"$toolsdir"/../../techlibs/common/simlib.v \
|
2013-11-24 13:44:00 -06:00
|
|
|
"$toolsdir"/../../techlibs/common/simcells.v
|
2013-01-05 04:13:26 -06:00
|
|
|
if $genvcd; then mv testbench.vcd ${bn}_syn${test_count}.vcd; fi
|
|
|
|
$toolsdir/cmp_tbdata ${bn}_out_ref ${bn}_out_syn${test_count}
|
|
|
|
test_count=$(( test_count + 1 ))
|
|
|
|
}
|
|
|
|
|
2016-07-02 06:32:20 -05:00
|
|
|
if [ "$frontend" = "verific" -o "$frontend" = "verific_gates" ] && grep -q VERIFIC-SKIP ${bn}_ref.v; then
|
2014-03-16 19:56:00 -05:00
|
|
|
touch ../${bn}.skip
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if [ -n "$scriptfiles" ]; then
|
2019-02-06 16:30:19 -06:00
|
|
|
test_passes -f "$frontend $include_opts" ${bn}_ref.v $scriptfiles
|
2014-01-02 10:51:30 -06:00
|
|
|
elif [ -n "$scriptopt" ]; then
|
2019-02-06 16:30:19 -06:00
|
|
|
test_passes -f "$frontend $include_opts" -p "$scriptopt" ${bn}_ref.v
|
2014-03-14 05:46:13 -05:00
|
|
|
elif [ "$frontend" = "verific" ]; then
|
2016-07-02 06:32:20 -05:00
|
|
|
test_passes -p "verific -vlog2k ${bn}_ref.v; verific -import -all; opt; memory;;"
|
2014-03-14 05:46:13 -05:00
|
|
|
elif [ "$frontend" = "verific_gates" ]; then
|
2016-07-02 06:32:20 -05:00
|
|
|
test_passes -p "verific -vlog2k ${bn}_ref.v; verific -import -gates -all; opt; memory;;"
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
2019-02-06 16:30:19 -06:00
|
|
|
test_passes -f "$frontend $include_opts" -p "hierarchy; proc; opt; memory; opt; fsm; opt -full -fine" ${bn}_ref.v
|
|
|
|
test_passes -f "$frontend $include_opts" -p "hierarchy; synth -run coarse; techmap; opt; abc -dff" ${bn}_ref.v
|
2019-02-15 13:14:17 -06:00
|
|
|
if [ -n "$firrtl2verilog" ]; then
|
|
|
|
if test -z "$xfirrtl" || ! grep "$fn" "$xfirrtl" ; then
|
|
|
|
"$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.v
|
2019-02-25 18:18:13 -06:00
|
|
|
$firrtl2verilog -i ${bn}_ref.fir -o ${bn}_ref.fir.v
|
2019-02-15 13:14:17 -06:00
|
|
|
test_passes -f "$frontend $include_opts" -p "hierarchy; proc; opt; memory; opt; fsm; opt -full -fine" ${bn}_ref.fir.v
|
|
|
|
fi
|
|
|
|
fi
|
2013-01-05 04:13:26 -06:00
|
|
|
fi
|
|
|
|
touch ../${bn}.log
|
|
|
|
}
|
|
|
|
|
|
|
|
if $verbose; then
|
|
|
|
echo ".."
|
|
|
|
echo "Output written to console." > ${bn}.err
|
|
|
|
( set -ex; body; )
|
|
|
|
else
|
|
|
|
( set -ex; body; ) > ${bn}.err 2>&1
|
|
|
|
fi
|
|
|
|
|
2019-02-15 13:14:17 -06:00
|
|
|
did_firrtl=""
|
|
|
|
if [ -f ${bn}.out/${bn}_ref.fir ]; then
|
|
|
|
did_firrtl="+FIRRTL "
|
|
|
|
fi
|
2013-01-05 04:13:26 -06:00
|
|
|
if [ -f ${bn}.log ]; then
|
|
|
|
mv ${bn}.err ${bn}.log
|
2019-02-15 13:14:17 -06:00
|
|
|
echo "${status_prefix}${did_firrtl}-> ok"
|
2014-03-16 19:56:00 -05:00
|
|
|
elif [ -f ${bn}.skip ]; then
|
|
|
|
mv ${bn}.err ${bn}.skip
|
2014-07-30 12:21:52 -05:00
|
|
|
echo "${status_prefix}-> skip"
|
2014-07-16 03:03:07 -05:00
|
|
|
else
|
2019-02-15 13:14:17 -06:00
|
|
|
echo "${status_prefix}${did_firrtl}-> ERROR!"
|
2014-07-16 03:03:07 -05:00
|
|
|
if $warn_iverilog_git; then
|
2015-08-14 15:23:01 -05:00
|
|
|
echo "Note: Make sure that 'iverilog' is an up-to-date git checkout of Icarus Verilog."
|
2014-07-16 03:03:07 -05:00
|
|
|
fi
|
|
|
|
$keeprunning || exit 1
|
|
|
|
fi
|
2013-01-05 04:13:26 -06:00
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|