SystemVerilog packed struct/enum type definitions to JSON/HTML refbook generator
Project description
sv-ref
SystemVerilog packed struct/enum type definitions to JSON/HTML refbook generator.
Parses SystemVerilog source using pyslang and outputs bit-level field information for waveform debugging. The generated HTML viewer lets you paste hex values and instantly decode them into named struct fields and enum values.
Installation
Requires Python 3.10+.
# Clone and install
git clone https://github.com/HTsulfuric/sv-ref.git
cd sv-ref
uv sync
Usage
Generate
sv-ref generate <files...> [options]
| Option | Description |
|---|---|
files |
One or more SystemVerilog source files (supports glob patterns) |
-I, --include-dir |
Include search paths for `include directives |
-o, --output-dir |
Output directory (default: .) |
-f, --filelist |
Filelist (.f) files to parse (repeatable) |
--json-only |
Only generate JSON output (skip HTML) |
--html-only |
Only generate HTML output (skip JSON) |
--version |
Show version and exit |
Decode
Decode a hex value in the terminal without opening a browser:
sv-ref decode <refbook.json> <type_name> <hex_value>
Example:
$ sv-ref decode refbook.json packet_t ABCD
packet_t [16 bits] = 0xABCD
------------------------------------------------------------
Name Bits Hex Decoded
------------------------------------------------------------
header [15:8] 0xAB 171
status [7:6] 0x02 ERR
payload [5:0] 0x0D 13
Filelist Support
Use .f files to specify source files and include directories.
Relative paths are resolved from the current working directory (standard EDA convention).
# sources.f
rtl/types.sv
rtl/pkg.sv
# Include search paths (for `include directives)
+incdir+rtl/includes
+incdir+lib/common
sv-ref generate -f sources.f -o out/
Example
Given a SystemVerilog file types.sv:
package test_pkg;
typedef enum logic [1:0] { IDLE=0, BUSY=1, ERR=2 } state_e;
typedef struct packed {
logic [7:0] header;
state_e status;
logic [5:0] payload;
} packet_t;
endpackage
Run:
sv-ref generate types.sv -o out/
This produces two files in out/:
- refbook.json -- machine-readable type data with bit widths and offsets
- index.html -- self-contained HTML viewer with hex decoder
JSON Output
The generated refbook.json contains all parsed types with field-level detail:
{
"meta": {
"version": "0.1.4",
"generated_at": "2026-02-07T00:00:00+00:00",
"source_files": ["types.sv"]
},
"types": [
{
"name": "packet_t",
"kind": "struct",
"total_width": 16,
"package": "test_pkg",
"fields": [
{
"name": "header",
"width": 8,
"offset": 8,
"field_type": { "name": "logic[7:0]", "kind": null, "signed": false }
},
{
"name": "status",
"width": 2,
"offset": 6,
"field_type": { "name": "state_e", "kind": "enum", "signed": false },
"enum_members": [
{ "name": "IDLE", "value": 0 },
{ "name": "BUSY", "value": 1 },
{ "name": "ERR", "value": 2 }
]
},
{
"name": "payload",
"width": 6,
"offset": 0,
"field_type": { "name": "logic[5:0]", "kind": null, "signed": false }
}
]
}
]
}
HTML Viewer
The generated index.html is a self-contained single-page app (no external dependencies).
Open it in any browser to:
- Browse all parsed types in a sidebar with package grouping
- Search types by name or package (
/to focus) - Paste a hex value to decode it into individual struct fields
- See enum member names resolved automatically
- View nested struct fields recursively
- Click any hex or decoded value to copy to clipboard
- Share decoded state via URL hash (
#type=packet_t&hex=ABCD) - Toggle light/dark theme (persisted to localStorage)
Keyboard Shortcuts
| Key | Action |
|---|---|
/ |
Focus search input |
Escape |
Clear search, blur input |
| Arrow Up/Down | Navigate type list |
Enter |
Focus hex input for selected type |
Supported Types
- Packed structs (
typedef struct packed) - Enums (
typedef enum) - Nested packed structs
- Signed/unsigned fields
- Parameterized types (resolved at elaboration)
- Multiple packages per file
- Module-scoped types (typedefs inside
moduleblocks) - Wide types (>53 bits) via BigInt
Types can be defined inside package or module blocks. Module-scoped types
use the module definition name as their package/group name in the output.
Development
# Run tests
uv run pytest tests/ -v
# Lint
uv run ruff check sv_ref/ tests/
# Format
uv run ruff format sv_ref/ tests/
# Generate demo output
make demo
License
MIT
Project details
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 sv_ref-0.1.5.tar.gz.
File metadata
- Download URL: sv_ref-0.1.5.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78ee1bc9febbe6649bfd2aae08f00c4f9e17d6d192566f19322edabf9155c2c4
|
|
| MD5 |
8186559d256fc0d94f7db3a3fcbeaece
|
|
| BLAKE2b-256 |
0f8c95b2e2c8b702e3854e8586ebfc2509ba86ef554a042468c6cf926318fde7
|
File details
Details for the file sv_ref-0.1.5-py3-none-any.whl.
File metadata
- Download URL: sv_ref-0.1.5-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c24a4852de4ad19d9cbc254bc576449fd6f796edd119fca968bf3cad5695dcfa
|
|
| MD5 |
eba474aa988fd0280c10279b674e8c23
|
|
| BLAKE2b-256 |
8ee2d42bf17dba52949989f007ea8b68e6f268ccb6ed3ab6d473c549a58523b7
|