SHDL hardware-description toolchain: the PySHDL user-facing driver, the SHDL→Base SHDL flattener, the Base SHDL→C compiler (shdlc), and the conformance suite.
Project description
SHDL
SHDL (Simple Hardware Description Language) is an educational, gate-level hardware description language and simulation toolchain. Its founding principle is fidelity: circuits simulate gate by gate, one propagation level per cycle (the unit-delay model), and no tool in the chain is allowed to collapse or shortcut that structure. You describe hardware out of AND/OR/NOT/XOR; you watch signals ripple through it.
The two languages
SHDL is the authoring language: reusable hierarchical components, multi-bit ports, compile-time parameters, generators and conditionals for repetitive structure, bit slices and concatenation, named constants, optional initial state, and imports. Specified in docs/shdl.md.
Base SHDL is the intermediate representation every tool consumes: a flat
netlist of single-bit wires over exactly six primitives — AND, OR, NOT,
XOR, __VCC__, __GND__ — plus a JSON metadata section (multi-bit port
groups, hierarchy, source maps, timing, constants, init seeds). Specified in
docs/base_shdl.md.
Pipeline
.shdl source
│
▼
Flattener six phases: strip, monomorphize, expand generators,
│ expand slices, materialize constants, flatten hierarchy
▼
Base SHDL single-bit primitive netlist + JSON metadata
│
▼
SHDLC generates C (two-buffer compute/commit cycle),
│ builds a shared library with a stable ABI
▼
libcircuit reset() / poke() / peek() / step()
(+ step_settle() / run_batch() throughput paths)
Quickstart
Requires Python ≥ 3.14 and a C compiler (clang or gcc).
Install the released package from PyPI to get the SHDL Python package and the
shdlc / shdl-flatten / shdl-conformance CLIs:
pip install PySHDL # or: uv add PySHDL
Or work from a clone with uv:
uv sync
# Flatten SHDL to Base SHDL (inspect the IR)
uv run shdl-flatten examples/fullAdder.shdl
# Compile straight from SHDL source to a shared library
uv run shdlc examples/fullAdder.shdl -o fullAdder.dylib
Drive a circuit from Python with PySHDL — one class, Circuit, runs the
whole pipeline (flatten → compile → build → load) in-process and exposes
poke/peek/step plus dict access and a context manager:
from SHDL import Circuit
with Circuit("examples/adder8.shdl") as c:
c["A"] = 100 # dict-style poke; bit 0 is the LSB
c["B"] = 55
c.settle() # advance every gate level (combinational depth)
print(c["Sum"]) # 155
See docs/pyshdl.md for the full guide, and
examples/interacting.py for a runnable walkthrough
(uv run python examples/interacting.py). The underlying ABI is callable from
any language; see docs/shdlc_goals.md §3 for the full
contract (masking, lazy evaluation, init-seeded power-on state).
Repository layout
| Path | What it is |
|---|---|
flattener/ |
SHDL → Base SHDL (lexer, parser, six lowering phases, metadata, HighEval reference interpreter) |
shdlc/ |
Base SHDL → C → shared library (model, codegen, cc driver, BaseEval reference interpreter, ctypes harness) |
SHDL/ |
The user-facing Python driver: Circuit runs the pipeline in-process and exposes poke/peek/step (from SHDL import Circuit) |
conformance/ |
Frozen corpus of cases with golden Base SHDL + cycle-by-cycle traces, and its runner |
tests/ |
flattener/, compiler/, and cpu/ suites (~1640 tests) |
examples/ |
Small circuits (adders, latches, mux, ALU) and a complete, verified 16-bit CPU (examples/CPU/) |
docs/ |
The normative specs and the verification map |
scripts/ |
Maintenance tooling (conformance corpus builder) |
The flattener and shdlc are deliberately decoupled: Base SHDL text is the only contract between them, and each side carries its own independent reference interpreter so the two can cross-check each other.
Testing
uv run pytest # full suite
uv run shdl-conformance run # golden corpus: flatten + compile + trace lockstep
The suite covers per-phase units, per-raise-site diagnostics (every error's exact position is pinned), differential fuzzing against two independent oracles, byte-determinism, ABI contracts under ASAN/UBSAN, and instruction- level lockstep of the example CPU against a golden model.
Documentation
- docs/SHDL_Project.md — project charter: architecture, ecosystem, build sequence.
- docs/shdl.md — the SHDL language specification.
- docs/base_shdl.md — the Base SHDL IR specification.
- docs/shdlc_goals.md — the compiler's obligations and ABI contract.
- docs/golden_tests.md — the verification map tying every spec obligation to tests.
Status
The flattener, the SHDLC compiler (release ABI), the conformance suite, and
PySHDL — the user-facing Python driver (from SHDL import Circuit) — are
complete and green. Next up are the debug build and the SHDB debugger — see the
build sequence in the charter.
Project details
Release history Release notifications | RSS feed
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 pyshdl-1.0.0.tar.gz.
File metadata
- Download URL: pyshdl-1.0.0.tar.gz
- Upload date:
- Size: 491.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66ae1fd4884794b84075e266ff4cf3ec7a912b2cf57d837aa4d096718052821c
|
|
| MD5 |
9bbffb6da6a7c250ab57cd5398180621
|
|
| BLAKE2b-256 |
e9686b56ef028b051e43a3eb61ed43158d867bb8c8fa9e55fd2b55dffd88a32e
|
Provenance
The following attestation bundles were made for pyshdl-1.0.0.tar.gz:
Publisher:
publish.yml on rafa-rrayes/SHDL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyshdl-1.0.0.tar.gz -
Subject digest:
66ae1fd4884794b84075e266ff4cf3ec7a912b2cf57d837aa4d096718052821c - Sigstore transparency entry: 1825873113
- Sigstore integration time:
-
Permalink:
rafa-rrayes/SHDL@52d0863c118867f0d990ce3c2e9f71da5a22bfa4 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/rafa-rrayes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@52d0863c118867f0d990ce3c2e9f71da5a22bfa4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyshdl-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyshdl-1.0.0-py3-none-any.whl
- Upload date:
- Size: 282.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
012bb0dab908ff5ec952d3c48c38c80bf28891ea288c9761ef8d32718c0eb9cd
|
|
| MD5 |
ab18c3de5490bc125bf134d02dee479b
|
|
| BLAKE2b-256 |
d203e83650269fc3370918de5d72ab10f1b0df981fbbe55f9f816366227d233a
|
Provenance
The following attestation bundles were made for pyshdl-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on rafa-rrayes/SHDL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyshdl-1.0.0-py3-none-any.whl -
Subject digest:
012bb0dab908ff5ec952d3c48c38c80bf28891ea288c9761ef8d32718c0eb9cd - Sigstore transparency entry: 1825873143
- Sigstore integration time:
-
Permalink:
rafa-rrayes/SHDL@52d0863c118867f0d990ce3c2e9f71da5a22bfa4 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/rafa-rrayes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@52d0863c118867f0d990ce3c2e9f71da5a22bfa4 -
Trigger Event:
release
-
Statement type: