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

Uploaded Source

Built Distributions

pyslang-4.0.0-cp311-cp311-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.11 Windows x86-64

pyslang-4.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-4.0.0-cp311-cp311-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

pyslang-4.0.0-cp311-cp311-macosx_10_15_universal2.whl (5.4 MB view details)

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

pyslang-4.0.0-cp310-cp310-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

pyslang-4.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-4.0.0-cp310-cp310-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

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

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

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

Uploaded CPython 3.9 Windows x86-64

pyslang-4.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-4.0.0-cp39-cp39-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

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

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

pyslang-4.0.0-cp38-cp38-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.8 Windows x86-64

pyslang-4.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-4.0.0-cp38-cp38-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

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

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

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

Uploaded CPython 3.7m Windows x86-64

pyslang-4.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-4.0.0-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-4.0.0.tar.gz.

File metadata

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

File hashes

Hashes for pyslang-4.0.0.tar.gz
Algorithm Hash digest
SHA256 952460e9fe9f3f3a7b11c90506235fc5e91ae08323e5ed13ff334d8e90da398e
MD5 7e3cfce397ea20ba5a606e46e983eaca
BLAKE2b-256 86ba93b183fbd36153a9a320aaa3c9c09ba603af642bbf384201493735edef31

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-4.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 40f6a5f00f3cca138153787e17133a515ba730c95415de678d66b72eff116a52
MD5 ea7eee1912d83929f60d74b73aa63d04
BLAKE2b-256 d08b826764fac7c72099c3fcbfc557a11f32a138b0d2576ab018463431f64f5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ee951e06a12a82b066455919bad8528f7a5a28f40ee5f51e78a8462d6a779d65
MD5 5e70c518d8322869c20ac2f352e7dc7a
BLAKE2b-256 36e1d5975e7c4adb656a207adde01839900147a8bc528211b0d366d5dab21a4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 baed62f6d0a096a815fabaaf8c57d4bf24db5693e9f6154186e76f6869c5f4ff
MD5 a4701d5f233a93341e4ec13a3c58d726
BLAKE2b-256 cec75088257064115e8482d5eebfae9c733877756a9a05004e8d43246a30d9c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 27bada0cbc08eca855feb4dbb3935203cf20508e165334fb8ac5c6c6a7202f54
MD5 c9f0ceaa24910beefc43b8a83468323a
BLAKE2b-256 8d0f1ad5ffa893f9213110d7aa8d80b566208bb13f4fea4abd5e0f661e3f6c29

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-4.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f516f1c9d0a59053616e0a4755e4654d83437ebf69fb688baecb51f85ecb0a9d
MD5 f52f425601a8854b72479f266f057b2a
BLAKE2b-256 7f90754275811b383450a6f749e40aa78dd1a0c473219fce41a0f7e067e89e26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1ec2edab32db3904541312a31cecf655652cfadff501804c9593556cb89333c3
MD5 69a91ceab0a91d1c95c164a95fe89ed7
BLAKE2b-256 e53ea2a3f90a1d649fb064791da9105b19906e71811facbf31ceb880773faad3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 29a0467d6ff3ae992b9b932dddc38d9c771c30984ae855040cb5ca0814b37c77
MD5 a080011ca6b81db6a76dd0d332b56f21
BLAKE2b-256 9e2f6e62024fbbf69697540e7c34b4c8d3a69d17b86ea679e5cd78bdd5ba4d34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 1d501928dfeb2cd2e246b313dcea8b74f46ddbdc8b44a23d0c22808c86ec9463
MD5 2ce37144549b5046a8fd34f53cf1ee9b
BLAKE2b-256 2db915eff0200c446b20539d0d6b4baae2705421f90eb5d28e7df0ed55edc253

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-4.0.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8cd4d50aade4ded8b73227ca90e3cdfbcc677e749dfb5db193cf8ca05a8f8737
MD5 ef3b00076809b94b3eb0fbb100e17560
BLAKE2b-256 9ed93b875dcdc11081973ed79cade7ead4146d934d43d7ddbd1acbedcda40fa1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 807bbf8753f4fa8ad691ce73983899653706af8a2f6c6debcb99268d1dd40108
MD5 bc1a9988651dfb605e9cc694d90e43fb
BLAKE2b-256 1fd2388b542285114e7482c57bf77bf1437d90f984b8943dd0d694bc5288d3d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 8c4db980249527afdbb1bcf534e4de12ce5cf3df921bcba9939724516d5d147a
MD5 355c76d2a6cc9901a3c2774801f4d525
BLAKE2b-256 49bfeeb64b3bdefb49080c37ebecbc8b3b5e8cb90b07c1420928cc48c9fd28e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 0ca88cf231b3b80599e7ce12fadc7a55fcd7a1447c4b9d3914439ce56ce5ca9e
MD5 a24e8ed8ab0e954305e1845abbbcac0d
BLAKE2b-256 0af938ae6c5c56c7c5a5370ae89a28e652e9592b6dfd05da13d4fbc66d29be60

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-4.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 84a63f477327ec6b696b63f580470518bd1a5d86ed380ce0b0d6d4413601b7e7
MD5 17c00afc0c5938d336a2ac260d4053ff
BLAKE2b-256 33382b6c9ce9e630846248bab7db5507944f80b500f42c9441dc17f9d2293ed5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 82f968f989682eceb4c342868a11fe2f31cf87c34c28f9ef11c87b22c8994b7c
MD5 db9fc6919e3dc978d78679593c08ebbe
BLAKE2b-256 dd6572033051195db1d9be6e45061462a1f240356d86bbad273bc5375318e4f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f61f2ffb62a14c15c5c508aa13d30841e08aa5771140c4e60fc071ab1c385acd
MD5 e37b36453ffc4012474bbc58acf5a7be
BLAKE2b-256 40621414e4676272c09970c78f2f89bd7e43cbb1d103df2bc1fb63e22f23dec1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 2be4f8d6d6f86e0bea9b2555a18123d12a143528f3b8fe209363de098d96287a
MD5 3c97d35f2ec16f84c8777ee27deb2c5c
BLAKE2b-256 d73ab123b90e8cec473135654fa459507e6b36f91a5d05bf5bbdc36fb407c289

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-4.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 548e0438b2492e76993fa9b6d29d994e61f1dc131eb2adf726c6b057fed8f64d
MD5 8696a0b56fa99149f4dec7cf9d25655e
BLAKE2b-256 9fc757de6f3711151f891153779803980191a11ccf031ae5c85101315034c05a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0277d0bc544d08e9118688d65209e450a08902adb6ddec1d16f9e5407f07a0db
MD5 22cc5b45c3a91c766d7f319c3358bd92
BLAKE2b-256 4509fabf46fe487b61d2b4d3ac4abb3a93d699b762987936fb60c6734b5b8836

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-4.0.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a6b1730ff5d49db9c72780af23ca2fc3f2cebe66f4a6dd0b370f60f47c8ac17e
MD5 dc8455f251ebc3ac2d89717b7d5e582f
BLAKE2b-256 5e7e251d28c91595451e149ead066c377c06d88a761ab4d6000bd47e489ecd4c

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