Skip to main content

Converts a subset of python generator functions into synthesizable sequential SystemVerilog

Project description

Open In Colab pypi py versions pypi downloads pytest

python2verilog

  • This tool facilitates the conversion of select Python functions into synthesizable sequential SystemVerilog code
  • Testbenchs can be automatically generated if the user uses the function within their Python code or provides explicit test cases
  • Ideal for quickly translating "CPU code" into hardware descriptions for use on FPGAs, without having to interface with a CPU
from python2verilog import verilogify, Modes

@verilogify(mode=Modes.WRITE)
def hrange(base, limit, step):
    i = base
    while i < limit:
        yield i
        i += step
hrange(10)

Specifications

Constrains on Python functions include:

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

  • Regular functions that use the return keyword, instead yield once
  • for loops, instead rewrite as a while loop
  • Global (nonlocal) variables, instead declare them within the function with minimal overhead
  • Keyword arguments, instead use positional arguments
  • Function calls, instead use the decorator on each of the subfunctions and manually connect together

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

The Github Actions run all the tests with writing enabled. You may find its output as a Github Artifact availible for download.

For Developers

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

Github Issues is used for tracking. Milestones and labels are used for milestones and labels respectively.

Docs

Sphinx is used. Follow the Github workflow to generate a local copy.

Testing

Requirements

For most up-to-date information, refer to the pytest github 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)

Install required python libraries with python3 -m pip install -r tests/requirements.txt

For automatic Verilog simulation and testing, install Icarus Verilog and its dependencies with sudo apt-get install iverilog expected (uses the unbuffer in expected).

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

Creating New Test

To create a new test case and set up configs, run python3 tests/integration/new_test_case.py <test-name>.

Running Tests

To run tests, use python3 -m pytest -sv.

Additional CLI flags can be found in tests/conftest.py.

Use git clean -dxf to remove gitignored and generated files.

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

python2verilog-0.2.0.tar.gz (43.2 kB view details)

Uploaded Source

Built Distribution

python2verilog-0.2.0-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

File details

Details for the file python2verilog-0.2.0.tar.gz.

File metadata

  • Download URL: python2verilog-0.2.0.tar.gz
  • Upload date:
  • Size: 43.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for python2verilog-0.2.0.tar.gz
Algorithm Hash digest
SHA256 36d92fed8aa2f15c942750e3ed14d549faf82fd58caa39307af18d9deb3c3c8c
MD5 6e1e1dd70c6bb0147578a4e42844f1b9
BLAKE2b-256 53f5d5cc22e8a28b2fd959dda28f2d0aa7bba9d4b84208546bb21b8e6b1ba17f

See more details on using hashes here.

File details

Details for the file python2verilog-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python2verilog-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1da4799a785a40e44dd43fa8049803e9cd440b61f92346ac6c4d67f8190a0bd5
MD5 1647cee18096d5cf1f93e61134291c7d
BLAKE2b-256 41d553b88e420690b50b020463e415e2cf966471c121f0ea5fb6e16c1271496d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page