Skip to content

Add support for unparseable/encrypted files#309

Open
micprog wants to merge 2 commits into
fischeti/filter-scriptfrom
slang-encrypted
Open

Add support for unparseable/encrypted files#309
micprog wants to merge 2 commits into
fischeti/filter-scriptfrom
slang-encrypted

Conversation

@micprog
Copy link
Copy Markdown
Member

@micprog micprog commented Jun 2, 2026

No description provided.

micprog and others added 2 commits June 2, 2026 01:17
IEEE-1735 encrypted IP makes slang trip at the surrounding `endmodule`
even though the lexer skips the protect envelope itself. Previously,
that error in any one file aborted the entire `bender script --top X`
invocation because session.cpp threw on the first per-file error.

bender-slang now collects per-tree pass/fail status instead of throwing
on parse errors. System-load failures (file unreadable) are still
fatal — only parse errors are tolerated. Diagnostics are still surfaced
to stderr per file so users can see exactly what slang complained
about.

A new failed_tree_indices() bridge function lets the Rust side learn
which trees had errors. apply_slang_filters builds a force_kept_paths
set from those indices and unions it with the reachability-derived
kept_paths during file filtering, then prints a clear warning per
file: "slang reported parse errors in <path>; preserving in script
output regardless of reachability".

The tolerance is on by default with loud per-file warnings so real
syntax bugs still get noticed; users wanting strict behavior can read
stderr and act on it. The dangling-reference case (parent instantiates
a module slang can't see) is already handled in analysis.cpp's DFS,
which silently skips refs missing from the symbol table.

Fixture: tests/pickle has a new `encrypted` target with three files —
encrypted_ip.sv (realistic IEEE-1735 envelope around a module body),
encrypted_user.sv (instantiates encrypted_ip via a dangling ref), and
encrypted_top.sv. The test confirms all three survive `--top
encrypted_top` even though slang fails to parse encrypted_ip.sv.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…iles

Three follow-ups on the parse-error tolerance added in the previous
commit:

* script now prints a single summary warning at end of filtering:
  "warning: slang reported parse errors in N file(s); kept in script
  output: a.sv, b.sv" — instead of one stderr line per file, which got
  noisy on big designs. The diagnostic for each file still comes
  through (slang emits those itself).

* script gains `--drop-unparseable`. Default behavior (keep) is
  unchanged. With the flag set, files slang couldn't parse are dropped
  from the output regardless of reachability; the summary warning's
  verb switches from "kept" to "dropped". Useful when the user knows
  the failures are real bugs in their RTL and wants the script to
  reflect that.

* `--source-annotations` now emits `// UNPARSEABLE: slang reported
  parse errors` above each kept-but-failed file in the script, so a
  reader can spot them in the file list itself. Reuses the existing
  FileEntry.comment plumbing via a fresh `unparseable_comment` helper
  in emit_template.

* pickle refuses on slang parse errors instead of silently emitting
  corrupt output: the slang printer reconstructs from the (partial)
  parse tree, and for encrypted protect envelopes that meant the
  base64 data block got mangled into something no downstream decrypt
  tool would accept. Pre-tolerance pickle threw automatically; now we
  check `failed_indices()` after parsing and surface a clear error
  pointing users at `bender script --top` for the file-list-only case.

apply_slang_filters now returns the filtered groups alongside the set
of kept-unparseable paths, which the caller threads into
emit_template for the comment annotation. The retain predicate is
unified into a single closure handling both the --top axis and the
--drop-unparseable axis.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@micprog micprog requested a review from fischeti June 2, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant