Add local HLS dev setup: clangd, pragma highlighting + linting, local C-sim
This commit is contained in:
75
Practicals/hlsdev/sim.sh
Executable file
75
Practicals/hlsdev/sim.sh
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Build and run the Vitis HLS C-simulation for a practical, locally.
|
||||
#
|
||||
# This is a plain C++ compile of the testbench + DUT, which is what "Run C
|
||||
# Simulation" does on the server (minus the HLS compiler's extra checking).
|
||||
# It is the fast way to know your logic is right before spending time on the
|
||||
# remote machine.
|
||||
#
|
||||
# Usage:
|
||||
# ./sim.sh # practical-3b
|
||||
# ./sim.sh practical-4 # any other practical directory
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
practical="${1:-practical-3b}"
|
||||
|
||||
# Find the HLS component: the directory holding hls_config.cfg.
|
||||
cfg="$(find "$here/../$practical" -name hls_config.cfg -not -path '*/hls/*' 2>/dev/null | head -1)"
|
||||
if [ -z "$cfg" ]; then
|
||||
echo "error: no hls_config.cfg found under $here/../$practical" >&2
|
||||
exit 1
|
||||
fi
|
||||
proj="$(cd "$(dirname "$cfg")" && pwd)"
|
||||
|
||||
# hls_config.cfg names the sources, so we never have to guess.
|
||||
tb_name="$(grep -E '^tb\.file=' "$cfg" | head -1 | cut -d= -f2- | tr -d '\r')"
|
||||
dut_name="$(grep -E '^syn\.file=' "$cfg" | grep -E '\.(cpp|cc|cxx|c)$' | head -1 | cut -d= -f2- | tr -d '\r')"
|
||||
|
||||
if [ -z "$tb_name" ] || [ -z "$dut_name" ]; then
|
||||
echo "error: could not read tb.file / syn.file from $cfg" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prefer the real Xilinx headers; fall back to the stub so this still works
|
||||
# before ./fetch-headers.sh has been run.
|
||||
if [ -f "$here/include/ap_int.h" ]; then
|
||||
inc="$here/include"
|
||||
inc_extra="$here/include"
|
||||
else
|
||||
inc="$here/include-stub"
|
||||
inc_extra="$here/include-stub"
|
||||
echo "=============================================================="
|
||||
echo "NOTE: using the FALLBACK stub headers in hlsdev/include-stub."
|
||||
echo " They are good enough for the Game of Life practical, but"
|
||||
echo " they are NOT the real Xilinx headers. Run ./fetch-headers.sh"
|
||||
echo " for a simulation you can fully trust."
|
||||
echo "=============================================================="
|
||||
echo
|
||||
fi
|
||||
|
||||
CXX="${CXX:-clang++}"
|
||||
out="$here/build"
|
||||
mkdir -p "$out"
|
||||
|
||||
dut="$proj/$dut_name"
|
||||
tb="$proj/$tb_name"
|
||||
for f in "$dut" "$tb"; do
|
||||
[ -f "$f" ] || { echo "error: missing source $f" >&2; exit 1; }
|
||||
done
|
||||
|
||||
echo "component : $proj"
|
||||
echo "testbench : $tb_name"
|
||||
echo "dut : $dut_name"
|
||||
echo "compiling with $CXX ..."
|
||||
|
||||
"$CXX" -std=c++14 -O2 -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-label \
|
||||
-I"$inc" -I"$inc_extra" -I"$proj" \
|
||||
"$tb" "$dut" -o "$out/csim"
|
||||
|
||||
echo "running ..."
|
||||
echo "------------------------------------------------------------------"
|
||||
"$out/csim"
|
||||
echo "------------------------------------------------------------------"
|
||||
Reference in New Issue
Block a user