### Install Slang using CMake Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox Install the slang library using CMake. The --prefix option can control the installation location. ```bash cmake --install build --strip ``` -------------------------------- ### Install fmt Library Targets and Headers Source: https://github.com/mikepopoloski/slang/blob/master/external/CMakeLists.txt Installs targets and headers for the fmt library if it was not found. This ensures the fmt library is available after installation. ```cmake if(NOT fmt_FOUND) install( TARGETS fmt EXPORT slangTargets LIBRARY COMPONENT slang_Development ARCHIVE COMPONENT slang_Development PUBLIC_HEADER EXCLUDE_FROM_ALL PRIVATE_HEADER EXCLUDE_FROM_ALL) install( DIRECTORY ${fmt_SOURCE_DIR}/include/fmt DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT slang_Development) endif() ``` -------------------------------- ### Install Executable Source: https://github.com/mikepopoloski/slang/blob/master/tools/hier/CMakeLists.txt Installs the hier executable to the system's binary directory if the SLANG_INCLUDE_INSTALL option is enabled. ```cmake if(SLANG_INCLUDE_INSTALL) install(TARGETS slang_hier RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Install Python Package Marker Files Source: https://github.com/mikepopoloski/slang/blob/master/bindings/CMakeLists.txt Installs the 'py.typed' marker file and the '__init__.py' file for the 'pyslang' package. These are installed as part of the 'pylib' component to the destination directory. ```cmake install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../pyslang/pyslang/py.typed ${CMAKE_CURRENT_SOURCE_DIR}/../pyslang/pyslang/__init__.py COMPONENT pylib DESTINATION .) ``` -------------------------------- ### Install Project Headers Source: https://github.com/mikepopoloski/slang/blob/master/external/CMakeLists.txt Installs project header files to the specified destination directory. This is part of the installation rules for the project. ```cmake install( DIRECTORY ${PROJECT_SOURCE_DIR}/external/ieee1800/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ieee1800 COMPONENT slang_Development) install( FILES ${PROJECT_SOURCE_DIR}/external/expected.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT slang_Development) ``` -------------------------------- ### Define Macro Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/command-line-ref.dox Defines macros with specified values at the start of all source files. Macros without a value default to '1'. ```ansi slang -DFOO=2 -DBAR=asdf -D BAZ=3 ``` -------------------------------- ### Install slang Driver Source: https://github.com/mikepopoloski/slang/blob/master/tools/driver/CMakeLists.txt Installs the slang driver executable to the binary directory if SLANG_INCLUDE_INSTALL is enabled. ```cmake if(SLANG_INCLUDE_INSTALL) install(TARGETS slang_driver RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() ``` -------------------------------- ### Example Slang Tidy Configuration File Source: https://github.com/mikepopoloski/slang/blob/master/tools/tidy/README.md A complete example of a .slang-tidy configuration file, showcasing the structure with 'Checks' and 'CheckConfigs' sections. ```config Checks: -*, synthesis-only-assigned-on-reset, style-enforce-port-suffix CheckConfigs: clkName: clk, clkNameRegexString: "clk_signal\S*|clock_port\S*", resetIsActiveHigh: false, inputPortSuffix: _k, outputPortSuffix: _p ``` -------------------------------- ### Install Test Dependencies and Run Pytest Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox Install the slang package with test dependencies and execute Python tests using pytest. ```bash pip install '.[test]' pytest ``` -------------------------------- ### Install Pyslang with Caching Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox Install pybind11, scikit-build-core, and the slang package with build isolation disabled and a specified build directory for caching. ```bash pip install pybind11 scikit-build-core pip install . --no-build-isolation --config-settings build-dir=build/python_build ``` -------------------------------- ### Install Pyslang using pip Source: https://github.com/mikepopoloski/slang/blob/master/pyslang/docs/pages/index.rst Install the pyslang library using pip. Use -U to update to the latest release. For local builds, clone the repository and install. ```bash pip install pyslang ``` ```bash pip install -U pyslang ``` ```bash git clone https://github.com/MikePopoloski/slang.git cd slang pip install . ``` -------------------------------- ### Setting Up Diagnostic Engine and Text Client Source: https://github.com/mikepopoloski/slang/blob/master/docs/diagnostic-apis.dox A basic example of setting up a diagnostic engine along with a text client to issue and report diagnostics. ```cpp DiagnosticEngine diagEngine(sourceManager); auto client = std::make_shared(); diagEngine.addClient(client); for (Diagnostic& diag : diags) diagEngine.issue(diag); std::string report = client->getString(); ``` -------------------------------- ### Quick Start Build Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox These commands configure and build the slang library using CMake. The `-j` flag allows for parallel compilation. ```bash cmake -B build cmake --build build -j ``` -------------------------------- ### Static Assertion Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/user-manual.dox Demonstrates the use of $static_assert to perform an elaboration-time check. The example shows a successful assertion and the detailed error output when a comparison fails. ```sv module m; localparam int foo = 12; struct packed { logic [4:1] a, b; } bar; $static_assert(foo < $bits(bar)); endmodule ``` ```ansi test.sv:5:5: error: static assertion failed $static_assert(foo < $bits(bar)); ^ test.sv:5:24: note: comparison reduces to (12 < 8) $static_assert(foo < $bits(bar)); ~~~~^~~~~~~~~~~~ ``` -------------------------------- ### SystemVerilog Container Example Source: https://github.com/mikepopoloski/slang/blob/master/tools/reflect/README.md Demonstrates SystemVerilog packages and modules with public parameters, which slang-reflect will process into C++ headers. ```systemverilog package foo; localparam foo_local /* public */ = 12; endpackage package bar; localparam bar_local /* public */ = 12; endpackage module top; localparam top_local /* verilator public */ = 12; endmodule ``` -------------------------------- ### Run Pyslang Driver Example Source: https://github.com/mikepopoloski/slang/blob/master/pyslang/examples/README.md Demonstrates the simplest way to use pyslang for file processing and error reporting. Run with SystemVerilog files as arguments. ```bash python driver.py ``` -------------------------------- ### Common Slang Options Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/user-manual.dox Demonstrates common slang command-line options including include directories, predefined macros, and warning settings. ```bash > slang myMod1.sv myMod2.sv -I/path/to/includes/ -DMY_MACRO=1 -Wextra -Wno-width-trunc ``` ```bash > slang myMod1.sv myMod2.sv +incdir+/path/to/includes/ +define+MY_MACRO=1 -Wextra -Wno-width-trunc ``` -------------------------------- ### Install Slang Header Directories and Files Source: https://github.com/mikepopoloski/slang/blob/master/source/CMakeLists.txt Conditionally installs Slang header files and directories when the SLANG_INCLUDE_INSTALL CMake variable is set. This ensures development headers are available in the installation path. ```cmake if(SLANG_INCLUDE_INSTALL) install( DIRECTORY ../include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT slang_Development) install( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/slang/diagnostics/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/slang/diagnostics COMPONENT slang_Development) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/slang/syntax/AllSyntax.h ${CMAKE_CURRENT_BINARY_DIR}/slang/syntax/SyntaxKind.h ${CMAKE_CURRENT_BINARY_DIR}/slang/syntax/SyntaxFwd.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/slang/syntax/ COMPONENT slang_Development) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/slang/parsing/TokenKind.h ${CMAKE_CURRENT_BINARY_DIR}/slang/parsing/KnownSystemName.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/slang/parsing/ COMPONENT slang_Development) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/slang/slang_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/slang/ COMPONENT slang_Development) endif() ``` -------------------------------- ### Install pyslang Target Source: https://github.com/mikepopoloski/slang/blob/master/bindings/CMakeLists.txt Installs the 'pyslang' target as part of the 'pylib' component to the root of the installation destination. ```cmake install( TARGETS pyslang COMPONENT pylib DESTINATION .) ``` -------------------------------- ### Install pyslang Python Bindings Source: https://github.com/mikepopoloski/slang/blob/master/README.md Installs the Python bindings for the slang library using pip. This allows for programmatic interaction with slang's SystemVerilog parsing and analysis capabilities. ```bash pip install pyslang ``` -------------------------------- ### Loop Unrolling Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/user-manual.dox Illustrates a SystemVerilog module where procedural for loops are used to assign values to an array. This example highlights how slang's loop unrolling extension allows such code to compile successfully. ```sv module m; int foo[10]; initial for (int i = 1; i < 10; i += 2) begin : baz foo[i] = 2; end for (genvar i = 0; i < 10; i += 2) begin always_comb foo[i] = 1; end endmodule ``` -------------------------------- ### Install Boost Library Targets and Headers Source: https://github.com/mikepopoloski/slang/blob/master/external/CMakeLists.txt Installs targets and headers for Boost libraries if Boost was not found. This includes specific Boost components like unordered and concurrent. ```cmake if(NOT Boost_FOUND) install( TARGETS boost_unordered EXPORT slangTargets COMPONENT slang_Development) install( FILES ${PROJECT_SOURCE_DIR}/external/boost_unordered.hpp ${PROJECT_SOURCE_DIR}/external/boost_concurrent.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT slang_Development) endif() ``` -------------------------------- ### Include Install Rules CMake Module Source: https://github.com/mikepopoloski/slang/blob/master/CMakeLists.txt Includes the 'cmake/install-rules.cmake' module if SLANG_INCLUDE_INSTALL is enabled. This defines project-specific installation rules. ```cmake if(SLANG_INCLUDE_INSTALL) include(cmake/install-rules.cmake) endif() ``` -------------------------------- ### Map Keyword Version Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/command-line-ref.dox Applies a specific SystemVerilog keyword version to files matching a pattern during parsing. This is useful for ensuring compatibility with different language standards. ```command-line --map-keyword-version=1364-2005+...*.v,...*.vh ``` ```command-line --map-keyword-version=1364-2005+/path/to/verilog.v ``` -------------------------------- ### File-Scoped Waiver Examples Source: https://github.com/mikepopoloski/slang/blob/master/docs/waivers.dox Examples demonstrating how to waive diagnostics based on file paths. Includes waiving all diagnostics in specific directories, waiving specific diagnostics in testbench files, and waiving a pattern in a specific file. ```toml # Waive everything in third-party IP [[waivers]] file = "**/ip/**" # Waive unused variables in testbench code [[waivers]] file = "**/tb/**/*.sv" diagnostic = "unused-variable" # Waive a specific pattern in a specific file [[waivers]] file = "**/rtl/core.sv" diagnostic = "unused-variable" regex = '\bdebug_reg\b' ``` -------------------------------- ### Hierarchy-Scoped Waiver Examples Source: https://github.com/mikepopoloski/slang/blob/master/docs/waivers.dox Examples showing how to waive diagnostics based on hierarchical instance paths. Demonstrates waiving in specific instances, subtrees using globs, and combining with regex for specific content. ```toml # Waive width truncation in a specific instance [[waivers]] hier = "top/u_subsys/u_conv" diagnostic = "width-trunc" # Same rule using dot separators [[waivers]] hier = "top.u_subsys.u_conv" diagnostic = "width-trunc" # Waive in a hierarchy subtree using globs [[waivers]] hier = "**/u_debug*" diagnostic = "unused-variable" # Combine with regex to match specific line content [[waivers]] hier = "**/u_debug*" diagnostic = "unused-variable" regex = '\bdbg_status\b' ``` -------------------------------- ### Install Thread Pool Header Source: https://github.com/mikepopoloski/slang/blob/master/external/CMakeLists.txt Installs the BS_thread_pool.hpp header if threading is enabled. This makes the thread pool functionality available for use. ```cmake if(SLANG_USE_THREADS) install( FILES ${PROJECT_SOURCE_DIR}/external/BS_thread_pool.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT slang_Development) endif() ``` -------------------------------- ### Load and Inspect SystemVerilog Syntax Tree Source: https://github.com/mikepopoloski/slang/blob/master/pyslang/docs/pages/index.rst Load a SystemVerilog file and inspect its syntax tree using pyslang. This example shows how to access module information and port declarations. ```python from pyslang.syntax import SyntaxTree tree = 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) ``` -------------------------------- ### SystemVerilog Parameters Example Source: https://github.com/mikepopoloski/slang/blob/master/tools/reflect/README.md Shows a SystemVerilog localparam declared as public, which slang-reflect will transpile into a C++ static constexpr. ```systemverilog package foo; localparam bar /* public */ = 42; endpackage ``` -------------------------------- ### Example of ANSI Port Declaration Merging Source: https://github.com/mikepopoloski/slang/blob/master/docs/command-line-ref.dox This example demonstrates how ANSI port declarations can merge with internal net or variable declarations, a feature supported by some tools but not strictly by SystemVerilog. ```SystemVerilog module m(input a, output b); wire [31:0] a; logic [31:0] b; assign b = a; endmodule ``` -------------------------------- ### Constructing a New Diagnostic Source: https://github.com/mikepopoloski/slang/blob/master/docs/diagnostic-apis.dox An example of constructing a new diagnostic using the Diagnostics class and adding arguments to it. ```cpp Diagnostics diags; Diagnostic& diag = diags.add(diag::SomeDiagCode, location); diag << arg1 << arg2; ``` -------------------------------- ### Library Map File Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/user-manual.dox Define libraries and their associated files using a library map file. This format is specified in the SystemVerilog LRM, section 33.3. ```systemverilog include some/other/lib.map; // Declare a library called "my_lib" with some files in it library my_lib some_file.sv, "all/in/dir/*.sv", other/file2.sv; ``` -------------------------------- ### Pragma Diagnostic Control Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/user-manual.dox Shows how to use slang's `pragma diagnostic` directives to control warning output within specific regions of code. It demonstrates ignoring, pushing, setting to error, and warning for a specific flag. ```sv module m; ; // warn `pragma diagnostic ignore="-Wempty-member" ; // hidden `pragma diagnostic push ; // also hidden `pragma diagnostic error="-Wempty-member" ; // error `pragma diagnostic warn="-Wempty-member" ; // warn `pragma diagnostic pop `pragma diagnostic pop // does nothing ; // hidden again ``` -------------------------------- ### Empty Output Port Connection Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example shows an output port explicitly connected to nothing. The driven value from the module is silently discarded, and this warning highlights this behavior. ```SystemVerilog module m(output logic o); assign o = 1; endmodule module n; m m1(.o()); // driven value is discarded endmodule ``` -------------------------------- ### SystemVerilog Namespace References Example Source: https://github.com/mikepopoloski/slang/blob/master/tools/reflect/README.md Illustrates how slang-reflect handles SystemVerilog namespace references, including including necessary headers for nested types. ```systemverilog package bar; typedef struct packed { logic k; } bar_struct /* public */; endpackage package foo; typedef struct { bar::bar_struct foo_struct; } foo_struct /* public */; endpackage ``` -------------------------------- ### Evaluate SystemVerilog Expressions Source: https://github.com/mikepopoloski/slang/blob/master/pyslang/docs/pages/index.rst Evaluate SystemVerilog expressions using pyslang's ScriptSession. This example demonstrates evaluating an array initialization and a sum reduction. ```python from pyslang.ast import ScriptSession session = 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) ``` -------------------------------- ### SystemVerilog Typedefs and Structs Example Source: https://github.com/mikepopoloski/slang/blob/master/tools/reflect/README.md Demonstrates how slang-reflect resolves SystemVerilog typedefs and emits the base types for struct members. ```systemverilog package bar; typedef enum {ONE = 5, TWO, THREE} my_enum /* public */; typedef my_enum t_enum; typedef struct packed { t_enum e; } bar_struct /* public */; endpackage ``` -------------------------------- ### Unconnected Input Port Warning Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example shows a module instance where an input port is left unconnected and has no default value. This warning flags such instances. ```SystemVerilog module m(input int i); endmodule module n; m m1(); endmodule ``` -------------------------------- ### Missing Member Implementation Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example shows a class with a declared member method but no found implementation. This warning is for compatibility with other tools. ```SystemVerilog module m; class c; extern function int f(); endclass endmodule ``` -------------------------------- ### Enable/Disable Checks and Groups Source: https://github.com/mikepopoloski/slang/blob/master/tools/tidy/README.md Examples demonstrating how to enable or disable specific checks or entire groups of checks within the slang-tidy configuration. ```config Enable a check: synthesis-only-assigned-on-reset ``` ```config Disable a check: -synthesis-only-assigned-on-reset ``` ```config Enable a group: synthesis-* ``` ```config Disable a group: -synthesis-* ``` ```config Enable all: * ``` ```config Disable all: -* ``` -------------------------------- ### Unconnected Unnamed Port Warning Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example shows an unnamed instance port that is left unconnected. The warning helps identify these potentially unintended omissions. ```SystemVerilog module m({a, b}); input a, b; endmodule module n; m m1(); endmodule ``` -------------------------------- ### Analysis Manager Listener Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/overview.dox This snippet demonstrates how to attach a listener to the AnalysisManager to receive callbacks for specific analyzed components, such as procedural blocks. The AnalysisManager must be initialized and a Compilation object must be provided for analysis. ```cpp AnalysisManager am; am.addListener([](const AnalyzedProcedure& proc) { // called for each analyzed procedural block }); am.analyze(comp); ``` -------------------------------- ### Integrate Slang with CMake using find_package Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox Integrate slang into a CMake project by finding the installed package and linking the slang::slang target to an executable. ```cmake cmake_minimum_required(VERSION 3.24) project(example) find_package(slang 1.0.0) add_executable(example example.cpp) target_link_libraries(example PRIVATE slang::slang) ``` -------------------------------- ### Signed vs. Unsigned Comparison Warning Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example shows a comparison between a signed 'int' and an unsigned 'int'. The signed operand is treated as unsigned, potentially leading to unexpected results. This warning helps catch such sign mismatches. ```SystemVerilog module m; int a = -1; int unsigned b = 1; initial begin if (a < b) begin end end endmodule ``` -------------------------------- ### Generate Python Stubs Post-Install Source: https://github.com/mikepopoloski/slang/blob/master/bindings/CMakeLists.txt Installs Python stubs as a post-installation step. It includes a CMake script (`generate_stubs.cmake`) to handle the stub generation process, using the specified Python executable. ```cmake install( CODE " set(STUBGEN_PYTHON_EXECUTABLE \"${Python_EXECUTABLE}\") # Do NOT override CMAKE_INSTALL_PREFIX - the install-time value is correct include(\"${CMAKE_CURRENT_SOURCE_DIR}/generate_stubs.cmake\") " COMPONENT pylib) ``` -------------------------------- ### Build Documentation Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox Enable documentation building by setting the `SLANG_INCLUDE_DOCS` CMake option and then build the documentation target. The output will be in `build/docs/html/`. ```bash cmake -B build -DSLANG_INCLUDE_DOCS=ON cmake --build build --target docs ``` -------------------------------- ### Build slang from Source Source: https://github.com/mikepopoloski/slang/blob/master/README.md Instructions for cloning the repository, configuring with CMake, and building the project. This is useful for developers who need to build slang from its source code. ```bash git clone https://github.com/MikePopoloski/slang.git cd slang cmake -B build cmake --build build -j ``` -------------------------------- ### Set Install RPATH for Shared Libraries Source: https://github.com/mikepopoloski/slang/blob/master/CMakeLists.txt Configures the installation RPATH for shared libraries to ensure they can be found at runtime. Uses @loader_path on Apple and $ORIGIN on other platforms. ```cmake if(NOT CMAKE_INSTALL_RPATH AND BUILD_SHARED_LIBS) if(APPLE) set(base @loader_path) else() set(base $ORIGIN) endif() file(RELATIVE_PATH relDir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) set(CMAKE_INSTALL_RPATH ${base} ${base}/${relDir}) endif() ``` -------------------------------- ### Build Project Source: https://github.com/mikepopoloski/slang/wiki/Build-Reference Build the project using the `make` command. The `-j` flag can be used to parallelize the build process. ```bash make -j 8 ``` -------------------------------- ### Syntax-Only Tools Source: https://github.com/mikepopoloski/slang/blob/master/docs/overview.dox Use this entry point when only the parse tree is needed, such as for building formatters or structural linters. It requires parsing the syntax tree without a full compilation context. ```cpp #include "slang/syntax/SyntaxTree.h" #include "slang/syntax/SyntaxVisitor.h" #include "slang/syntax/SyntaxPrinter.h" using namespace slang::syntax; // Parse from a file. A default SourceManager is used. auto treeOrErr = SyntaxTree::fromFile("input.sv"); if (!treeOrErr) { /* handle OS error */ } auto& tree = *treeOrErr; // std::shared_ptr // Traverse with a SyntaxVisitor. struct MyVisitor : public SyntaxVisitor { void handle(const ModuleDeclarationSyntax& node) { visitDefault(node); } }; MyVisitor visitor; tree->root().visit(visitor); // Print the tree back to source text. auto text = SyntaxPrinter::printFile(*tree); ``` -------------------------------- ### Single Diagnostic Waiver Source: https://github.com/mikepopoloski/slang/blob/master/docs/waivers.dox Example of waiving a single, specific diagnostic within files matching a glob pattern. ```toml # Single diagnostic [[waivers]] file = "**/rtl/**" diagnostic = "unused-variable" ``` -------------------------------- ### Compile and Analyze SystemVerilog File (Success) Source: https://github.com/mikepopoloski/slang/blob/master/docs/user-manual.dox Compile and analyze a valid SystemVerilog file. This command should return zero upon successful build. ```systemverilog // test1.sv module m; struct { logic a; } s; int i = s.a + 1; initial $display("%d", i); endmodule ``` ```ansi > slang test1.sv [93mTop level design units: [0m m [1;32mBuild succeeded: [0m0 errors, 0 warnings > echo $? ``` -------------------------------- ### Run Rewriter Tool Source: https://github.com/mikepopoloski/slang/blob/master/tools/rewriter/README.md Basic usage of the rewriter tool. Specify options and the input file name. ```bash rewriter [options] ``` -------------------------------- ### Multiple Continuous Assignments Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example demonstrates multiple continuous assignments to the same variable, which is an error in SystemVerilog. This warning is for compatibility with other tools. ```SystemVerilog module m; int i; assign i = 1; assign i = 2; endmodule ``` -------------------------------- ### Define Macro Flags Source: https://github.com/mikepopoloski/slang/blob/master/docs/user-manual.dox Define macros at the start of all source files. Supported by both command line and compilation unit listings. ```bash -D,--define-macro = +define+=[+=...] ``` -------------------------------- ### Unused Waiver Summary Source: https://github.com/mikepopoloski/slang/blob/master/docs/waivers.dox When waiver rules go unused, Slang prints a summary. This example shows the default summary output. ```ansi warning: 3 unused waivers (rerun with --print-unused-waivers to list) ``` -------------------------------- ### Unknown Library Configuration Warning Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt Flags a configuration that references an unknown library in its list. Ensure all library names in configurations are valid. ```SystemVerilog config cfg; design d; default liblist foo; endconfig module d; endmodule ``` -------------------------------- ### Lifetime Specifiers on Method Prototypes Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt Lifetime specifiers are not allowed on method prototype declarations in standard SystemVerilog. This example shows a non-standard extension. ```SystemVerilog class C; extern function automatic void foo; endclass function automatic void C::foo; endfunction ``` -------------------------------- ### Using SmallVector and BumpAllocator Source: https://github.com/mikepopoloski/slang/blob/master/docs/common-components.dox Demonstrates building a dynamic list with SmallVector and then copying it into a BumpAllocator. This pattern is useful for constructing lists that will be managed by an arena allocator. ```cpp SmallVector smallVec; smallVec.append(3); smallVec.append(4); smallVec.append(5); BumpAllocator alloc; span finalList = smallVec.copy(alloc); ``` -------------------------------- ### Integrate Slang with CMake using FetchContent Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox Integrate slang into a CMake project by fetching its source from GitHub and building it as part of the project. It's recommended to pin to a specific tag in production. ```cmake cmake_minimum_required(VERSION 3.24) project(example) # Note: this example just pulls the head master branch # for slang, but a real project would very likely pin # this to a specific tag and only update when ready # to accept a new version. include(FetchContent) FetchContent_Declare( slang GIT_REPOSITORY https://github.com/MikePopoloski/slang.git GIT_SHALLOW ON) FetchContent_MakeAvailable(slang) add_executable(example example.cpp) target_link_libraries(example PRIVATE slang::slang) ``` -------------------------------- ### Configure Waivers for Specific Files Source: https://github.com/mikepopoloski/slang/blob/master/docs/waivers.dox This snippet shows how to define a waiver configuration in a .dox file, specifying files to apply waivers to and the diagnostics to be waived. ```toml file = "**/rtl/**" diagnostic = ["unused-variable", "width-trunc"] @endcode ``` -------------------------------- ### Set Default Library Name Source: https://github.com/mikepopoloski/slang/blob/master/docs/command-line-ref.dox Sets the name of the default library. Defaults to 'work' if not specified. ```command-line --defaultLibName ``` -------------------------------- ### Initializer Required for For Loop Variable Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example demonstrates a variable declared in a for loop initializer without an initializer expression, which is required by SystemVerilog. This warning is for compatibility with other tools. ```SystemVerilog module m; initial begin for (int i; i < 4; i++) begin end end endmodule ``` -------------------------------- ### Misplaced Trailing Separator Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example highlights a trailing separator (comma) in a list where it's not allowed by the SystemVerilog standard. This warning is for compatibility with tools like Yosys. ```SystemVerilog module m(input a, output b,); endmodule ``` -------------------------------- ### Clone Slang Repository Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox Use this command to download the slang source code from GitHub. ```bash git clone https://github.com/MikePopoloski/slang.git ``` -------------------------------- ### Conditional Target Setup for External Dependency Source: https://github.com/mikepopoloski/slang/blob/master/external/CMakeLists.txt Sets up the target for an external dependency based on whether it was found or needs to be built. This allows for flexible dependency handling. ```cmake if(tomlplusplus_FOUND) get_target_property(TOMLPP_INC tomlplusplus::tomlplusplus INTERFACE_INCLUDE_DIRECTORIES) message(STATUS "Found system tomlplusplus library: ${TOMLPP_INC}") set(tomlplusplus_target "tomlplusplus::tomlplusplus") else() message(STATUS "Using remote tomlplusplus library") if(IS_DIRECTORY "${tomlplusplus_SOURCE_DIR}") set_property(DIRECTORY ${tomlplusplus_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES) endif() set(tomlplusplus_target "$") endif() ``` -------------------------------- ### Fetch RTLMeter Benchmark Suite with CMake Source: https://github.com/mikepopoloski/slang/blob/master/tests/benchmarks/CMakeLists.txt Use FetchContent to declare and download the RTLMeter benchmark suite from its Git repository. This ensures all necessary RTL source files are available for the build. ```cmake FetchContent_Declare( rtlmeter GIT_REPOSITORY https://github.com/MikePopoloski/rtlmeter GIT_TAG main GIT_SHALLOW ON) FetchContent_MakeAvailable(rtlmeter) ``` -------------------------------- ### Translate Off Format Example Source: https://github.com/mikepopoloski/slang/blob/master/docs/command-line-ref.dox Specifies a custom format for 'translate off' directives within comments to skip processing specific code regions. This is useful for compatibility with legacy code. ```sv module m; // pragma translate_off ... some code to skip ... // pragma translate_on endmodule ``` -------------------------------- ### Extract Logic Names with Pyslang Source: https://github.com/mikepopoloski/slang/blob/master/pyslang/examples/README.md Extracts names of all `logic` declarations from SystemVerilog code using AST traversal. Requires no specific setup beyond running the script. ```python python extract_logic_names.py ``` -------------------------------- ### Non-Standard Bare Associative Array Pattern Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example shows an associative array literal without the apostrophe prefix before the opening brace, which is required by the LRM. Some tools allow omitting it. ```SystemVerilog module m; string s[int]; function void f(); ``` -------------------------------- ### Empty Input Port Connection Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This code demonstrates explicitly connecting an input port to nothing using `.port_name()`. This results in the port receiving its type's default value (e.g., 'x) instead of its declared default. ```SystemVerilog module m(input logic a = 1, input logic b); endmodule module n; m m1(.a(), .b()); // a defaults to 'x, not 1; b also defaults to 'x endmodule ``` -------------------------------- ### Run Slang Tests Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox Navigate into the build directory and execute tests using ctest. The `--output-on-failure` flag shows test output only when a test fails. ```bash cd build && ctest --output-on-failure ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/mikepopoloski/slang/blob/master/docs/building.dox This command sequence creates a Python virtual environment named 'venv' and then activates it. This is recommended for managing Python dependencies. ```bash python3 -m venv venv source venv/bin/activate ``` -------------------------------- ### Conditional pybind11 Status Messages Source: https://github.com/mikepopoloski/slang/blob/master/bindings/CMakeLists.txt Checks if pybind11 was found (e.g., from a system installation) and prints status messages indicating whether a system library is being used or a remote one is being fetched. ```cmake if(pybind11_FOUND) message(STATUS "Using system pybind11 library: ${pybind11_VERSION}") message(STATUS "Using system pybind11 include: ${pybind11_INCLUDE_DIRS}") else() message(STATUS "Using remote pybind11 library") endif() ``` -------------------------------- ### Ineffective Sign Warning Source: https://github.com/mikepopoloski/slang/blob/master/scripts/warning_docs.txt This example demonstrates a non-ANSI port declaration where the signing keyword is specified, but the data type does not permit the signing to take effect. The warning highlights this ineffective signing. ```SystemVerilog module m(a); input unsigned a; int a; endmodule ```