Skip to main content

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

pip install PySHDL

Quick Start

1. Define a Circuit (SHDL)

Create a file adder.shdl:

use fullAdder::{FullAdder};

component Adder16(A[16], B[16], Cin) -> (Sum[16], Cout) {
    >i[16]{
        fa{i}: FullAdder;
    }
    
    connect {
        A[1] -> fa1.A;
        B[1] -> fa1.B;
        Cin -> fa1.Cin;
        fa1.Sum -> Sum[1];
        
        >i[2, 16]{
            A[{i}] -> fa{i}.A;
            B[{i}] -> fa{i}.B;
            fa{i-1}.Cout -> fa{i}.Cin;
            fa{i}.Sum -> Sum[{i}];
        }
        
        fa16.Cout -> Cout;
    }
}

2. Use in Python

from PySHDL import Circuit

# Load and compile the circuit
circuit = Circuit("adder.shdl")

# Set input values
circuit.poke("A", 42)
circuit.poke("B", 17)
circuit.poke("Cin", 1)

# Run simulation
circuit.step(10)

# Read output
result = circuit.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 value
  • peek(port_name) - Read an output port value
  • step(cycles) - Advance simulation by N cycles
  • reset() - Reset circuit to initial state

Examples

See the examples/ directory for more complete examples:

  • interacting.py - Basic circuit interaction
  • SHDL_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyshdl-0.1.4.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyshdl-0.1.4-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file pyshdl-0.1.4.tar.gz.

File metadata

  • Download URL: pyshdl-0.1.4.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for pyshdl-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f5202aa09953c66153ac384e818f0e404d6b189e2abd3b54020f250b6b0ff13c
MD5 8324116fe8cd8a93fb8ddf1969628de4
BLAKE2b-256 16df4c879dae3f0866a5716af61865525aeaaf78ad2b13d8b83c209baf06ddd3

See more details on using hashes here.

File details

Details for the file pyshdl-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pyshdl-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for pyshdl-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 64fc065cbf0eae5d4c372ca3ebc7d9465f62734fc197696adc70cd44668a1e3a
MD5 c50aa7f296158310e13b9c2f467d1b3f
BLAKE2b-256 0cecab089b8b280e1774f0dae48eebf5d6aa5bb9deb9104eeb33de36f35a1774

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