Skip to main content

A Python-based HDL design prototyping framework for circuit simulation and verification

Project description

HDLproto

HDLproto is a lightweight, pre-RTL simulator that runs on pure Python. With zero external dependencies, it lets you quickly validate signal timing and control logic during the early design stages (from spec to architecture).

  • Intuitive API: express HDL design rules directly using @always_ff / @always_comb and .r / .w
  • Event-driven safety: detect rule violations, multiple drivers, and non-convergent combinational logic via exceptions
  • Easy to adopt: runs with Python only — great for learning, teaching, and rapid prototyping

About HDLproto (Concept and Scope)

HDLproto is a lightweight simulation framework for emulating HDL-style (Verilog/SystemVerilog) descriptions in Python. It does not aim to strictly replicate HDL syntax but rather to provide a prototyping environment for concisely testing "hardware behavior models" like always_comb / always_ff and Wire / Reg within Python.

Target Goals

HDLproto is designed for the following use cases:

  • Verifying CPU microarchitecture designs
  • Checking the behavior of small-scale digital circuits
  • Prototyping control units and Finite State Machines (FSMs)
  • Validating ideas and organizing dataflow before full HDL design
  • Understanding the behavior of always_ff / always_comb for educational purposes

The primary goal is to enable users to easily express and verify "HDL-like behavior" using only Python.

What HDLproto is NOT (Unsupported Features)

  • Code generation to Verilog / VHDL / SystemVerilog
  • Logic synthesis for FPGAs / ASICs
  • Timing analysis or logic optimization
  • Implementation of large-scale RTL (thousands of signals)

HDLproto is strictly a simulation environment for prototyping and is not a tool for generating synthesizable RTL for FPGAs.

Key Features

  • Build HDL-style modules and signals using only Python
  • Faithfully simulates the behavior of always_comb and always_ff
  • The simulator automatically handles Wire/Reg propagation and stabilization loops
  • Automatically analyzes dependencies between modules and signals to run simulations
  • Capable of simulating small-scale CPUs (like SAP-1 or a Z80 subset)

Intended Users

  • Those who want to quickly prototype CPUs or digital circuits
  • Those who want to verify dataflow or algorithms before starting HDL design
  • Engineers and students who want to learn the concepts of hardware description languages
  • Those who want to design with a hardware mindset, even without access to Verilog
  • Those who want to experiment with circuits using the flexibility of Python

Installation

Installation from PyPI

pip install hdlproto

Install development version

git clone https://github.com/shntn/hdlproto.git
cd hdlproto
pip install -e .

Run without installation

git clone https://github.com/shntn/hdlproto.git
cd hdlproto
PYTHONPATH=. python3 example/ex_sap1.py

Requirements

  • Python 3.10 or higher

Design Rules (Important)

  • @always_ff((Edge.POS, 'clk'), ...): Only non-blocking assignments to Reg (writes via .r) are valid. Describes sequential logic sensitive to specified signal edges.
  • @always_comb: Only writes to Wire/OutputWire (via .w) are valid. Writing to Reg/OutputReg will raise an exception.
  • Simulator.clock() drives the clock signal specified in SimConfig. The clock signal must be received as an InputWire in the top module and defined as a Wire in the TestBench.
  • Reset is treated as an input signal. Asynchronous reset is implemented by adding the reset signal to the @always_ff trigger list (e.g., @always_ff((Edge.POS, 'clk'), (Edge.POS, 'reset'))). Synchronous reset is described by writing the reset condition inside an always_ff block that only triggers on the clock edge.
  • Convergence loop: @always_comb is re-evaluated until signals stabilize. Non-convergence raises an exception.

Included Samples

  • example/ex_module.py: A slightly richer introductory example.
  • example/ex_sap1.py: A SAP-1 implementation, ideal for pre-RTL exercises.
  • example/ex_exception.py: Scripts to reproduce exceptions (rule violations, conflicts).

License

  • License: MIT License

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

hdlproto-0.4.1.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

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

hdlproto-0.4.1-py3-none-any.whl (42.5 kB view details)

Uploaded Python 3

File details

Details for the file hdlproto-0.4.1.tar.gz.

File metadata

  • Download URL: hdlproto-0.4.1.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0rc1

File hashes

Hashes for hdlproto-0.4.1.tar.gz
Algorithm Hash digest
SHA256 0027cc0781f8a7dd4e456571c54699ea4a11aaa794169021ce2100a1d2ea8187
MD5 d8f8bd483f8a9e5ddc4c705836cd45b7
BLAKE2b-256 b53a898e2747e9528b60b0c2a42c0c77a050039527743280ca92e0022fd56e3a

See more details on using hashes here.

File details

Details for the file hdlproto-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: hdlproto-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 42.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0rc1

File hashes

Hashes for hdlproto-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5692dffd82f4bfce37d8f7bc6d509f49cfc18c6c0ca43420ffb62d340c78f6a9
MD5 487448c0f4709453df9b41eb79e18b7a
BLAKE2b-256 1f67b54681bd0dee006d686df2d208ea2f2e06672763a2e3bb35eb70023df36d

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