Skip to main content

Zuspec SystemVerilog Backend

The Zuspec SystemVerilog (SV) Backend is a code generator that transforms Zuspec hardware component models into synthesizable SystemVerilog RTL.

Features

  • Component Translation: Converts Zuspec Components to SystemVerilog modules
  • Clocked Processes: Transforms @sync decorated methods to always blocks
  • Async Processes: Converts @process methods to initial blocks with timing control
  • Parameterization: Supports parameterized component widths using const fields
  • Bundle Flattening: Automatically flattens interface bundles to port lists
  • Instance Hierarchy: Generates module instantiations with port connections
  • Export Interfaces: Creates SystemVerilog interfaces for export fields with bound tasks
  • Debug Annotations: Optional source location comments in generated code

Installation

pip install zuspec-be-sv

Quick Start

import zuspec.dataclasses as zdc
from zuspec.be.sv import SVGenerator
from pathlib import Path

@zdc.dataclass
class Counter(zdc.Component):
    clock : zdc.bit = zdc.input()
    reset : zdc.bit = zdc.input()
    count : zdc.bit32 = zdc.output()

    @zdc.sync(clock=lambda s:s.clock, reset=lambda s:s.reset)
    def _count(self):
        if self.reset:
            self.count = 0
        else:
            self.count += 1

# Generate SystemVerilog
factory = zdc.DataModelFactory()
ctxt = factory.build(Counter)

generator = SVGenerator(Path("output"))
sv_files = generator.generate(ctxt)

This generates:

module Counter(
  input logic clock,
  input logic reset,
  output logic [31:0] count
);

  always @(posedge clock or posedge reset) begin
    if (reset) begin
      count <= 0;
    end else begin
      count <= count + 1;
    end
  end

endmodule

Documentation

Full documentation is available at: https://zuspec.github.io/packages/zuspec-be-sv/docs/_build/html/

Topics covered:

Examples

Parameterized Component

@zdc.dataclass
class ConfigurableAdder(zdc.Component):
    DATA_WIDTH : int = zdc.const(default=32)
    
    a : zdc.int = zdc.input(width=lambda s: s.DATA_WIDTH)
    b : zdc.int = zdc.input(width=lambda s: s.DATA_WIDTH)
    sum : zdc.int = zdc.output(width=lambda s: s.DATA_WIDTH)

Generates:

module ConfigurableAdder #(
  parameter int DATA_WIDTH = 32
)(
  input logic [(DATA_WIDTH-1):0] a,
  input logic [(DATA_WIDTH-1):0] b,
  output logic [(DATA_WIDTH-1):0] sum
);
  // ...
endmodule

Hierarchical System

@zdc.dataclass
class System(zdc.Component):
    clock : zdc.bit = zdc.input()
    
    counter1 : Counter = zdc.inst()
    counter2 : Counter = zdc.inst()
    
    def __bind__(self):
        return {
            self.counter1.clock : self.clock,
            self.counter2.clock : self.clock
        }

Generates module with instantiated subcomponents and connections.

Export Interface

from typing import Protocol

class SendIF(Protocol):
    async def send(self, data: int) -> int: ...

@zdc.dataclass
class Transactor(zdc.Component):
    send_if : SendIF = zdc.export()
    
    def __bind__(self):
        return {
            self.send_if.send : self._send_impl
        }
    
    async def _send_impl(self, data: int) -> int:
        self.data_out = data
        await self.posedge(self.clock)
        return data * 2

Generates SystemVerilog interface with task.

Requirements

  • Python >= 3.7
  • zuspec-dataclasses >= 0.0.1

Development

Clone and install in development mode:

git clone https://github.com/zuspec/zuspec-be-sv
cd zuspec-be-sv
pip install -e ".[dev]"

Run tests:

pytest

Build documentation:

cd docs
make html

License

Apache-2.0

Contributing

Contributions are welcome! Please see Contributing Guide for details.

Related Projects

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

zuspec_be_sv-0.1.0-py3-none-any.whl (85.8 kB view details)

Uploaded Python 3

File details

Details for the file zuspec_be_sv-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zuspec_be_sv-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 85.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for zuspec_be_sv-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c796364b7f441780bd3f463cf9eed6ac788774ce7c81b79dfc006f860a3a88f8
MD5 bb8e10804970ff0ee1a049d059b35627
BLAKE2b-256 958e4ddd32b217748fe3ed5d9c831a704e4e8322b91ebed48df870b8c1c53a34

See more details on using hashes here.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page