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-2023 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-3.0.0.tar.gz (945.6 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.10 Windows x86-64

pyslang-3.0.0-cp310-cp310-musllinux_1_1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pyslang-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyslang-3.0.0-cp310-cp310-macosx_10_15_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pyslang-3.0.0-cp310-cp310-macosx_10_15_universal2.whl (5.2 MB view details)

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

pyslang-3.0.0-cp39-cp39-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.9 Windows x86-64

pyslang-3.0.0-cp39-cp39-musllinux_1_1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pyslang-3.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyslang-3.0.0-cp39-cp39-macosx_10_15_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pyslang-3.0.0-cp39-cp39-macosx_10_15_universal2.whl (5.2 MB view details)

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

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

Uploaded CPython 3.8 Windows x86-64

pyslang-3.0.0-cp38-cp38-musllinux_1_1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pyslang-3.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyslang-3.0.0-cp38-cp38-macosx_10_15_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pyslang-3.0.0-cp38-cp38-macosx_10_15_universal2.whl (5.2 MB view details)

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

pyslang-3.0.0-cp37-cp37m-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.7m Windows x86-64

pyslang-3.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl (3.4 MB view details)

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

pyslang-3.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

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

pyslang-3.0.0-cp37-cp37m-macosx_10_15_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: pyslang-3.0.0.tar.gz
  • Upload date:
  • Size: 945.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyslang-3.0.0.tar.gz
Algorithm Hash digest
SHA256 f4d57f33a7cd1cb31c6f18c1db338409a914ae019c19be4cec7452919a495626
MD5 e472f942c60e48ea5059940eef5bbfea
BLAKE2b-256 336562b248b0c7fe139737f84a789fb4fab1f7a8c0fe6275def2f721c9a0e2af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-3.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyslang-3.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c006abacb0547795622b38e1174237a896bfe7834d06d9a8a17b124f1c19d3fc
MD5 f2d38f26b3e6991c2f7bf75e8f59be26
BLAKE2b-256 253dc1a716ca7e47d6b5f7718ddc48ef8f05902b62cd1d8eee10ddee447d5ac1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 309d85856690d446598b38b0bc278c740e3aac0a6632994dfd546d71c873132f
MD5 1204a5668e9207c891eca9f47ddd17c3
BLAKE2b-256 05364f0e7b8edf0ec6d3f24ed44a5337faeeeec29b7528c9a36411f05463158a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd63b0e34896f5fb7d8ad0e9878f6075633136d52562271f3f4f3d864404d960
MD5 ede58c7ba2bec43915453c768198746c
BLAKE2b-256 241fd56d5defdc80b8f4e29ab5f27e636651a4f3501c07cf2634fd8392ae625a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9baf73a834fcb52a739f9238b8c107b9bf3dd801431f8a4f012cccfe6ce35129
MD5 17142c69d344a445b176075c5be255e8
BLAKE2b-256 ed508b3ec9bb17175995b50c89216ac11a0b313b441ece4ac79c6a24069d2130

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 8619a76570eb2ce7071697d04deffe3e3a8fb08f3cdf0219b82330b45e89bf6b
MD5 dfd022a76c9155de8e575ec4e7a2a909
BLAKE2b-256 76cbb1296daecd0f242c64988752c15df19272d62855e6b3373b8fe972c68a62

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-3.0.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyslang-3.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a8f1b522f856ae938c69b4bb16e482e88a68f01da28e8190db661b605757858a
MD5 c10477b331560ee3a8a0d756bb8ae402
BLAKE2b-256 fbdb097fe5e15783d7750b3b30bb9735f2f5f00e324aee71562fce7c6fbeaaba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 2c12636ed4f5f5c626c34eed537cdd62b445b9b6d630831c3671de8f56c869b2
MD5 708f6fc28f746ec003e9ea78e1115bed
BLAKE2b-256 943b812fa042f40837b37771c3ea19ee4f474de0b6c668d6deb9ac63ac6e26cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2aac6e5d3fdb5b30da91df530ab49fcb7f5976877c3270d3e332fce3bf4198b5
MD5 341ad22f2e7f94265901cd6e056f4332
BLAKE2b-256 7fd36f3e3b9ea2f05214ce289c96784b29b140b4889cabf54174ebefbb4c6867

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 cc26cefb319e245c2d59aede38af570be1d252c0b731de91d5d4e7ad0ea93d6e
MD5 77d4e863cc1a32526928352bc193071e
BLAKE2b-256 17760294944196763b122d91c07f335cff355dac3669e0d81b6a94b742524676

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 ac2214ce537fa1e0b4469f956ac8951a1e7fec3f8f65f5e30b7d7f4ad1dfd6c7
MD5 270bd2ca774070482bdd0a089378da54
BLAKE2b-256 f533d0354223f1c26b01124a8f3ad59ca455d4d35688adc2dde04882dad0ae33

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-3.0.0-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.2 CPython/3.9.16

File hashes

Hashes for pyslang-3.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 090e96d3a135ca0375dbf18d8d76fc3ebce24585713c7e5ed8f7d6a4aa262152
MD5 33134903ad00085c1f55007efb4bd5e8
BLAKE2b-256 73d88dd593493ef507f10b77ea61ef4a83075fc7982b07829e34e4e053e48255

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 5da843e9474a0446c9c9a0e76419acb4a2148d6568acd499c471eb2d31a472c8
MD5 8322306cbb01d18f5b03b7919ab5ece7
BLAKE2b-256 c5d79bc08bf52bf38c361f0815108f4150ce766ccd06be14c1d1fc57c0aa9c55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b86bbc1efd70656e1bd727cf239b78371fb1e7f7076018ac5d7501bbe68dae1
MD5 1a8dd5685731e03e7e6dd724e443ddfa
BLAKE2b-256 480bacbe75fe328c77a8151402740126d72c2464997c272f6753727e77fade8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 76ddc5b9de270c5831788882432d809fa5d11f611dc1285a8ee5191e59dfee78
MD5 dd2b213770fb1ca7f2363f774a82c205
BLAKE2b-256 fa6f9a6a0b913d9322afbc6ead6df729c650f0b8806868055bbf8e9e76cac682

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 380babd5d5acbc2a94800609069944f9bed10cb43870634c0cb713e8e99d0e9d
MD5 906f6a5fb6965a834cb8470ee1b760f2
BLAKE2b-256 40dba8de666ccd66b0dec3339a538ad56cd0c7383ca4bdefae2266d5db23a493

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-3.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 0a045e065ea7670f29585dd3dc2f973c6a3243cdd15cbbbbff2fde280a3d8aec
MD5 eb5355597064295e401a5371b60191a9
BLAKE2b-256 03ff5cfc200d214936309a460bb9eed098d52cdc078295f96ceb112620c44b38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1e7f1f57ae8c52ec2ac986df4fe5394a824a02c4c04e98e3cd81b0ca4e828545
MD5 46b2828df42f1f8cbc63eb4e7b55c571
BLAKE2b-256 7b00e55ae76d12259a9455e66999d6adbd9d43e4363ec109e0d81fe0c6419906

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c7458f583dd70f2001834bfd9d110df26ebe8b02e7029d5542d4625b6eb8e99
MD5 ff6b242a1b932ee347941e422c4e3feb
BLAKE2b-256 b665b35444655f7ba1f7931f8e23878e13e0622a2c736a47c87d50612b8b730e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-3.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 596676961ae24ad49ba7ed6b312fa66b9106daa574914813d024fdf29f0ce710
MD5 0364ddf1da6e5cb667c9924b32f65d24
BLAKE2b-256 a1aec21fa2cafd05aa5304a8acfd1e0e2e28259812cea5c892c0807d98b99961

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