feat(verilog): index Verilog/SystemVerilog, resolve port bindings, signal access and build profiles - #1875
feat(verilog): index Verilog/SystemVerilog, resolve port bindings, signal access and build profiles#1875danusha2345 wants to merge 8 commits into
Conversation
…and signals Add a tree-sitter-systemverilog grammar (.v, .vh, .sv, .svh) and an extractor that records modules, packages, interfaces and modports as containers, named instances with an `instantiates` reference to the instantiated module, ports, nets and variables, parameters and `define macros, functions and tasks, `include imports, always/assign blocks and lexical/generate scopes. Signal references keep their enclosing block; bit and part selects keep their base signal. Same-line declarations get distinct node ids through the column. The extraction stamp is bumped so existing indexes ask for a re-index. Based on the extractor contributed in colbymchenry#402. Co-authored-by: FHYQ-Dong <FHYQ-Dong@users.noreply.github.com>
…erences Instantiations prefer a synthesizable module over a same-named simulation stub. Named, positional and wildcard (.*) port connections resolve to the formal port of the instantiated module and to the local signal; positional bindings follow the ANSI/non-ANSI header order, wildcard bindings require known formals and an unambiguous local signal, and explicit connections win. Member references are matched inside their own scope, package-qualified calls keep the package identity, and named-symbol flow walks `instantiates` edges so `codegraph_explore` shows the hierarchy path between two modules. Sync re-opens a wildcard or positional binding's whole fan-out when a module header changes, and replays HDL references by their qualified name instead of re-attaching by short name.
Every signal reference is tagged read, write, readwrite, control (an if / case / ternary condition) or event (an always sensitivity), and arguments passed to a known function or task take the direction of that formal. `codegraph_explore` accepts `hdlAccess` (CLI: `--hdl-access`) with one exact or qualified signal name and lists the matching access sites with their source; the wiring of the option is in the following commit.
…her scope An optional `hdl` section in codegraph.json names profiles of source files or filelists (+incdir+, +define+, nested -f/-F), include directories, defines, top modules and language mode. The active profile selects the HDL units that are indexed and masks the conditional-compilation branches it disables while preserving offsets; includes contribute macro state and are tracked as dependencies. The index records the profile fingerprint and diagnostics, `codegraph status` and `codegraph_explore` report the configured versus the indexed profile, a context change forces a full HDL re-index even on a scoped sync, and the file watcher follows filelists, included headers and explicitly selected ignored paths. A scope change that lands while a scoped sync is in flight is now rescheduled: it adds no pending file, only the full-reconcile flag, and the post-sync check used to drop it.
`codegraph hdl-semantic [query]` (and `CodeGraph.getHdlSemantics()`) runs an installed slang executable — or, with `--python`, a Python with pinned pyslang — on a snapshot of the active HDL profile and returns evaluated parameters, port widths and, for the pyslang backend, the macro origins of declarations, initializers and types. Facts carry full provenance (frontend version and hashes, profile and configuration fingerprints, top, overrides, compiler limits) and link to a source node only when the indexed file still matches. Nothing runs automatically and a compiler failure never touches the source graph. The MCP server instructions gain a Verilog/SystemVerilog section covering the hierarchy, port-connection, hdlAccess, profile and semantic queries.
…ntics # Conflicts: # src/extraction/index.ts # src/index.ts
|
Merged |
…ntics # Conflicts: # src/resolution/name-matcher.ts
…puted from `handleParam` only created the constant node, so `localparam K = (N + 1) * 2;` had no edge to `N` and impact on a width parameter stopped at the parameter itself. The value expression now goes through the same scoped signal walk the processes use: identifiers become `hdl:signal:` references FROM the parameter, callee names and package qualifiers are left out, and the resolver binds them in the parameter's lexical scope only, so a same-named parameter of another module is never the target. Idea and shape by FHYQ-Dong (comment on colbymchenry#402). Measured on two real designs, nodes unchanged: a Tang Nano 9k card reader +16 edges, pulp-platform AXI +222 edges; every sampled edge stays inside its module. Co-authored-by: FHYQ-Dong <FHYQ-Dong@users.noreply.github.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Added 8f9d7dd at @FHYQ-Dong's suggestion (#402, now closed in favour of this PR): a parameter references the parameters its value is computed from, so impact on a width/depth parameter follows the derived |
What
Verilog / SystemVerilog support, carved out of the superset draft #1845 onto current
main(58c07e8). Five commits, each compiling on its own:tree-sitter-systemverilog0.4.0 bundled as wasm.codegraph_explorefollowsinstantiatesedges for Verilog, soexplore "top uart_rx"prints the pathtop → uart_bridge → uart_rx. Based on the extractor in feat(verilog): index Verilog/SystemVerilog with module-instantiation edges #402 by @FHYQ-Dong (co-authored)..*connections link an instance's local signals to the instantiated module's formal ports; bit/part selects keep their base signal; local signal references stay in their block scope, and a sync that changes a module header re-derives its whole binding fan-out.codegraph_explorewithhdlAccess(read/write/readwrite/control/event/all; CLIexplore --hdl-access) lists where a signal is read, written, used as a condition or as a clock/reset event, including the direction of arguments passed to known functions and tasks.hdlsection incodegraph.jsonselects source files or filelists, include directories and defines; conditional-compilation branches are indexed under the active profile,statusreports configured vs indexed profile, and the watcher follows filelists and included headers.codegraph hdl-semanticruns an installed slang (or pyslang via--python) on the active profile and returns evaluated parameters, port widths and macro origins as a separate answer; it never touches the indexed graph and is never run implicitly.EXTRACTION_VERSION26 → 27: projects with Verilog files need a re-index. No kernel changes (Verilog is not kernel-routed); other languages' node ids are unchanged.Verification
tscclean; HDL suites (verilog-*,hdl-*, plusextraction,watcher,mcp-unindexed,sync-rebuild-convergence): 35 files / 287 tests pass. Full suite on Linux: nothing fails here that passes onmain(the only differences weredist/viewer-less UI tests on both sides)..v) and a 2-UART bridge; instantiation paths andhdlAccess writesites verified by hand. A TypeScript-only project shows no HDL output.hdl-semanticwas exercised earlier on the pulp-platform AXI wrapper with slang / pyslang (parameter overrides 2/4, macro-derived widths 35/36/34); the machine this PR was cut on has neither installed, so the CLI's refusal path is what ran here.Out of scope
Everything else on #1845 (call evidence, index freshness, MCP lifecycle, C/C++ macros) stays there or is superseded on
main; that draft's description lists where each piece went.