#parser #verilog #systemverilog

app svinst

Determines the modules declared and instantiated in SystemVerilog files, producing a YAML file as output

11 releases

0.1.6 Apr 29, 2021
0.1.5 Nov 10, 2020
0.1.4 Oct 27, 2020
0.1.3 Jul 6, 2020
0.0.5 Mar 3, 2020

#296 in Parser implementations

Download history 11/week @ 2021-08-17 2/week @ 2021-09-07 1/week @ 2021-09-14 11/week @ 2021-09-28 13/week @ 2021-10-12 1/week @ 2021-10-26 3/week @ 2021-11-02 15/week @ 2021-11-09 9/week @ 2021-11-16 13/week @ 2021-11-23 18/week @ 2021-11-30

55 downloads per month

MIT license

678 lines


License: MIT Actions Status codecov Crates.io Join the chat at https://gitter.im/sgherbst/svinst

This tool takes a SystemVerilog file as input and produces as output the module(s) declared in that file, along with the module(s) instantiated in each one of those module declarations. It uses sv-parser and is adapted from svlint.

For those interested to access this functionality from Python, please see pysvinst.


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.


You can download a binary for your system from the Releases tab. This method does not require Rust be installed.

Alternatively, you can install the package with Cargo:

> cargo install svinst


The svinst binary accepts one or more SystemVerilog files as input, and prints a YAML-formatted representation of the modules defined and instantiated in those files:

> svinst verilog/test.sv
  - file_name: "verilog/test.sv"
      - mod_name: "A"
      - mod_name: "B"
      - mod_name: "C"
          - mod_name: "A"
            inst_name: "I0"
          - mod_name: "B"
            inst_name: "I1"
      - mod_name: "D"
          - mod_name: "X"
            inst_name: "I0"
          - mod_name: "Y"
            inst_name: "I1"

If there are any parsing errors, the return code of svinst is nonzero, and the error message(s) will be sent to stderr:

> svinst verilog/broken.sv > /dev/null
parse failed: "verilog/broken.sv"
5 | endmodule
> echo $?

It is also possible to specify files to be included on the command line, via the -i INCLUDE_PATH option. Multiple include paths may be specified; pass each separately via individual -i options.

> svinst verilog/inc_test.sv -i verilog/
  - file_name: "verilog/inc_test.sv"
      - mod_name: "inc_top"
          - mod_name: "mod_name_from_inc_sv"
            inst_name: "I0"

Pre-processor defines can be set from the command line as well. In this example, the first define has both a name and a value, controlling the name of the instantiated module from a define variable. The second define has only a name, and it causes a second module to be instantiated only if it has be defined.

> svinst verilog/def_test.sv -d MODULE_NAME=module_name_from_define -d EXTRA_INSTANCE
  - file_name: "verilog/def_test.sv"
      - mod_name: "def_top"
          - mod_name: "module_name_from_define"
            inst_name: "I0"
          - mod_name: "module_from_ifdef"
            inst_name: "I1"

It is also possible to generate the full syntax tree for SystemVerilog file(s) using the full-tree option. The output is still in YAML format:

> svinst verilog/simple.sv --full-tree
  - file_name: "verilog/simple.sv"
      - SourceText:
        - Description:
          - ModuleDeclaration:
            - ModuleDeclarationAnsi:
              - ModuleAnsiHeader:
                - ModuleKeyword:
                  - Keyword:
                    - Token: "module"
                      Line: 1
                - ModuleIdentifier:
                  - Identifier:
                    - SimpleIdentifier:
                      - Token: "A"
                        Line: 1
                - Symbol:
                  - Token: ";"
                    Line: 1
              - Keyword:
                - Token: "endmodule"
                  Line: 2


~104K SLoC