#!/usr/bin/env bash
set -euo pipefail
project_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
output_dir="${1:-${TMPDIR:-/tmp}/admo-fifo-synthesis}"
mkdir -p "$output_dir"
yosys -V
for config in '1 8' '3 8' '4 8' '8 16'; do
  read -r depth width <<< "$config"
  echo "--- Generic synthesis DEPTH=$depth DATA_WIDTH=$width ---"
  yosys -Q -T -p "read_verilog -sv \"$project_dir/rtl/sync_fifo.sv\"; chparam -set DEPTH $depth -set DATA_WIDTH $width sync_fifo; hierarchy -check -top sync_fifo; synth -top sync_fifo -noabc; check -assert; stat -width; write_json \"$output_dir/fifo_${depth}_${width}.json\"" > "$output_dir/fifo_${depth}_${width}.log"
  grep -q 'Found and reported 0 problems' "$output_dir/fifo_${depth}_${width}.log"
  tail -30 "$output_dir/fifo_${depth}_${width}.log"
done
echo 'PASS four generic FIFO synthesis configurations (no device mapping or timing claim)'
