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_comband.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
Requirements
- Python 3.10+
Installation
From PyPI:
pip install hdlproto
Development install
git clone https://github.com/shntn/hdlproto.git
cd hdlproto
pip install -e .
Tip (running examples from the repo without installing): PYTHONPATH=. python example/ex_module.py
Quick Start (minimal example)
Save the script below as quickstart.py and run it.
from hdlproto import *
class Counter(Module):
def __init__(self, en, out):
self.en = Input(en)
self.out = Output(out)
self.cnt = Reg(init=0, width=4)
self.cnt_next = Wire(init=0, width=4)
super().__init__()
@always_ff
def seq(self, reset):
if reset:
self.cnt.r = 0
elif self.en.w:
self.cnt.r = self.cnt_next.w
@always_comb
def comb(self):
self.cnt_next.w = (self.cnt.r + 1) % 16
self.out.w = self.cnt.r
class TbCounter(TestBench):
def __init__(self):
self.en = Wire(init=1)
self.out = Wire(init=0, width=4)
self.dut = Counter(self.en, self.out)
super().__init__()
@testcase
def run(self, simulator):
for i in range(6):
if i == 3: # stop increment mid-way
self.en.w = 0
simulator.clock()
print(f"cycle={i}, out={self.out.w}")
if __name__ == "__main__":
sim = Simulator(SimConfig(), TbCounter())
sim.reset()
sim.testcase("run")
What happens:
- Within one clock, the simulator evaluates
@always_ff(register updates) →@always_comb(wire/outputs) - Dropping
ento 0 ati == 3stops the counter as expected
Design Rules (important)
@always_ff: only write to Reg via.r(writingWire/Input/Outputhere is invalid)@always_comb: only driveWire/Outputvia.w(writingReghere is invalid)- Convergence loop:
@always_combre-evaluates until signals stabilize; non-convergence raises an exception
Key Exceptions
SignalInvalidAccess: phase violation (e.g., writingReginalways_comb, writingWireinalways_ff)SignalWriteConflict: multiplealways_*blocks drive the same signalSignalUnstableError: combinational logic failed to stabilize within the allowed iterations (possible feedback loop)
Included Examples
example/ex_module.py: a slightly richer starter exampleexample/ex_sap1.py: a SAP-1 implementation, great for pre-RTL explorationexample/ex_exception.py: small scripts that intentionally raise the main exceptions
Lisence
This project is licensed under the MIT License, see the LICENSE.txt file for details
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hdlproto-0.1.0.tar.gz.
File metadata
- Download URL: hdlproto-0.1.0.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a3d42d13a899a0e6c74f08a470163e12df2a9b02e21354d0c210647fd103fb1
|
|
| MD5 |
dd8dc8e39924e2e49fa9bccc746a674a
|
|
| BLAKE2b-256 |
c71c278f50e6a5b5e04d7f843cc3d2504249aaf31f01e28d6690bcd201d1a986
|
File details
Details for the file hdlproto-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hdlproto-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71d640b1130f979a8705f2ad710bd995e684f2eff58be2f04729e169a0ef29e5
|
|
| MD5 |
24e4c105c4d977ebbed0e994118c1723
|
|
| BLAKE2b-256 |
9be2cfcf5a1518c4b34a13c4607733efa603b19de92be8c22c17773c500a95d8
|