MCPcopy Create free account
hub / github.com/MikePopoloski/slang

github.com/MikePopoloski/slang @v11.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v11.0 ↗ · + Follow
7,436 symbols 20,739 edges 438 files 785 documented · 11% updated 9d agov11.0 · 2026-05-15★ 1,08516 open issues

Browse by type

Functions 5,397 Types & classes 2,039
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

slang - SystemVerilog Language Services

codecov PyPI License: MIT

slang is a software library that provides various components for lexing, parsing, type checking, and elaborating SystemVerilog code. It comes with an executable tool that can compile and lint any SystemVerilog project, but it is also intended to be usable as a front end for synthesis tools, simulators, linters, code editors, and refactoring tools.

slang is the fastest and most compliant SystemVerilog frontend (according to the open source chipsalliance test suite).

Full documentation is available on the website: https://sv-lang.com

Features

  • Fully parse, analyze, and elaborate all SystemVerilog features - see this page for current status.
  • Be robust about compilation, no matter how broken the source text. This makes the compiler usable in editor highlighting and completion scenarios, where the code is likely to be broken because the user is still writing it.
  • The parse tree should round trip back to the original source, making it easy to write refactoring and code generation tools.
  • Provide great error messages, ala clang.
  • Be fast and robust in the face of production-scale projects.

Use Cases

Some examples of things you can use slang for: - Very fast syntax checking and linting tool - Dumping the AST of your project to JSON - Source code introspection via included Python bindings - SystemVerilog code generation and refactoring - As the engine for an editor language server - As a fast and robust preprocessor that sits in front of downstream tools - As a frontend for a synthesis or simulation tool, by including slang as a library

Getting Started

Instructions on building slang from source are here. The tl;dr is:

git clone https://github.com/MikePopoloski/slang.git
cd slang
cmake -B build
cmake --build build -j

The slang binary can be run on your code right out of the box; check out the user manual for more information about how it works.

If you're looking to use slang as a library, please read through the developer guide.

Try It Out

Experiment with parsing, type checking, and error detection live on the web (inspired by Matt Godbolt's excellent Compiler Explorer).

Python Bindings

This project also includes Python bindings for the library, which can be installed via PyPI:

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/slang.git
cd slang
pip install .

Example Python 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 discussion thread.

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 is licensed under the MIT license:

Copyright (c) 2015-2026 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.

Core symbols most depended-on inside this repo

Shape

Method 3,661
Class 1,934
Function 1,736
Enum 105

Languages

C++97%
Python3%

Modules by API surface

external/boost_concurrent.hpp1,000 symbols
external/boost_unordered.hpp715 symbols
external/expected.hpp148 symbols
external/BS_thread_pool.hpp106 symbols
include/slang/util/IntervalMap.h100 symbols
source/syntax/SyntaxFacts.cpp99 symbols
source/numeric/SVInt.cpp80 symbols
include/slang/syntax/SyntaxNode.h71 symbols
source/ast/Compilation.cpp65 symbols
source/ast/builtins/SystemTasks.cpp59 symbols
source/ast/builtins/ArrayMethods.cpp57 symbols
include/slang/ast/Compilation.h57 symbols

For agents

$ claude mcp add slang \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page