Skip to main content

Python bindings for slang, a library for compiling SystemVerilog

Project description

pyslang - Language bindings for slang, SystemVerilog parsing and compilation library

build PyPI License: MIT Join the chat at https://gitter.im/MikePopoloski/slang

slang is a software library that provides various components for lexing, parsing, type checking, and elaborating SystemVerilog code. pyslang exposes that library to Python projects.

Full documentation is available on the website: https://sv-lang.com

Installation

pyslang can be installed like any other Python library, using (a recent version of) the Python package manager pip, on Linux, macOS, and Windows:

pip install pyslang

or, to update your installed version to the latest release:

pip install -U pyslang

or, to checkout and install a local build:

git clone https://github.com/MikePopoloski/pyslang.git
cd pyslang
git submodule update --init --recursive
pip install .

Example usage

Given a 'test.sv' source file:

module memory(
    address,
    data_in,
    data_out,
    read_write,
    chip_en
  );

  input wire [7:0] address, data_in;
  output reg [7:0] data_out;
  input wire read_write, chip_en;

  reg [7:0] mem [0:255];

  always @ (address or data_in or read_write or chip_en)
    if (read_write == 1 && chip_en == 1) begin
      mem[address] = data_in;
  end

  always @ (read_write or chip_en or address)
    if (read_write == 0 && chip_en)
      data_out = mem[address];
    else
      data_out = 0;

endmodule

We can use slang to load the syntax tree and inspect it:

import pyslang

tree = pyslang.SyntaxTree.fromFile('test.sv')
mod = tree.root.members[0]
print(mod.header.name.value)
print(mod.members[0].kind)
print(mod.members[1].header.dataType)
memory
SyntaxKind.PortDeclaration
reg [7:0]

We can also evaluate arbitrary SystemVerilog expressions:

session = pyslang.ScriptSession()
session.eval("logic bit_arr [16] = '{0:1, 1:1, 2:1, default:0};")
result = session.eval("bit_arr.sum with ( int'(item) );")
print(result)
3

Contact & Support

If you encounter a bug, have questions, or want to contribute, please get in touch by opening a GitHub issue or posting a message on Gitter.

Contributions are welcome, whether they be in the form of bug reports, comments, suggestions, documentation improvements, or full fledged new features via pull requests.

License

slang (and pyslang) is licensed under the MIT license:

Copyright (c) 2015-2022 Michael Popoloski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

pyslang-1.0.191.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

pyslang-1.0.191-cp310-cp310-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

pyslang-1.0.191-cp310-cp310-musllinux_1_1_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pyslang-1.0.191-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyslang-1.0.191-cp310-cp310-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pyslang-1.0.191-cp310-cp310-macosx_10_15_universal2.whl (5.4 MB view details)

Uploaded CPython 3.10 macOS 10.15+ universal2 (ARM64, x86-64)

pyslang-1.0.191-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

pyslang-1.0.191-cp39-cp39-musllinux_1_1_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pyslang-1.0.191-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyslang-1.0.191-cp39-cp39-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pyslang-1.0.191-cp39-cp39-macosx_10_15_universal2.whl (5.4 MB view details)

Uploaded CPython 3.9 macOS 10.15+ universal2 (ARM64, x86-64)

pyslang-1.0.191-cp38-cp38-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.8 Windows x86-64

pyslang-1.0.191-cp38-cp38-musllinux_1_1_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pyslang-1.0.191-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyslang-1.0.191-cp38-cp38-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pyslang-1.0.191-cp38-cp38-macosx_10_15_universal2.whl (5.4 MB view details)

Uploaded CPython 3.8 macOS 10.15+ universal2 (ARM64, x86-64)

pyslang-1.0.191-cp37-cp37m-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.7m Windows x86-64

pyslang-1.0.191-cp37-cp37m-musllinux_1_1_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

pyslang-1.0.191-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyslang-1.0.191-cp37-cp37m-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

Details for the file pyslang-1.0.191.tar.gz.

File metadata

  • Download URL: pyslang-1.0.191.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pyslang-1.0.191.tar.gz
Algorithm Hash digest
SHA256 1108b44be2f641638c64109c209288afef94180a8a4f94c8e4331eb066cf7c79
MD5 f7952e46d1ab9b04e95624dc297274a2
BLAKE2b-256 48eadb415f9fba81d799c139ee50c68ba514bc4b89833aaa0063cf7c1b9d00c1

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2dbcd19571f21c5b8c6483821bb6dec2925147835929a8fc07b01efa763485ea
MD5 a610e62e922d413e8572faf860b7ea5f
BLAKE2b-256 5e9d1b8b4ca6d9fcd560ca237af6094f6c8eae367d23ddbf871465490d87a4f7

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 28132220bff248a7a66f9015989a3df9cca3720b9bf205f381c9c463ef309c5f
MD5 0c6e7677ee7174140e2e04f2ae070ce3
BLAKE2b-256 7b7bb26e7850a8ba6e6e9ccf745eb542d644a2e112c701e0ece57f6f8eb472e5

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc6b448b102ea79b1e205f4e482492488d25de471874438b7b20535c6b99160c
MD5 9bbbfb336145f1119dd53b0fba5ec591
BLAKE2b-256 4ab2a97aaec0e74b61e43d0bab620523d5124cd359d98513db446744b64fbf28

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f17692ad993437691b3ee21a4a03bb626315f818b541e6191e630bb20e28a648
MD5 7beafdd2bc92ddffc1e806afe3e82860
BLAKE2b-256 5300505c932e0a520e4ee45da722448024a77a06d7881ba0aa469a264288c9fa

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp310-cp310-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 ecf3213f3ea1c9959e2720b3cab33cfc1cde47194f1be8d75e3696da8e5a96e3
MD5 5aeb95b05fdf5468ede80c9cd4db84b7
BLAKE2b-256 a8594a4bbd32530db7d03dc917f280436fcc1d660fcd1cc1fec3f145ce9d98b4

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pyslang-1.0.191-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pyslang-1.0.191-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5ba7fa2373bd0e1ba63c2b9ca6276e8b74d398502f49b67eb0dfbab9a4a41a6e
MD5 3648e5b58a278ca542dfa7967360cd84
BLAKE2b-256 b2c34ab919753b8d90c97dc0d84acdb7f29a8a1e4e694671801a8daf11dc2267

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 d4300a8c20e4186732a58ea1836e4ddea4822063978718a554228b83a53936c1
MD5 b3cc555568bf3f600b32dad9d5be5d34
BLAKE2b-256 5b521ee284da49a14786fe2486d19eb649d1d117c2a36e93771d5e6333ad3785

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f8574763aa29ac60b44c8f2b6a2f5be57e51bf49497aea08257036a9ece989aa
MD5 52d81691bf1af899a4ecde85bcc66e08
BLAKE2b-256 6d8e11ffdd7fe3175c4d408135cdbf2bb7f276fe0707bd660a58c23b4df7a104

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7de2a2e691f7d3e0eff004ec5cf1eb0c2792a7708ce3d1e730ce82080f97d170
MD5 576cc2fea7415fc6879b063620208609
BLAKE2b-256 e4654634c5a4ebd51ec0cb61b8afdfea093bf663318a4cd1e124e88d1127c4f0

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp39-cp39-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 408d39f2538c26ccacb9c41a8b9492e5b5ae339771c122e8ea0ecc6db01cfb57
MD5 13ae745c0708aa63a843de414da0dc67
BLAKE2b-256 2c32aac7cbbf473a5842e0aa458690fb6318d73ba6c3a399e7d5a9a7bb36a6d6

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyslang-1.0.191-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pyslang-1.0.191-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0df3d6e258cb9cc51d328ee45d7394bfc3d8274ddb26dd42922dd89393546cff
MD5 0bb107a17f922531a926dd1972a8ac97
BLAKE2b-256 a144fb9c53a35c4e8fab1644f9ed6cfae110d80096a9da72a7ffc56f24b68ee8

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 52d5ac1f669791ef23c4a0a5cc99f82db260af6a034990d56710e206bdd996a1
MD5 3269f0aa4cb13202dad1c633ef60067e
BLAKE2b-256 69ed69571aed3c16af096a1deb5477b7ef1c2cb86d4c82af4c1e60c3c18a2bca

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 266bc3d03b91a27e2120212036a2915d38027b204cff631f0e0f938d6c86e743
MD5 290db6b9eee263680340027d46b1c52c
BLAKE2b-256 0cfd66f2163bdb0118cfa31d5a873f74f8d532f297fda772039904baed4854cc

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2b5dc155e8142124275f9f27486355d8d600024de8d36e80155e1bd39b51e892
MD5 8b171877a7214d4390c09b7fb4bb3082
BLAKE2b-256 ccdf587ab900002cfce4d6f5aa5ca67d5596f897f1e9939e81e37b3f2d058427

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp38-cp38-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 7f2ac04ab994e712817ff04a7ad1ce75a8ec374e8d2de335035bdb30e5371db1
MD5 dbaf8c75eaf234d0aa33615763b06c41
BLAKE2b-256 440d2db60b40a903d8cecdb871bdbc996c5887751263b0dad8935e89ef15b83d

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 120850846ca8cf12e43d56334f2d94d682c72f2a834f6461223a93c7253eda82
MD5 ab899e57950330cb5173aed8554fdb1e
BLAKE2b-256 67305c08a8110c3978b24b5b50291474059210fcbe5e819e30d4703a57f562bb

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp37-cp37m-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0f52b6e94d4f8e968315e142af8dbefb929fbe0f8095bcae9f949784b17035c8
MD5 615b8e0de9c5216018b78a08b132afdd
BLAKE2b-256 884498d203a65cfea81193a25f33059bb6e8dc21eb1d7b1b6012ebd3fc8942d9

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 48b839e15bec3499eceaa08bea37e1fd65c5b946cb4e8c983342ccce3adda3ca
MD5 f1d3b3495a00eccbef167e55572dc926
BLAKE2b-256 5f92d66ba208235d2d0367cc168ecd1f137223321a8a498271d822c9f8919c9b

See more details on using hashes here.

File details

Details for the file pyslang-1.0.191-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-1.0.191-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 84dd6425389c07d8bca4f179300d502aa5030fc22ecb75b35fe52f9e0010a9b4
MD5 887979149f296113eef3bf87e5191a21
BLAKE2b-256 c010e6fa8bf636c989019a65d45703a2a3de02ac3879345592f3af88c537d23a

See more details on using hashes here.

Supported by

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