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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

pyslang-6.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.6 MB view details)

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

pyslang-6.0-cp312-cp312-macosx_10_15_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12 macOS 10.15+ x86-64

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

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

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

Uploaded CPython 3.11 Windows x86-64

pyslang-6.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.6 MB view details)

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

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

Uploaded CPython 3.11 macOS 10.15+ x86-64

pyslang-6.0-cp311-cp311-macosx_10_15_universal2.whl (5.5 MB view details)

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

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

Uploaded CPython 3.10 Windows x86-64

pyslang-6.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.6 MB view details)

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

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

Uploaded CPython 3.10 macOS 10.15+ x86-64

pyslang-6.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-6.0-cp39-cp39-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

pyslang-6.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.6 MB view details)

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

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

Uploaded CPython 3.9 macOS 10.15+ x86-64

pyslang-6.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-6.0-cp38-cp38-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.8 Windows x86-64

pyslang-6.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.6 MB view details)

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

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

Uploaded CPython 3.8 macOS 10.15+ x86-64

pyslang-6.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-6.0-cp37-cp37m-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.7m Windows x86-64

pyslang-6.0-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.7 MB view details)

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

pyslang-6.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-6.0.tar.gz.

File metadata

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

File hashes

Hashes for pyslang-6.0.tar.gz
Algorithm Hash digest
SHA256 0809685eacdd0c28ef51669735ad93244e12bd01fcc8c93ee19587e6fce760cb
MD5 bc3aec59a876f71f3bd072b122d3b5b5
BLAKE2b-256 b57c67a1aaf90f48d2a59bb95816a7aee75c9b6a04305bef90c0f2c09e392aea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-6.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/5.0.0 CPython/3.12.3

File hashes

Hashes for pyslang-6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 56b8066e6c69562ddf3ccc01f32ad1d26f76c487ef49840346d9dd3350e980fa
MD5 d3d67ed4afd39f4f9e785d5741d824f4
BLAKE2b-256 e85ddb28eee377a40e408d56bad8875d8ad5492a9fdbee9b7290e57047fd4186

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b3ebec9d232a3602d130b66a8c994d2987301f109b17c6acbdbceeb84245c75b
MD5 9564814afaa2620fb48a9ee65225ad33
BLAKE2b-256 595a83f531fb1f309514d5b3d14c679504197aba6165d9ca729891f32f935e1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a13f93e9b9f180fb607fc19ff5b42eeac4cc0c4d427a2c056db63ba5d07ceba3
MD5 aa48a8c7b7c170cdf5380d7c2bb463ae
BLAKE2b-256 889ea5b5835e08bff141fa5da66a654a4f95a76062ef891ba8c3778915e9030b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp312-cp312-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 bb29cb8292a70efa38d84964d6a7964e4175a345b5a7887f1b65ebc01ba030fa
MD5 1501f1bad33e6df848a217a1e057e72b
BLAKE2b-256 f0f18be222ca018cba62bfd8ba749ec69bffa65877db9a484db4adb1a4e61760

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-6.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/5.0.0 CPython/3.12.3

File hashes

Hashes for pyslang-6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a894a2f34c84d6da72a4254ec3ef4a1e66e89a73e4f328aaacf24c07a2c758ef
MD5 7b82a4b892695beff48682953ee630f7
BLAKE2b-256 13a0946fbb986b1ddcc84005ffcdd5c50f7fc14b612c6d4d12550d66b627baa7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 78dfd85f6264d0c64ffe4e86955ea69539fdae635d7d887b8211575f6b2a2165
MD5 ecacf45fb86c5daf7ac6318adcc2f64c
BLAKE2b-256 5e5a9c0193a9a0b301e01c5f3d03d12d27da26a244d9d1be8e1b35a65a768124

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 28c5f603b431b2063dd9c07f0daefac58d7ead232972762a80a293d328268ded
MD5 4034ce9896d75eda9df511fba34c0855
BLAKE2b-256 a02657b8c9c1551411ff4cb1bc4fe66775f6ef33eba3693fcf84dd81df5b65cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 09cd6600ab245be023319a73b7aea322e792a106bb902be1cd92175b9bfc7bce
MD5 658b72f1cd7b4511b4af0585394f68a1
BLAKE2b-256 4f8a11c1b2d89145459a33a83c3076b9ed693e3906677a2246c8a790cc609972

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-6.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/5.0.0 CPython/3.12.3

File hashes

Hashes for pyslang-6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3d94d63dcc4aaf59db9e8ad273529815806f0432cfbe4058129136f7c1b26e47
MD5 987d0369552ce2a13b156173c87945a0
BLAKE2b-256 fdebb8c5c8df73abe58c6a02cb8469fc739d7eda11979dbba981349f031c70b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d620915698b45d5ef8816bcb38b96037da44c511c2ffa59d2e4f62c15f8e1943
MD5 17a95468d1fc4e41714979d1766458e2
BLAKE2b-256 51ca643f46756ec3c680c493034d967c06f9a1d6bb687cd438ae565d3256fe6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d24d9b912a916ab81939911ca604a562aab9e13a240719a5bca31c70b9baed54
MD5 746b7cd6d61bd82f3c0c0dce176b941c
BLAKE2b-256 09041c98fbcd78b7344ca6465b9e7bb9cab4f42906456d470aba3a5023fe0381

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 e71b1a7d0d973bd50999775df2f512587c912f8369880b39c7f8d070b42beb22
MD5 4a0fbabb7a04334035a3207b6290287c
BLAKE2b-256 96d078f234ec77a760ce506d130027bcf8d09fbe884c12a5725aa52e84c65fc4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-6.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 146619fd6fabd3a564667201f06882eed102a7990c7a178256e0007553dd507a
MD5 e6bc69b5f05890ec375238b43fcaaeec
BLAKE2b-256 87ce4b6f36f9da5399376faa02fa6d45dcae2703485b4738b1ee06c97d9556e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bd664a8de43f58cf740718c624036e4ba4ded635673352d40415aa84bceec1d8
MD5 ed87022724599186414a21aa7be738e2
BLAKE2b-256 48fc4ad5678db0d84f0b52e155f2459b7de2e8446f2609f6826452f7f4136c2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0f90703c1bb1806113fed9ad07ba726035c7d81f655bccaaa485d34bf727ec6c
MD5 12bd1006bf4a684867c409ed6a7aae18
BLAKE2b-256 2ece5dfd7a6899a8d42ac03f1fa7ccd6a9d4356d095eb9899cb5c6efa32a5d20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 14ba45b7bdffdf4c094bdde4848a15474a1b735991729c0fb52fe043a05c3a52
MD5 cbc35663aca23ca8ed3a0ae908306f99
BLAKE2b-256 947ca276aa072766f3fbbc3e9f8d6237f3ee95af33f94317d67dc7bf3313b581

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyslang-6.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/5.0.0 CPython/3.12.3

File hashes

Hashes for pyslang-6.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c922f4e9f2320a171de9bbc8c52eeaf6f35fa445848e1edabc926e63857c22b0
MD5 c8cf887da8cfd967f871fa138cac2f94
BLAKE2b-256 3c600f3cb0973a6993d172ce8d20dc9830719c344181d5dd20f9094a0efab554

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4760e01ad02b4819f498e2972514f33d9147c1332fea526ad9a6035a0b4b72e0
MD5 65f497ff4f68850e19577abf8d5b598d
BLAKE2b-256 4c20f24dce638befd9a5a92467604bb5dc839174006805a270ca1f4445515a45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0b1326f14cfe74e4d2a35a5838f5af33b2acc4feb1bd3fce3ffaa87f07556cc0
MD5 a33136baa680a352107379f6a66ee05a
BLAKE2b-256 bd4f7fe8dde84ced7eed06622d59cc13a7bb71724e72b8a6bb7580dd025040ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 2f383f18523c2f8da8ed1d3a1bf3a62904565f09db32ec91cae912be5f2ee249
MD5 fc55c9e4e5a00df28a3ae004ce3512a9
BLAKE2b-256 8a0d06def15f664fc22ae61e2743ff51e39ec245463e0dac554fcd644fbdf81f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyslang-6.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 30ec45e094f65593fba629fc5f731dc1f574a530253ab47722bc682202f9943e
MD5 ca091e00e3e0d8082af09b8b46507b99
BLAKE2b-256 0ab9b441eded9c25bbfcb01a5fcc1c3546cfcdcef02e0ffacf55b832dd8057ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1c09aef1848eac8b9460625c4472db058579da0017c2833a2e82f7ea6f2fd3b1
MD5 6e87d2e3b09eec4cba786e3c51a88fcd
BLAKE2b-256 3fdc5af3241f7e268ba7165fa8c17553cadf362e4a0c300197b0d168c12a7af4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyslang-6.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 6ac7b13177f7b432866f3f1bcc7bc6fd692a4df8e59c477e2bcd854b127527e8
MD5 d757c0c9be0ebadc1370f31aec2ff9c9
BLAKE2b-256 681fa76780a1a5b92da813c53c76f3818e3c96a51adb9c5b8ee6351313c88d5d

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