#!/usr/bin/env bash set -euo pipefail root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" mode=test if [[ "${1:-}" == "--build-only" || "${1:-}" == "--trace" ]]; then mode="${1#--}" shift fi task="${1:?task name is required}" case "$task" in task01_clock_enable|task02_counter_blinker|task03_pattern_rom) ;; *) printf 'Unknown RTL task: %s\n' "$task" >&2; exit 2 ;; esac state="${STEM_STATE_DIR:-$root/.stem/instances/local}" profile="${STEM_PROFILE:-hazard3-sim}" target="${STEM_TARGET:-hazard3-baremetal}" build_dir="$state/build/rtl/$task" artifact_dir="$root/.stem/artifacts/$profile/$target/$task" binary="$build_dir/sim" mkdir -p "$build_dir" "$artifact_dir" args=(--binary --timing --assert -Wall -Wno-fatal -Wno-DECLFILENAME -Wno-BLKSEQ -Wno-UNUSEDSIGNAL --top-module tb --Mdir "$build_dir/obj" -o "$binary" "$root/src/tasks/$task.sv" "$root/tests/${task}_tb.sv") if [[ "$mode" == trace ]]; then args+=(--trace) fi verilator "${args[@]}" >/dev/null cp -f "$root/src/tasks/$task.sv" "$artifact_dir/" if [[ "$mode" == build-only ]]; then printf 'BUILD %s binary=%s\n' "$task" "$binary" exit 0 fi trace_file="$artifact_dir/$task.vcd" if [[ "$mode" == trace ]]; then "$binary" "+trace=$trace_file" test -s "$trace_file" printf 'TRACE %s vcd=%s\n' "$task" "$trace_file" else "$binary" fi