Files
lab-rv32i-asm-blinker/tools/card-action.sh
T

55 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
action="${1:?action is required}"
root="${STEM_REPO:-$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)}"
profile="${STEM_PROFILE:-native-amd64}"
target="${STEM_TARGET:-native}"
selector="${STEM_TASK:-task1}"
state="${STEM_STATE_DIR:-$root/.stem/instances/local}"
tasks=(task01_clock_enable task02_counter_blinker task03_pattern_rom)
resolve_task() {
local value="${1,,}" stem
for stem in "${tasks[@]}"; do
if [[ "$value" == "$stem" ]]; then
printf '%s\n' "$stem"
return
fi
done
if [[ "$value" =~ ^(task|t)?[-_]?0*([1-3])($|[-_].*) ]]; then
printf '%s\n' "${tasks[${BASH_REMATCH[2]} - 1]}"
return
fi
printf 'Unknown task selector: %s\n' "$1" >&2
exit 2
}
task="$(resolve_task "$selector")"
artifact_dir="$root/.stem/artifacts/$profile/$target/$task"
mkdir -p "$state" "$artifact_dir"
case "$profile:$target:$action" in
native-amd64:native:build)
python3 -m py_compile "$root/tests/reference_model.py"
cp -f "$root/src/tasks/$task.sv" "$artifact_dir/"
;;
native-amd64:native:test|native-amd64:native:run)
exec python3 "$root/tests/reference_model.py" "$task"
;;
hazard3-sim:hazard3-baremetal:build)
exec "$root/tests/test_rtl.sh" --build-only "$task"
;;
hazard3-sim:hazard3-baremetal:test|hazard3-sim:hazard3-baremetal:run)
exec "$root/tests/test_rtl.sh" "$task"
;;
hazard3-sim:hazard3-baremetal:debug)
exec "$root/tests/test_rtl.sh" --trace "$task"
;;
*)
printf 'Unsupported profile/target/action: %s/%s/%s\n' "$profile" "$target" "$action" >&2
exit 2
;;
esac