Files
lucisv/tools/corpus_fetch.sh
T
lucioandClaude Fable 5 980bd9c5d4 Add corpus-check: ecosystem check against 820 files of real RTL
tools/corpus_fetch.sh pins picorv32, ibex, common_cells and two
OpenTitan IPs by exact SHA; tools/corpus_check.sh buckets per-file
outcomes (parse/format/verification-error/crash) into a summary,
a deduped error histogram, and a TSV diffable between commits.

Baseline at 9f1a6cf: 35.2% parsed, zero crashes, zero corruption;
24 safety-net refusals reducing to four formatter bugs (event-list
comma -> or, dropped comments in port lists and always blocks,
merged header imports, dropped empty #()) — queued as the next
bug-fix round with corpus files as acceptance inputs.

The corpus proved the README roadmap order wrong: macro invocation
at item/statement position blocks ~60% of RTL parse errors (it
wasn't listed), interfaces (was #1) blocked one file. README
roadmap re-ordered by measured impact.

Dev: Opus agent; QA: Sonnet agent (all claims pass, re-run
byte-identical; fixed a TSV tab-splitting bug); review in
docs/features/corpus-check/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-19 00:46:32 -07:00

78 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Clone pinned revisions of permissively-licensed open-source RTL into a
# local corpus directory, for tools/corpus_check.sh to run vfmt over.
#
# Every repo is pinned to an exact commit and fetched shallow (--depth 1);
# nothing here ever tracks a moving branch, so corpus numbers recorded in
# docs/features/corpus-check/README.md stay reproducible.
#
# Usage: tools/corpus_fetch.sh [corpus-dir] (default: ./corpus)
set -eu
corpus_dir=${1:-corpus}
# name|url|commit|sparse paths (space separated, empty = whole repo)
#
# Licenses: picorv32 ISC, ibex Apache-2.0, common_cells SHL-0.51,
# opentitan Apache-2.0. All permissive; nothing is redistributed by this
# repo -- corpus/ is gitignored and only ever read.
repos=$(
cat <<'EOF'
picorv32|https://github.com/YosysHQ/picorv32.git|a473fc8fca393771d83b0ffcf0b14db3393339d8|
ibex|https://github.com/lowRISC/ibex.git|7b5df75a041affe56e8c235260f98a09b3319008|
common_cells|https://github.com/pulp-platform/common_cells.git|1281545696eb3fcba50ec5b4275993476a3c710e|
opentitan|https://github.com/lowRISC/opentitan.git|bc1910f4505346dbef000155530fd5a68c60e889|hw/ip/uart hw/ip/gpio
EOF
)
fetch_one() {
name=$1
url=$2
commit=$3
sparse=$4
dest="$corpus_dir/$name"
stamp="$dest/.vfmt-corpus-rev"
if [ -f "$stamp" ] && [ "$(cat "$stamp")" = "$commit" ]; then
echo "== $name: already at $commit, skipping"
return 0
fi
echo "== $name: fetching $commit from $url"
rm -rf "$dest"
mkdir -p "$dest"
git -C "$dest" init --quiet
git -C "$dest" remote add origin "$url"
if [ -n "$sparse" ]; then
# Big repo (opentitan): blobless partial clone + sparse checkout of
# just the subdirectories we care about.
git -C "$dest" config core.sparseCheckout true
git -C "$dest" sparse-checkout init --cone
# shellcheck disable=SC2086 # $sparse is an intentional path list
git -C "$dest" sparse-checkout set $sparse
git -C "$dest" fetch --quiet --depth 1 --filter=blob:none origin "$commit"
else
git -C "$dest" fetch --quiet --depth 1 origin "$commit"
fi
git -C "$dest" checkout --quiet FETCH_HEAD
echo "$commit" >"$stamp"
}
mkdir -p "$corpus_dir"
echo "$repos" | while IFS='|' read -r name url commit sparse; do
[ -n "$name" ] || continue
fetch_one "$name" "$url" "$commit" "$sparse"
done
echo
echo "corpus in $corpus_dir:"
for d in "$corpus_dir"/*/; do
[ -d "$d" ] || continue
n=$(find "$d" -type f \( -name '*.v' -o -name '*.sv' \) -not -path '*/.git/*' | wc -l | tr -d ' ')
printf ' %-16s %5s .v/.sv files\n' "$(basename "$d")" "$n"
done