#!/usr/bin/env bash
# ============================================================================
# Terminal-only Vivado/xsim run for the Calc1 UVM environment (no Makefile).
#
#   ./run_vivado.sh                 # default test_sanity
#   ./run_vivado.sh test_corner     # pick a test
#   TEST=test_random VERB=UVM_HIGH ./run_vivado.sh
#
# Override the tool path with VIVADO=/path/to/Vivado/2022.2
# ============================================================================
set -euo pipefail

VIVADO=${VIVADO:-/tools/Xilinx/Vivado/2022.2}
TEST=${1:-${TEST:-test_sanity}}
VERB=${VERB:-UVM_LOW}
SEED=${SEED:-random}

source "$VIVADO/settings64.sh"

echo ">> compiling DUT"
xvlog --nolog dut/*.v

echo ">> compiling UVM testbench"
xvlog --nolog --sv -L uvm \
  -i ./verif -i ./verif/Agent -i ./verif/Sequences -i ./verif/Configurations \
  ./verif/Configurations/configurations_pkg.sv \
  ./verif/Agent/calc_agent_pkg.sv \
  ./verif/Sequences/calc_seq_pkg.sv \
  ./verif/calc_test_pkg.sv \
  ./verif/calc_if.sv \
  ./verif/calc_verif_top.sv

echo ">> elaborating"
xelab --nolog -L uvm -timescale 1ns/10ps calc_verif_top -s calc_sim

echo ">> running $TEST"
xsim --nolog calc_sim -R \
  -testplusarg "UVM_TESTNAME=$TEST" \
  -testplusarg "UVM_VERBOSITY=$VERB" \
  -sv_seed "$SEED"
