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

Uploaded Source

Built Distributions

pyslang-7.0-cp312-cp312-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.12 Windows x86-64

pyslang-7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.9 MB view details)

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

pyslang-7.0-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pyslang-7.0-cp312-cp312-macosx_10_15_universal2.whl (6.0 MB view details)

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

pyslang-7.0-cp311-cp311-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.11 Windows x86-64

pyslang-7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.9 MB view details)

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

pyslang-7.0-cp311-cp311-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pyslang-7.0-cp311-cp311-macosx_10_15_universal2.whl (5.9 MB view details)

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

pyslang-7.0-cp310-cp310-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.10 Windows x86-64

pyslang-7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.9 MB view details)

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

pyslang-7.0-cp310-cp310-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pyslang-7.0-cp310-cp310-macosx_10_15_universal2.whl (5.9 MB view details)

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

pyslang-7.0-cp39-cp39-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.9 Windows x86-64

pyslang-7.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.9 MB view details)

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

pyslang-7.0-cp39-cp39-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pyslang-7.0-cp39-cp39-macosx_10_15_universal2.whl (5.9 MB view details)

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

pyslang-7.0-cp38-cp38-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.8 Windows x86-64

pyslang-7.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.9 MB view details)

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

pyslang-7.0-cp38-cp38-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pyslang-7.0-cp38-cp38-macosx_10_15_universal2.whl (5.9 MB view details)

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

pyslang-7.0-cp37-cp37m-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.7m Windows x86-64

pyslang-7.0-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.0 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for pyslang-7.0.tar.gz
Algorithm Hash digest
SHA256 4f493d96d1735fdc725acb52d605b86a421ca91fbc04483fb427a0cc1648467c
MD5 0f98333f4842373a7ed340bbaa9fa0b4
BLAKE2b-256 a9f215572dceac317dceb8f95fd96e599a0fdacad94d61cc22ecd22886c63049

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-7.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pyslang-7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 96bd76e93e75142a01ba712654cd7e1268fc5bce756e6142af263e3a7c992335
MD5 a3a377b9bfa1ef7086a1ae216c13a1e5
BLAKE2b-256 c0c882d50fc491a67352a97d1937a6722163428ac17f09f86a5f29379134a9b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 293538566a01dc465348062428e5994c70b55171f0a6f0a637f55abb0b14e4d8
MD5 09e4898ee966b9ed0e2826287319dea6
BLAKE2b-256 91eed213b57bd4aa0dc6ae06a36297b47364d0e1ada1ef29f365548ec147c676

See more details on using hashes here.

File details

Details for the file pyslang-7.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyslang-7.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fd17b09743fe4041e94437cb1d8f3ebe31a91ebe37775bc58e8205fa434710fb
MD5 a757bdcbcb1c5081b64c4db9138effc0
BLAKE2b-256 78ede4f75eaf07dbda2648cbd3ace691cbe4bfa8a19550872293cbc31a3c3aea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp312-cp312-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 ba5c9619197d95f2cd8f82fa9a0f1e3e9778833934309dbf8895f9551fe0e548
MD5 ed232f36050ee02bf25a9065e57315b3
BLAKE2b-256 03f49e4e7b81a3052e3aae0b5355825e76924ee96978ae4d7352a7bb530d9d3a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-7.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pyslang-7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7d85f43b6c67042dcc75eeeea9ba4369438fd8712742bf0d264a4f472623dddb
MD5 a55a6409171e4fbe47132143faa94cfa
BLAKE2b-256 7d74f9ed2be883623cabd86141fad921a9022d3876cc132c0c33dafd2c7bad96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 22746a2de37ea27cf0bec318b9ffeb4c0876659b546e6358bc62e7f8a9331289
MD5 0e06c1614c605138adbe704489302936
BLAKE2b-256 d315aec4ce646d3ef0c5521bb11c68a4170220873e2939f3a4bd44c7c6dad031

See more details on using hashes here.

File details

Details for the file pyslang-7.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyslang-7.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 84d33f3f653d10d80f7605473b101d584d76413c37235794f88e427b3bd97d6d
MD5 a23cdcda7be26dc0d4d899c636a03bd9
BLAKE2b-256 c8edd7312bf34474e06a51f228cf21365371398895c6e4ff1aac9592d88c5435

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 a7d8a1e0f55082f9de6f7e515ff5a1777955ad277c2044ef0d30a4d446a6bc2c
MD5 1c6aa6d1aca49e8736e03eb50cd424c7
BLAKE2b-256 8d8836c2da964772ad6efc6659efa5be5ce87495bbf287a958f50aa6d84ae997

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-7.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pyslang-7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a1b5e5a70cc59735f4fc101356ec411bbd42338a1a6496a8763e730f8107ed0c
MD5 76eeec9075c1d13d6b77d8b1c7e5999a
BLAKE2b-256 e0294494fbfc825ba5e72bf005683897b784d09fb43fb8aa7cd6ad8c6ef46905

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 82e38044045ac3dcc98808e4acf1d2f4b639ad793ebe822a81f6e4e630010056
MD5 81737f2014bea79e721bbbc33a44c323
BLAKE2b-256 806acae145a971f51b7eb0bb0a0a8fa08b48d11b8ea58c3f3ffce66c805b6ce0

See more details on using hashes here.

File details

Details for the file pyslang-7.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyslang-7.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a5e605eef9c55d835cdf5c0eef2be094140a9be0fb264772202ce7dea156fa7
MD5 70334acce32d0c1c270c5714f2f27f2f
BLAKE2b-256 81a8c9fb2c460b25bebe357676b62d25799cacad14ca1adc0c6ac08cdc0b12bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 2719fe4a8cbb53fa5ee18aec266cf13c32b381e317708f8a4bdcf7e0eb6bfca0
MD5 0971c951346a945e9fe7cd67db08b82f
BLAKE2b-256 64f26e292bc295d89e99aa745169910f7d7d143c61026f42b6e4290f9596fe8a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-7.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pyslang-7.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 17a638ea1c5987310fb29a5913f9a3277db60c8b83ed8fec8e5ef52c1b291294
MD5 88dbe66c04c2a2fe6779896329d81a7a
BLAKE2b-256 f8b510f0bdc85d24a3738c88f618372d8e5f8c598f26dcbf2b53cf48212d718e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0b9d7abaf86a65ec542460ecbbd9d7a41715ca0f935ffb92f8a3fbffe0793c47
MD5 beebc6e7e1634d0c93c5a65bb6646484
BLAKE2b-256 02f5c19216f48d5c9e6779681b310f190022edb574b0bb1b9b6a1fe55fe68203

See more details on using hashes here.

File details

Details for the file pyslang-7.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyslang-7.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d11979fbb8684c7e8f5b95dd9cc0b77773459fff0e9485d558faf350eee5ba7
MD5 fcb86f79b69bf6f741b2f6c20f9e5988
BLAKE2b-256 550d597755bc87781034a9edc451972b04ad896b2698baefe69289f143d962d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 52f5f59e2b6301b9670ddde781449e0b8c580a000761b3824d3c24941fb4eb03
MD5 07b77aee071c4f628a5398bf80e62526
BLAKE2b-256 749cb16b623126d1a6b4cb02285278b77cf775872b7986825384ce95b446222e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-7.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pyslang-7.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f25dfd4bc0d500c4e45b1549427f4f69e4a0408f909b5175e43439c7ce68a4c0
MD5 156ce009fa9350301d41463f98e9a2ed
BLAKE2b-256 c64577908fadea2ca2821c40ea65dbcfd6264c664fd174a698876fb2fc333898

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a64fd3eb30180ab546e72b033997f1b703ea5b073058e410ae6847a1ae6b4de7
MD5 b8564ba507242d738104a4d29591eb13
BLAKE2b-256 dcbe55b3dc192dc610190fe840f400f48d6722b4f27b24abc6a329b31223307a

See more details on using hashes here.

File details

Details for the file pyslang-7.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyslang-7.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 562f0831f1987d2cb24c9f9141703ba98bbf6aa1aac9ee93f1a5a25c19189b7e
MD5 408d9e539009167202654403d487ae07
BLAKE2b-256 bee842c08259c017966b65338b3757768cb08543666443dfe5d0cccb8d74a4a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 714c51d8f0c164c52f1f4e6acabd44071d505e728fc8bdedcbaa27f3fbf4107b
MD5 0933fe03840252105382995edb9ffce8
BLAKE2b-256 ca69baef84b568ad080a43af1f9db04cab991a6b90c908a1a56a178f9a1c12c3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-7.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 96903a654f541442b7b54da5bca04bd3767d439f6c255b27bd6bf533e2676e2b
MD5 2c94fca73a76a6f690bfe074f40ac7c5
BLAKE2b-256 9de1411e4040965eeba5077d280f77d8a4476461ab2b33b0fb9cc44a0673fa8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-7.0-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 63c2fdd09126f5f8a86ab38c7b2ff5f6a9a4e832ff229dcf51ae7df560606ec1
MD5 96576564ddff5d4345e9be30a08f7cb8
BLAKE2b-256 3cd1d9e7fe189e2ad253e345ec10a0380fccfcf7cf5c4a9f79e69f9fa6a586e6

See more details on using hashes here.

Supported by

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