SHDL (Simple Hardware Description Language) is a minimal HDL designed for creating digital circuits and easily simulating them. It compiles directly to C for maximum performance and portability. PySHDL is the Python interface for SHDL.
Project description
SHDL - Simple Hardware Description Language
A lightweight hardware description language and Python driver for digital circuit simulation. SHDL provides an intuitive syntax for defining digital circuits and a clean Python API for interacting with them (PySHDL).
Features
- 🚀 Simple Syntax - Easy-to-learn hardware description language
- 🐍 Python Integration - Seamless Python API for circuit simulation
- ⚡ C Backend - Compiles to optimized C code for fast simulation and portability
- 🔧 Command Line Tools - Built-in compiler and utilities
- 📦 Component Reuse - Import and compose reusable circuit components
- 🔢 Constants Support - Use named constants for parameterizable designs
Installation
We recommend using uv for using PySHDL. If you don't have it installed, you can install it via pip:
pip install PySHDL
Quick Start
1. Define a Circuit (SHDL)
Create a file fullAdder.shdl:
component FullAdder(A, B, Cin) -> (Sum, Cout) {
x1: XOR; a1: AND;
x2: XOR; a2: AND;
o1: OR;
connect {
A -> x1.A; B -> x1.B;
A -> a1.A; B -> a1.B;
x1.O -> x2.A; Cin -> x2.B;
x1.O -> a2.A; Cin -> a2.B;
a1.O -> o1.A; a2.O -> o1.B;
x2.O -> Sum; o1.O -> Cout;
}
}
2. Use in Python
from SHDL import Circuit
# Load and compile the circuit
with Circuit("fullAdder.shdl") as c:
# Set input values
c.poke("A", 1)
c.poke("B", 1)
c.poke("Cin", 1)
# Run simulation
c.step(10)
# Read output
result = c.peek("Sum")
print(f"Result: {result}") # Output: Result: 60
3. Compile from Command Line
# Compile SHDL to C
shdlc adder.shdl -o adder.c
# Compile and build executable
shdlc adder.shdl --optimize 3
CLI Options
shdlc [options] <input.shdl>
Options:
-o, --output FILE Output C file (default: <input>.c)
-I, --include DIR Add directory to component search path
-c, --compile-only Generate C code only, do not compile to binary
-O, --optimize LEVEL GCC optimization level 0-3 (default: 3)
Python API
Circuit Class
Circuit(shdl_file, search_paths=None)
Create a new circuit instance from a SHDL file.
Methods:
poke(port_name, value)- Set an input port valuepeek(port_name)- Read an output port valuestep(cycles)- Advance simulation by N cyclesreset()- Reset circuit to initial state
Examples
See the examples/ directory for more complete examples:
interacting.py- Basic circuit interactionSHDL_components/- Reusable component library
Documentation
Github repository: rafa-rrayes/SHDL For more detailed documentation, see DOCS.md
Requirements
- Python >= 3.9
- GCC or compatible C compiler (for circuit compilation)
Author
Rafa Rayes
Email: rafa@rayes.com.br
GitHub: rafa-rrayes
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
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-0.2.0.tar.gz.
File metadata
- Download URL: pyshdl-0.2.0.tar.gz
- Upload date:
- Size: 48.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ccacca0e4ac09f0df8e296e08544717b831908f4c7f7521e5072916a7d09efd
|
|
| MD5 |
303293b628e7c13b2e867a0efecfa16e
|
|
| BLAKE2b-256 |
5928823f8a12e64867235cde682a5fe768acf47ad048dab3139ceb42a0173eda
|
File details
Details for the file pyshdl-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pyshdl-0.2.0-py3-none-any.whl
- Upload date:
- Size: 116.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f55b645dbf32e373bab7f2832b3ca33ebfc86650f2c4a5f5cf28c661c43decb
|
|
| MD5 |
d99bd12b85ccaea4d85d17d510534bd8
|
|
| BLAKE2b-256 |
c3a273f11d2a5f69d270dfda92f660f8b9749adeae5259528fe7a72c8c2b3e13
|