Skip to main content

Open In Colab pypi py versions pypi downloads pytest

python2verilog

  • This tool facilitates the conversion of select Python functions (including generators!) into synthesizable sequential SystemVerilog
  • Ideal for quickly translating higher-level "CPU code" into hardware descriptions for use on FPGAs, without needing to interface with or including a CPU in the design
  • Testbenches can be automatically generated if the user uses the function within their Python code or provides explicit test cases
from python2verilog import verilogify

@verilogify
def hrange(base, limit, step):
    i = base
    while i < limit:
        yield i
        i += step
print(list(hrange(0, 10, 3)))

A live transpile demo can be found here.

Specifications

Some constrains on Python functions include:

  • Supports only signed integral input/output and operations
  • Must be a pure function

Unsupported Python paradigms include but are not limited to the following:

  • Global (nonlocal) variables, instead declare them within the function with minimal overhead
  • Keyword parameters and default arguments, instead use explicit positional arguments

Usage and Installation

Try it in Google Collab or check out examples/!

python3 -m pip install --upgrade pip

python3 -m pip install python2verilog

Tested Generations

You may find the output of the integration testing as a Github Artifact available for download.

For Developers

To setup pre-commit, run pre-commit install.

Github Issues are used for tracking.

Sphinx is used for the docs. Follow the sphinx workflow to generate a local copy.

Development

Setup

For most up-to-date information, refer to the pytest workflow or the packaging workflow.

A Ubuntu environment (WSL2 works too, make sure to have the repo on the Ubuntu partition, as os.mkfifo is used to avoid writing to disk)

Steps

source ./build.sh venv
./build.sh all
pre-commit install

For automatic Verilog simulation and testing, install Icarus Verilog and its dependencies with

sudo apt install expect
# This adds `iverilog` to PATH
git submodule update --init
./extern/iverilog_setup.sh

The online simulator EDA Playground can be used as a subsitute if you manually copy-paste the module and testbench files to it.

Running Tests

Run Python tests with pytest. Run rust tests with cargo test.

CLI arguments for test configuration can be found in tests/conftest.py.

Use ./clean.sh to remove gitignored and generated files.

Troubleshooting

cargo test Errors

  • error: linker `cc` not found
    • On Ubuntu run sudo apt install build-essential
  • /usr/bin/ld: cannot find -lpython3.10: No such file or directory
    • On Ubuntu 22.04 run sudo apt install libpython3.10-dev

Flamegraph

cargo install flamegraph

sudo apt install linux-tools-common linux-tools-generic linux-tools-`uname -r`

sudo sysctl kernel.perf_event_paranoid=0

CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --unit-test tohdl-tests -- verilog::module::test::odd_fib
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --test loops

Will need to set PERF env var for flamegraph if running in WSL from this stackoverflow answer.

Metadata

Release files for python2verilog 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python2verilog 0.5.0
File Size Uploaded Provenance
python2verilog-0.5.0.tar.gz 59.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for python2verilog 0.5.0
File Interpreter ABI Platform
python2verilog-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 128.9 kB

Release files / python2verilog-0.5.0.tar.gz

Download URL python2verilog-0.5.0.tar.gz
Size 59.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c1b68fe2d3d49cb3b2be9a2e2cfb2f1be2aba01ac35a01bab41512a04bc7fa59
BLAKE2b-256 checksum
How to use checksums
2302c05ac947a18b9a2f9126d7e7bef830b7a781e975bf13fc45471c1ecf4bda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / python2verilog-0.5.0-py3-none-any.whl

Download URL python2verilog-0.5.0-py3-none-any.whl
Size 69.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8bcfa0ed8766398a1c4e55dbfb4bb6c48b06b3924e620905eadc3566173fad9
BLAKE2b-256 checksum
How to use checksums
7d42a8ad78efabce848b267a16a032835d4db6452a7c3c2cc863b7909319687f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Security for python2verilog 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page