#!/usr/bin/env bash
# End-to-end LintQ pipeline: extract facts from a Qiskit script, then run the
# Souffle analyses over them. Writes diagnostics to engine/out/*.csv.
#
# Usage:
#   bash run.sh                       # lints the bundled sample_circuit.py
#   bash run.sh path/to/circuit.py    # lints an arbitrary Qiskit script
set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")"

TARGET="${1:-extractor/sample_circuit.py}"

mkdir -p extractor/facts
python3 extractor/ast_to_facts.py "$TARGET" --out extractor/facts

cd engine
mkdir -p out
souffle -F ../extractor/facts -D out lintq.dl

echo "=== LintQ warnings for $TARGET ==="
for f in out/WarnOpAfterMeas.csv out/WarnDoubleMeas.csv out/WarnGhostCompose.csv; do
  echo "--- $f ---"
  cat "$f"
done
