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-5.0.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

pyslang-5.0.0-cp312-cp312-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12 Windows x86-64

pyslang-5.0.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pyslang-5.0.0-cp312-cp312-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12 macOS 10.15+ x86-64

pyslang-5.0.0-cp312-cp312-macosx_10_15_universal2.whl (5.3 MB view details)

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

pyslang-5.0.0-cp311-cp311-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.11 Windows x86-64

pyslang-5.0.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pyslang-5.0.0-cp311-cp311-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

pyslang-5.0.0-cp311-cp311-macosx_10_15_universal2.whl (5.3 MB view details)

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

pyslang-5.0.0-cp310-cp310-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.10 Windows x86-64

pyslang-5.0.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pyslang-5.0.0-cp310-cp310-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pyslang-5.0.0-cp310-cp310-macosx_10_15_universal2.whl (5.3 MB view details)

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

pyslang-5.0.0-cp39-cp39-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

pyslang-5.0.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pyslang-5.0.0-cp39-cp39-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pyslang-5.0.0-cp39-cp39-macosx_10_15_universal2.whl (5.3 MB view details)

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

pyslang-5.0.0-cp38-cp38-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

pyslang-5.0.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pyslang-5.0.0-cp38-cp38-macosx_10_15_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pyslang-5.0.0-cp38-cp38-macosx_10_15_universal2.whl (5.3 MB view details)

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

pyslang-5.0.0-cp37-cp37m-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.7m Windows x86-64

pyslang-5.0.0-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

pyslang-5.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-5.0.0.tar.gz.

File metadata

  • Download URL: pyslang-5.0.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pyslang-5.0.0.tar.gz
Algorithm Hash digest
SHA256 5124048bc44f0a10e0a8127a64fb4addbd2441ec71fde316e0421cf9005d3ae3
MD5 7ad01e6b011478aca0c186c948496ef6
BLAKE2b-256 17abd79995777be00bab1138f26e2a6d403fbfe0654c478218857dff1c00575e

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyslang-5.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pyslang-5.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 908fb71ddc34f8931cd0fda5981167a4fa6998751d1928132880fa24bf09f410
MD5 1abd94f15b588b70dbca8e5656b80db4
BLAKE2b-256 92f108bd73bc6b9951969bae711a7aff779c7f1eaa4a25b35453d6a79117d8a8

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b587f31e01e26170bebb7280b86435a3de1c1368234ee4cfd365ba31d0773cb3
MD5 0237a5dd37d6f5af43f88deec83a1b43
BLAKE2b-256 14f9f81fbfa49fe6ad3e195d2f14ff5d5d42f832b087a6db8be078e0ea81c65e

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp312-cp312-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5dbba0880a6b5085447ead35e22741883a7b3d8945d97d16730c49bdb481c7a5
MD5 cc73d1a53db247fdc3409c70305a5056
BLAKE2b-256 1782f958c83781c5882e9bbebaac0cf587e91e292623063cb7ac55fd00c71ce9

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp312-cp312-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp312-cp312-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 1540f905ddc3764c7537a31d65bf166c547cf3047ed74734b50448367935e2ce
MD5 f406db20d1bbfd235e56f9f7ba48066b
BLAKE2b-256 90944c66f16826b3fac2559efff8d63d7f77fc27b664e6f2a9e230d4f7b84345

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyslang-5.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pyslang-5.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e171787cf938857b3142bd2624835b30e8f0a263b16caedbace1e8814bc399bc
MD5 92a222e6b624ed23ce02707011962526
BLAKE2b-256 956d426231e495484abd87a9f6c34c4f8754c87969601e41e440e9965eb87577

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4d1037ece801d68126a4e9c33c5700e4c489cd6e49befc05fc2563547fe4b881
MD5 7292a0b35b5194ad47b4f33296acd35e
BLAKE2b-256 49c3321f4f564a3be1f8a31f2de6daf5398ccd4e53cfe12d0f4a6738177107a5

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp311-cp311-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d47052c16d28903c699da89cc8cf895faf5827cea61ecc7c530898f7e8cab975
MD5 ecac8b3ba0cab35644e897524cfb75e0
BLAKE2b-256 cd47352d81ec9e3d001ea4f6cf3902f7fadc9c251241db263eb77cd203ec0d7f

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp311-cp311-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 0957d0f08e2f01f37a73455596d75a046164efde0fa30ed28cf55747268b54bf
MD5 d8a0ea4256ef715bfa0a728874895eca
BLAKE2b-256 5fb8feded344a8db7e07d4f58cd0c1ba567697c158350cd5eadbb5a43baa2ec4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-5.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 444f9197c82207223ef505bb838a3da8dbb02b427d1ca50aeda4dad377182ad8
MD5 f6f25473a4762bcc166b6c82d9f6e9b1
BLAKE2b-256 35e3c94ed923869443539e5496ee18ff13ce829c015d3a1879995c728065f13b

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 216cab758282c534917a2d9c5880b5632c417bb7e3bd797889b73f96cf2bbde2
MD5 c9c4e73ec5a9cd7d592dd490cfbd5d4f
BLAKE2b-256 b8a9f64348c296fe4deddb7fc95e7cc58ea301f714a216c5f4a1d9a1d34396f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-5.0.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 320b319101abfd68790f55780025af28451c128408b17cc65afdfe3cc28e9afd
MD5 f593a3d5175abb20d2cf387265ee86c1
BLAKE2b-256 643fa089617b4015e98f5ef532d90edb985cfc35a39bf334b04f2e51524f3237

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-5.0.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 688a7615dc0c990549c7f3b1f9d362e2784d99c521b545eb78fa44634c013a1c
MD5 be196a92d87fc5206116e4a3b94905ad
BLAKE2b-256 0a83fd5d8fb4e9c7a04393b37743f54c7da53e88ac4b3a2b65b66e024222af86

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-5.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d8382086e1c28f3d36ae01524d35e450c38ae3fb466ffd8d2eb1b8096748fbdf
MD5 f5a45f166dcf8830b85957ea8e6c07dc
BLAKE2b-256 bad07ff2d3d34ba58593caf49bcd5c3b74c50627994e706aebd0a6b894d9b3ae

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6239829d497bf2ef4de65f4cd299b3f95663a10bd8c63d30d006e46812a4ec5b
MD5 71aa0c8e1f08e4aee6be16cae64c2051
BLAKE2b-256 2abd0e62f357304be30e936a088912e58cf668445c026beefa4b218c2dbf00cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-5.0.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e5386c36e80cf4ddcb36be4004566dc343f5759fd279e6a8c8a804f0692695da
MD5 6c05f182db948e7a04f25efea1a09572
BLAKE2b-256 ff17f4cee907e0ec545d48fe4a59dfdae70feb553df2833f06ea1f5e70767a05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-5.0.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 0c4157c364276b183a44799aac588703fb949491ad057f30e4954af914c99d9e
MD5 fe80df4486025794e1ea095b252ea4d2
BLAKE2b-256 7920cf97573bdc9b75161ca0137f98d24d8afc52d4f2b55b579dd909521459e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-5.0.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pyslang-5.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5f196983a238542bd3136c160b61dfd56eaf6bf834e9421e02ea3fe6bc6240b0
MD5 41e9824a190e2d7226fc9caafeb55d32
BLAKE2b-256 f8d387a7d0ac778a919726050113fb7e7c448b7486b94e176626385513d8e6fc

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 00a4319ab820bb9880c4ab9907c76e1da8b4918dd541a0c3b22fe44a6c9dfb80
MD5 6ec2bb544ba84daa2b5f8ed70302599e
BLAKE2b-256 ed9394d8a5aa44974c4ef0da2a93e1c89b6064d5dafbeace7527b5a4b5bdb90c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-5.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 94c0ae8a755af1b55ca0483895ee2e6a3cd973ee778ee6e7e09c4d23a701cd23
MD5 6cdb17f3134cb2764ec63a9aa9066e2d
BLAKE2b-256 acb526ccb50496aaa6be9759abe32582a3cb41bbff7cbb99d08b0517e814cff2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-5.0.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 3f4511f82980a74bdaa85ed144cace03b8119555ea7baa0cfede2b48888af10b
MD5 f17b3bf87ec92ade80ce72d9c2d78b69
BLAKE2b-256 6ccf3fe2068c4a32fbdf546de8c253eb4574b246a4dd80d9f2de7c9785b0335e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-5.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 69d93a6fab1b272126b87eba272fe69403a1f4321094348005f88d6fc82f048e
MD5 09a4bcef404618d815ab1fc7161e14df
BLAKE2b-256 a552b5a8dd010d3f74923b46aad56e6734160d6bad4a9bbe18609014ec00da7f

See more details on using hashes here.

File details

Details for the file pyslang-5.0.0-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyslang-5.0.0-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5bf5d267279d8fe1e29a2522974883243c2d6bcaf53500d1b5b9ab488eec8644
MD5 7fda70004e13da317b832512b92707e4
BLAKE2b-256 c7be476360f142be10ad823d5a7e20cebff41940de7648568d06994d4c75472a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-5.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3443b55af0e46fd00a6add363b02574e5ce302e5c96f8aa11e6f279f8dbdcd2f
MD5 c0e6bea9f948119b63ca17c6c66869e3
BLAKE2b-256 c579acbea633f2a2d71eca5ca317edd2dd01e1a0d99b863cfc5e67181a590262

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