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-2.0.0.tar.gz (886.5 kB view details)

Uploaded Source

Built Distributions

pyslang-2.0.0-cp310-cp310-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.10 Windows x86-64

pyslang-2.0.0-cp310-cp310-musllinux_1_1_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pyslang-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyslang-2.0.0-cp310-cp310-macosx_10_15_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pyslang-2.0.0-cp310-cp310-macosx_10_15_universal2.whl (5.0 MB view details)

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

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

Uploaded CPython 3.9 Windows x86-64

pyslang-2.0.0-cp39-cp39-musllinux_1_1_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pyslang-2.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyslang-2.0.0-cp39-cp39-macosx_10_15_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pyslang-2.0.0-cp39-cp39-macosx_10_15_universal2.whl (5.0 MB view details)

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

pyslang-2.0.0-cp38-cp38-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.8 Windows x86-64

pyslang-2.0.0-cp38-cp38-musllinux_1_1_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pyslang-2.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyslang-2.0.0-cp38-cp38-macosx_10_15_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pyslang-2.0.0-cp38-cp38-macosx_10_15_universal2.whl (5.0 MB view details)

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

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

Uploaded CPython 3.7m Windows x86-64

pyslang-2.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl (3.2 MB view details)

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

pyslang-2.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

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

pyslang-2.0.0-cp37-cp37m-macosx_10_15_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: pyslang-2.0.0.tar.gz
  • Upload date:
  • Size: 886.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for pyslang-2.0.0.tar.gz
Algorithm Hash digest
SHA256 5ce7075209c47f68f501fb688750b8bcb7cd6eaccbfd2e68f34515a84c10a4df
MD5 6023cee3897e244ed0632005e1bcfdb7
BLAKE2b-256 57e33965221baa336a721db9037b0ac0ca4e13a59a2e528dd3baf702b1f21336

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-2.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for pyslang-2.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 222a02f5bcbdb183f8e6539c90a61d0d96687e78dc6f822c38604a6f7c1ac4b3
MD5 6a48dddb740895193ff819d6e6130d51
BLAKE2b-256 40502a9715344ef321aabd1d3a5a11cd235b1e12f6abf66a388881b294b9317d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 8131fb0b67803547e6416a91a9006766951e935deaadf21af6d951245cdc16ad
MD5 7242ae6ebbe01c4d9b594c269d5d6800
BLAKE2b-256 45586e193514f66c71005c27150ff21199b355c90300aa4734cf9a3c7e9562c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3347bbca0d0c8fd62f4bbe30eb1f1ed0c1252e86ab6fd58a95544ef6d274b754
MD5 2f82ff70c66b2f27ed25e6daf1960e11
BLAKE2b-256 18242066507e14a12fe5a44e8e6a235a92f09807b0b3e3ffb16999eaf1bf0e51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4b3120bed5cec1c5e28e5b2f93d7bb52980e87f18badc1df6c13b6ff6323aa66
MD5 5fd2efed9a94865aed2061ac521aa9f8
BLAKE2b-256 b08fb1a520834d9f4dee4728efd804f38e04156319785d9b24ff615fa4ac4ed4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 6c330175e91dfb50a49be49bc68cc90fbb606cd99a8b040585ec4fc6f24f94ae
MD5 3ae051ab65a3d9976558dd412c7b6c59
BLAKE2b-256 f607232bd97d27178a752c30e40b5359838db056f641a798bc210d38c42fc578

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-2.0.0-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.15

File hashes

Hashes for pyslang-2.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2b482e4c1c1cbf8a0828a093091ad5ece548438298945b323cedcc76227c8322
MD5 e76455f18a15b5bf00128efeb150be42
BLAKE2b-256 f2b839d953138880b0edaedb7dc3708f766c369b6c05a5106d9c2f580211677a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 60d8a71cad23ad8f5949c26a713c6855efcbc5ed4632c47fabbed2adecdff1dd
MD5 196ab18df7b44a1ba886ed2731a1b2ca
BLAKE2b-256 17cb7919a7f42a99ea7f5a735f82d9ea5b25e8db8a50d9cf40a1319bf86ae20d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3933a024e41c1d2d1202f8a51a1126c4517c13e8003674942055dafc77470d5
MD5 16613e3403d9096fa1ee2594ed7bbacd
BLAKE2b-256 267a01af3ff7b1c4514c7f583793583b6e469d05cd59dd242e93c6b06a478e84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 49f47cdd0b3079a5649e7639a67c556909912ac70532ec674c374547a3eb7467
MD5 8a76cedb3fc18aec31a179a4c385b0e7
BLAKE2b-256 66c664890daa84f6b93f6b14809accad663c008e8200bdad0e8b066ca8caded3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 dc38538621fe8ca311521644c7b85c94c658a8d91045ec60d7ef910abe30cc02
MD5 a0e0e468708ac660024742e1edaf88ba
BLAKE2b-256 02217f0222702cde83e69791e5736e82206430ef51d96e8156310b6c87ef4a64

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-2.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c5d98aa114aac5b1d6e60cad79f9d89f6d2d981333e4f2a956ff32201fe7eecf
MD5 5135917352e5a7aaa4b9b003c89d141e
BLAKE2b-256 4ec1b65efe53a8c7231cd1a54362cf9e7277b3f56e8f9db260749da4e3f220c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 7fb4b2c303542f7c3f1599a2bf2013a8949cd37bd2dc711688b394c8a6b49b01
MD5 eba287f88c0d7cdf2bb2294d4adc5db8
BLAKE2b-256 b26b7ad244ba80c9d89aea710a283b48960c60b613c90359f1266ea496f171d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ad101227efa6fdf53c84fcaa01ff064d001676b309c36c57b09697be022d97c1
MD5 8bc3baba5ebacef7ad8502788dae57bd
BLAKE2b-256 94a824b6bd81affef6282713adf2b1e9c07adfec03d44ab305913acc4a9bd014

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 65e1891f5fc4cd6a4644e4736de3b90c7e8230d004a4976501059adca8a4dec1
MD5 d079fbf3a12fd10bee374381be8be6ca
BLAKE2b-256 569db925180b0607f909bc7480a1b07c021750d6c931273608e0c91f35372eda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 d4dee40666cdae4ed269fcf48daea69c94ab3b36199f09ff093cc5b45441c8b1
MD5 a755d0b3da8d4c6e9a8f2d756f40112d
BLAKE2b-256 4a70c82f4688b0e7bbd4c81fc40aa27119b4b68865f379c9eff37d4cace9ae99

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-2.0.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for pyslang-2.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 7561620acac20f9c6b50198c3c5ac3c16015b4e5b1d99aa527db9e35d8762bd5
MD5 61ffa8415f6be703bcf53fc5e9acb98c
BLAKE2b-256 86e747d841e0ae25a9c1ae40a323e028b4f75a3dfc1e516a8fd3e21d8da4ace1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5ac117e8ab3d06aaafc216949ede2f38f3d700800b916611626260896a667c20
MD5 5c64e4db317531bc130409a77120d080
BLAKE2b-256 14e7fade552245f2a4eb7302332b6ff3e5179ad9ea60bc7f13c03271c5566b33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0154494b79f43de64b6e2048b12daccb5c79263d4e1428f609870cd9d238b21a
MD5 1a31f75b03365634ece6bcae1dec4996
BLAKE2b-256 4126bc4d71a28e8f1ba062059267c6b836fb49d3908d00e2186c7ab0e540da9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-2.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e492696e4582136f7b8ca3505f3e6911755b9dc0fada3f67937a6772aaca8e4d
MD5 0e8b610d1b8ded94b6cf35d5b997602c
BLAKE2b-256 3d71e517ab9652895fc6483f56facf4ea879bc9a2dcfa062195e1b502b53b4f2

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