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/Output (via .w) are valid. Writing to Reg will raise an exception.
  • Simulator.clock() drives the clock signal specified in SimConfig. The clock signal must be received as an Input 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.3.1.tar.gz (28.9 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.3.1-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hdlproto-0.3.1.tar.gz
Algorithm Hash digest
SHA256 ed5625a77599302d9e59d6eec06d0f5c7ab621d7cdab779a91c26123ac557a93
MD5 89c6e48f80e8bc95fde4e998ac1e92c5
BLAKE2b-256 cc68fcf43c4efb20ecb0a2638dacaff758db4e0015cbec6e9e1859ce65eb1f8f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hdlproto-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 33.2 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23a717a82699be33f6471a9f227f973a38d4b558a8c8d579bf904258e642f271
MD5 c516d5f4b06d23d98573a8ce9195b643
BLAKE2b-256 1a63b0d55a92d11d93999da79b17b8a83c36c1cab3c2c23577b244aa2dc421c2

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