Knowledge graph extractor for SystemVerilog, Verilog, and VHDL
Project description
hdl-kgraph
A knowledge graph for your HDL design. hdl-kgraph parses SystemVerilog, Verilog, and VHDL sources and builds a queryable graph of modules, entities, instances, ports, parameters, signals, classes, packages, and the relationships between them — design hierarchy, port connectivity, package imports, class inheritance, clock domains, and more.
Status: alpha (v0.2). SystemVerilog/Verilog structural extraction, the pass-2 linker, SQLite persistence, the
build/status/query/treeCLI, and real-world inputs — the SV preprocessor,.ffilelists, include dirs, andhdl-kgraph.tomlconfig — are in. VHDL lands in M3. See ROADMAP.md.
Why
HDL codebases are graphs — hierarchy, connectivity, clock domains — but the tools that understand them are locked inside simulators and synthesis flows. hdl-kgraph extracts that structure into a local-first SQLite database you can query from the CLI, scripts, or (later) AI assistants via MCP. The architecture follows code-review-graph, adapted for hardware.
Quickstart
pip install hdl-kgraph
hdl-kgraph build ./rtl # parse sources -> ./rtl/.hdl-kgraph/graph.db
hdl-kgraph build -f sim/tb.f # drive the build from a vendor-style filelist
hdl-kgraph build -D SYNTHESIS -D WIDTH=8 -I include # defines + incdirs
hdl-kgraph status # files, parse errors, node/edge counts
hdl-kgraph tree soc_top # print the design hierarchy from a top module
hdl-kgraph query instances-of fifo
hdl-kgraph query unresolved # what couldn't be resolved (vendor IP, macros)
build accepts --exclude GLOB (repeatable) and --max-file-size KB to keep
generated netlists and vendored IP out of the graph. Files with syntax errors
still yield partial results; status reports the parse-error count.
Unresolved instance targets render as [?] in tree and ambiguous matches as
[~0.6] — see the confidence convention in ROADMAP.md.
Filelists support +incdir+/+define+, nested -f, -y/-v library
dirs, and $VAR expansion. When no defines are given at all, conditionals
on undefined names emit both branches: the side a define-less compile
would select at full confidence, the alternative at 0.6. Repeatable inputs
can also live in an hdl-kgraph.toml at the build root (CLI flags win):
[build]
filelists = ["sim/tb.f"]
defines = ["SYNTHESIS", "WIDTH=8"]
incdirs = ["include"]
exclude = ["vendor/*"]
Coming next:
hdl-kgraph impact rtl/uart_tx.sv # what does my change affect? (M4)
hdl-kgraph visualize # interactive HTML graph (M5)
hdl-kgraph serve --mcp # MCP server for AI assistants (M6)
What gets extracted
- Design units: modules, interfaces/modports, packages, programs, checkers, UDPs; VHDL entities, architectures, packages, configurations
- Structure: instances with port connections and parameter overrides,
generate blocks,
include/definerelationships, filelists - Verification: SV classes (UVM hierarchies via inheritance chains), constraints, covergroups, assertions/properties/sequences, clocking blocks
- Dataflow (M5): signal drivers/readers, clock and reset trees, CDC-suspect crossings
Every cross-file edge carries a confidence score (resolved → heuristic), so the graph is honest about what was proven syntactically vs inferred by name matching. The full schema is documented in ROADMAP.md.
Roadmap at a glance
| Milestone | Theme |
|---|---|
| M1 (v0.1) | SystemVerilog/Verilog structural graph + CLI |
| M2 (v0.2) | Preprocessor, .f filelists, includes |
| M3 (v0.3) | VHDL + mixed-language linking |
| M4 (v0.4) | Incremental updates, watch mode, impact analysis |
| M5 (v0.5) | Clock/reset/CDC analyses, lint checks, visualization |
| M6 (v0.6) | MCP server for AI assistants |
| M7 (v0.7) | Semantic enrichment (pyslang, GHDL) |
| M8 (v1.0) | C/C++/Python boundary (DPI-C, cocotb), stable API |
| M9 (v1.x) | Chisel/FIRRTL, Amaranth, SpinalHDL |
| M10 (v1.x) | Tcl/SDC/UPF constraints, Perl scripting, SLN portable stimulus |
Details and acceptance criteria: ROADMAP.md.
Development
git clone https://github.com/chuanseng-ng/hdl-kgraph
cd hdl-kgraph
pip install -e .[dev]
ruff check . && ruff format --check . && mypy && pytest
See CONTRIBUTING.md. The single most useful contribution right now: the smallest HDL file that breaks extraction.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hdl_kgraph-0.2.0.tar.gz.
File metadata
- Download URL: hdl_kgraph-0.2.0.tar.gz
- Upload date:
- Size: 73.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d414a266f0169289441a4582a16875d2adcfab7f4fd8c23bdeb676f00a9d89b5
|
|
| MD5 |
86d4163d8760af83ac426feb2e3aff33
|
|
| BLAKE2b-256 |
82a4712124e7a1459900d21a5e467d73149e3568c1a4f8fd3a1994973bfe9c3a
|
Provenance
The following attestation bundles were made for hdl_kgraph-0.2.0.tar.gz:
Publisher:
release.yml on chuanseng-ng/hdl-kgraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hdl_kgraph-0.2.0.tar.gz -
Subject digest:
d414a266f0169289441a4582a16875d2adcfab7f4fd8c23bdeb676f00a9d89b5 - Sigstore transparency entry: 1789902507
- Sigstore integration time:
-
Permalink:
chuanseng-ng/hdl-kgraph@b30602ac89f5ac42bbadd2611c43600223b231ec -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/chuanseng-ng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b30602ac89f5ac42bbadd2611c43600223b231ec -
Trigger Event:
push
-
Statement type:
File details
Details for the file hdl_kgraph-0.2.0-py3-none-any.whl.
File metadata
- Download URL: hdl_kgraph-0.2.0-py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee2dfbb92eced14a984e4b5a13a347984297bba75d27b7d15595f9f95d5f5498
|
|
| MD5 |
cae1d47333e39a94a594b03b0fc70d6e
|
|
| BLAKE2b-256 |
ba446f3c59d73d6be0a40af9e803f265a37e9eeb0395fdebd12838ca3fe7e7de
|
Provenance
The following attestation bundles were made for hdl_kgraph-0.2.0-py3-none-any.whl:
Publisher:
release.yml on chuanseng-ng/hdl-kgraph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hdl_kgraph-0.2.0-py3-none-any.whl -
Subject digest:
ee2dfbb92eced14a984e4b5a13a347984297bba75d27b7d15595f9f95d5f5498 - Sigstore transparency entry: 1789902573
- Sigstore integration time:
-
Permalink:
chuanseng-ng/hdl-kgraph@b30602ac89f5ac42bbadd2611c43600223b231ec -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/chuanseng-ng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b30602ac89f5ac42bbadd2611c43600223b231ec -
Trigger Event:
push
-
Statement type: