Files

52 lines
1.2 KiB
Bash

#!/bin/sh
# Run the input handshake regression or measure cycles for an existing ROM image.
set -e
usage() {
printf '%s\n' "Usage: $0 in-ready | step | states <image.hex> <instruction count> [input.txt] [eprom]" >&2
exit 2
}
# Resolve image and input paths from the repository root, as in the examples.
cd "$(dirname "$0")/.."
mode=${1:-in-ready}
case "$mode" in
in-ready)
testbench=tests/tb_in_ready.v
set --
;;
step)
testbench=tests/tb_step.v
set --
;;
states)
[ "$#" -ge 3 ] && [ "$#" -le 5 ] || usage
image=$2
length=$3
input=${4:-}
testbench=tests/tb_state_mix.v
case "${5:-}" in
'') set -- ;;
eprom) set -- -DEPROM_MODE ;;
*) usage ;;
esac
;;
*) usage ;;
esac
build_dir=$(mktemp -d)
trap 'rm -r -- "$build_dir"' 0
iverilog -g2012 "$@" -o "$build_dir/tb.vvp" rtl/rot8.v "$testbench"
if [ "$mode" = states ]; then
# Use short ASCII file names for Icarus plusargs on Windows.
cp -- "$image" "$build_dir/program.hex"
set -- "+HEX=program.hex" "+LEN=$length"
if [ -n "$input" ]; then
cp -- "$input" "$build_dir/input.txt"
set -- "$@" "+INFILE=input.txt"
fi
fi
cd "$build_dir"
vvp tb.vvp "$@"