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.0.tar.gz (28.8 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.0-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hdlproto-0.3.0.tar.gz
  • Upload date:
  • Size: 28.8 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.0.tar.gz
Algorithm Hash digest
SHA256 a8d330e84e8a78455b208ea1c82afa0ddc280f8d5f168beb7e78a0526ba2703e
MD5 a4fc9109c031993891c72ffda9cd3d9c
BLAKE2b-256 37d205053456a2469e372e41423f4a88ce34ae9bc93c2e5e9037000550f96333

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hdlproto-0.3.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe91268904985ad41efee0e5ebc5924099915236a5591806363e53dba14690f7
MD5 853ad4d9827ec3c198a52515d7e2587f
BLAKE2b-256 2f81cac9df6a2e8b57377228bdb119599628079b26abfb0d75c80887ad148f7a

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