Skip to main content

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.11+.

# 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 directories (auto-discovers *.sv files)
-o, --output-dir Output directory (default: .)
-f, --filelist Filelist (.f) files to parse (repeatable)
-r, --recursive Recursively scan include directories
--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:

# sources.f
rtl/types.sv
rtl/pkg.sv

# Include directories
+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.0",
    "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
  • Wide types (>53 bits) via BigInt

Types must be defined inside a package block.

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

sv_ref-0.1.1.tar.gz (67.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sv_ref-0.1.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file sv_ref-0.1.1.tar.gz.

File metadata

  • Download URL: sv_ref-0.1.1.tar.gz
  • Upload date:
  • Size: 67.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sv_ref-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6c0bfbf44797db31112e5ff291c1332732dfec746a4f030c2233cb8010e06349
MD5 2a5f7304c28bacdc179aceb3af91e692
BLAKE2b-256 cc92d49195eb88538a6c6012aadbfea6028dd47636434925fdd581d49a335df1

See more details on using hashes here.

File details

Details for the file sv_ref-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sv_ref-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sv_ref-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b653e25a38df7fdb17850850f5e437842819452ff5b791cfb6e07a86a526df51
MD5 09eed4293a1d57ab91f7d9aa25954f2d
BLAKE2b-256 cf78961dc3d1843445e7a360d794c5b9d39d0ce2c8f2eb6b25307149a50f59a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page