Skip to main content

Python library for parsing module definitions and instantiations from SystemVerilog files

Project description

pysvinst

License: MIT Actions Status codecov PyPI version

This Python library examines SystemVerilog files to determine what modules are defined and what modules are instantiated. The backend uses sv-parser, which has good support of SystemVerilog 2017.

Purpose

The Verilog language has contains features for defining configs and libraries. However, these features are not well-supported by open-source tools, and even some commercial synthesis tools. By extracting a list of modules defined and instantiated in a file, a user can work around this problem by constructing their own design hierarchy outside of Verilog, and then passing that list of files back into the simulator / synthesis tool.

Installation

This package can be installed via pip:

> pip install svinst

Alternatively, you can clone the repository and build the package yourself. This requires that Rust is installed.

> git clone https://github.com/sgherbst/pysvinst.git
> cd pysvinst
> pip install -e .

Usage

The main functionality of this package is provided through the function get_defs. In this first example, a list of module definitions is returned, each one containing a list module instantiations (if any) contained in that module definition.

>>> from svinst import get_defs
>>> defs = get_defs('tests/verilog/test.sv')
>>> _ = [print(str(def_)) for def_ in defs]
ModDef("A", [
])
ModDef("B", [
])
ModDef("C", [
  ModInst("A", "I0"),
  ModInst("B", "I1")
])
ModDef("D", [
  ModInst("X", "I0"),
  ModInst("Y", "I1")
])

It is also possible to add define variables and include directory paths, since both of these can change the modules that get defined and instantiated:

>>> get_defs('tests/verilog/inc_test.sv', includes=['tests/verilog'])
>>> get_defs('tests/verilog/def_test.sv',
             defines={'MODULE_NAME': 'module_name_from_define', 'EXTRA_INSTANCE': None})

If there is a syntax error, an error message is printed and an Exception is raised.

>>> get_defs('tests/verilog/broken.sv')
parse failed: "tests/verilog/broken.sv"
 tests/verilog/broken.sv:5:10
  |
5 | endmodule
  |  

Finally, the user can get a full syntax tree for advanced processing, using the command get_syntax_tree. That command also allows the arguments includes and defines.

>>> from svinst import get_syntax_tree
>>> tree = get_syntax_tree('tests/verilog/simple.sv')
>>> _ = [print(elem) for elem in tree]
SyntaxNode("SourceText", [
  SyntaxNode("Description", [
    SyntaxNode("ModuleDeclaration", [
      SyntaxNode("ModuleDeclarationAnsi", [
        SyntaxNode("ModuleAnsiHeader", [
          SyntaxNode("ModuleKeyword", [
            SyntaxNode("Keyword", [
              SyntaxToken("module", line=1)
            ])
          ]),
          SyntaxNode("ModuleIdentifier", [
            SyntaxNode("Identifier", [
              SyntaxNode("SimpleIdentifier", [
                SyntaxToken("A", line=1)
              ])
            ])
          ]),
          SyntaxNode("Symbol", [
            SyntaxToken(";", line=1)
          ])
        ]),
        SyntaxNode("Keyword", [
          SyntaxToken("endmodule", line=2)
        ])
      ])
    ])
  ])
])

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

svinst-0.1.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

svinst-0.1.5-cp37-cp37m-manylinux1_x86_64.whl (10.9 MB view details)

Uploaded CPython 3.7m

svinst-0.1.5-cp37-cp37m-macosx_10_14_x86_64.whl (9.6 MB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

File details

Details for the file svinst-0.1.5.tar.gz.

File metadata

  • Download URL: svinst-0.1.5.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for svinst-0.1.5.tar.gz
Algorithm Hash digest
SHA256 0d3607be591684fa022d9b52e5d92dae0aa77bf8f23991ade9a986cd1ba3adf3
MD5 de18b81bc049de7c7200855a8df14299
BLAKE2b-256 e1a00edfd0999b5c7cc3c63d7cf8ad576048fde4447c9652a00c4825cff294d9

See more details on using hashes here.

File details

Details for the file svinst-0.1.5-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: svinst-0.1.5-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 10.9 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for svinst-0.1.5-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 be52da357daed8750457b0524940624fadc7a341b52632d007b795475bc2edd4
MD5 d15fc0f1c0bb3093e256bc3627c83de7
BLAKE2b-256 3c79e6d64469fc299b3884d540d890912301fc97c6c9f19f7d4c5d843d4a8985

See more details on using hashes here.

File details

Details for the file svinst-0.1.5-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: svinst-0.1.5-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 9.6 MB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for svinst-0.1.5-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 f5b8bfa50d9c13d1eb9ad66481fc045b86b9e394dee9ada03be2dc51b62299fd
MD5 65d72091ad44657ad410a8b645d71978
BLAKE2b-256 b290b006f59c72d2288127af2235d55095cac748a3fba382222272219b4381f3

See more details on using hashes here.

Supported by

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