Skip to main content

A framework to integrade scripting into hardware design.

Project description

VeriSnip-Overview

VeriSnip (VS) is a project designed to bring the power of Verilog scripting to the open‑source hardware community. This tool simplifies the generation of Verilog modules or snippets by seamlessly integrating with other programs. The generated files can be easily included in any Verilog project. The motivation behind this work is so that creating hardware modules is a process of creating a template file written in Verilog and letting your programs/scripts generate the hardware. These scripts are included in your Verilog template file using Verilog snippets.

With VeriSnip, the process of calling programs or scripts responsible for generating Verilog files is streamlined. After file generation, VeriSnip neatly organizes all Hardware Description Languages (HDL) and TestBench files under the build directory.

Learn more about how VeriSnip works here.

Index

  1. How to use VeriSnip (vs_build.py)
  2. vs_colours.py
  3. MyLibrary
  4. Opening Issues
  5. Contributing
  6. Development Environment
  7. Credits

How to use VeriSnip (aka, vs_build)

The vs_build script serves as the cornerstone of the VeriSnip tool‑chain, encompassing core functions essential for project compilation. This script orchestrates the creation of the build directory, housing Verilog modules and headers crucial for the project's hardware implementation. The code residing under the ./build directory represents the compiled output ready for simulation and FPGA synthesis.

Run vs_build.py

vs_build must receive at least one argument. To show the help page:

Usage: python vs_build.py --help

Create a build directory containing all the compiled hardware:

Usage: python vs_build.py <main_module> [OPTIONS] [NAME=VALUE ...] <main_module> -> This is the name of the main RTL design. --TestBench <testbench_name> (optional) -> by default vs_build looks for a TestBench file with the name <main_module>_tb. --Boards <board_modules> (optional) -> Space-separated list of board top modules (e.g., "Board1 Board2"). --inc_dir <directories> (optional) -> Space-separated list of include directories. --pre-build <script_path> (optional) -> Path to a script executed before the build. --post-build <script_path> (optional) -> Path to a script executed after a successful build. --quiet (optional) -> suppresses INFO prints. --debug (optional) -> enables DEBUG prints. Parameters: Additional parameters can be passed in the format NAME=VALUE (e.g., WIDTH=8).

Clean the contents generated by vs_build:

Usage: python vs_build.py --clean Removes the "build" and "generated" directories.

Example of calling vs_build: python3 ./*vs_build* top_module --TestBench top_module_tb --Boards "top_module_ecp5" or ./*vs_build* --help

Using Verilog Snippets (.vs)

Users need to include the corresponding .vs file in their Verilog modules to enable VeriSnip to search for or generate a Verilog Snippet. For example:

module example (
  `include "example_ios.vs" // VS_NO_GENERATE
);
  `include "example_contents.vs" /*
    Argument passed to the program/script that generates example_contents.vs
    {MODULE_PARAM}
  */
endmodule

VeriSnip searches for a program or script whose name matches the .vs filename (without the extension). For example, include "example_contents.vs" will match a script named example_contents.* or example.* (any supported extension). Arguments for the script are provided in the comment that immediately follows the include. Enclose module parameters in braces: {...} to replace them by their value before calling the curresponding script.

Since include "example_ios.vs" is followed by VS_NO_GENERATE, VeriSnip will ignore this file and will not attempt to generate it.
The file can be generated later by another include statement if necessary.

For another example, refer to the MyReg module.
You can run vs_build myreg to execute a small build with VeriSnip.

Note: Avoid including a file on the first line of a Verilog source file, as this is not supported.
Instead, use the beginning of the file to provide a brief introduction or description of its contents.

Creating a Compatible Program/Script for Verilog Snippet Generation

Users have the flexibility to create custom programs or scripts for generating ".vs" files or Verilog modules, or they can utilize existing ones. It's crucial to note that all scripts responsible for generating Verilog code, whether modules or ".vs" files, are independent of "vs_build." "vs_build" exclusively calls these scripts without importing them into the project.

Supported File Extensions and Corresponding Languages: Currently, VeriSnip supports programs and scripts with the following file extensions:

  • ".py" for Python
  • ".sh" for Bash
  • ".lua" for Lua
  • ".scala" for Scala
  • ".rb" for Ruby
  • ".pl" for Perl
  • ".vt" for Verilog Template (a custom extension)

The Verilog Template extension (".vt") is specific to VeriSnip. If you compile a program that generates a Verilog module or snippet, you can use the ".vt" extension to enable VeriSnip to locate it.

When vs_build calls another program (see example here), it passes a variable number of arguments. Nevertheless, it always follows the same order. Therefore, take into consideration the following arguments and their order when developing your program or script:

  • Path to the program or script being called
  • Difference between the ".vs" filename and the program/script name. It corresponds to the suffix of the program/script name
  • Comment written after the "`include"
  • File where the include is being called from, therefore the file where the "`include" is written
  • vs_build received arguments (excluding its own name)

Code structure

vs_build code is distinctly divided into three stages.

  • in 1st stage the function find_vs_scripts_and_verilog() finds all existing verilog modules, headers, snippets and scripts under the current directory.
  • the 2nd stage is where it finds the verilog modules and snippets needed by the core. If a verilog module or a snippet does not exist it will try to generate them. The generated snippets should be stored under the ./rtl/generated directory. The function called for this stage is verilog_fetch().
  • during the 3rd stage all verilog snippet files included are substituted for its content. Those files are then stored under the ./build directory.

2nd stage - details

  • When calling scripts to generate ".vs" priority is always given to scripts with the full name of the file. If there is no script corresponding to the ".vs" name look for a script that corresponds only to the initial part of the name. Example:

    • in include "io_modules.vs" look for VTio.py or io.py if io_modules.py does not exist.
  • When calling scripts that generate modules the script should have the name of the module.

  • "vs_build" only calls the scripts if they are newer than the files already existent.

  • When there are two or more scripts with the same name a warning should be printed and the script with the closest directory path should be used.

  • All files and scripts should only be looked for from the base directory of the project, unless specified otherwise in a custom script.

3rd stage - details

  • all files which are generated should have a copy in the "aux" directory
  • "vs_build" substitutes the ".vs" and copies the modules needed to the build directory, after finding or generating all modules and ".vs" files.

vs_colours

This script defines the colors that should be used when printing error, warning or successful messages. It defines the vs_print() function and some variables that allow to modify the text printed to the console.

MyLibrary

The "MyLibrary" directory contains hardware Verilog modules, snippets and scripts that might be commonly reused.

Scripts

This section of the README contains information about the scripts present under the ./library/scripts directory. Read more about each script in the README.md on the scripts directory.

Opening an Issue

Welcome to our issue reporting system! We appreciate your contribution to the project by reporting any issues you encounter. Your feedback helps us make this project even better.

How to Open an Issue

When opening an issue, please follow this format:

Issue Title: A concise and descriptive title for the issue.

Hello Tag the developers you think might be able to help,

Issue Description:

Provide a detailed description of the issue you encountered. Include information about your environment, steps to reproduce the issue, and any error messages. The more details you provide, the easier it is for us to understand and address the problem.

Solution Reference (Optional):

If you have a solution in mind, you're welcome to present it and provide a detailed explanation of why you believe it will work. If possible, include references to supporting pages or documentation that back your proposed solution. This can help us better understand your perspective and expedite the resolution process.

Suggested Changes (Optional):

If you have ideas for changes that might solve the issue, propose them here. Be clear and concise in your suggestions.

Additional Question (Optional):

If you have questions directly or indirectly related to the issue, feel free to ask them in this section.

Tag developers by using @username to get their attention.

We appreciate your help in improving this project!

Contributing

All contributions to this project are warmly welcomed.

Contributions in the form of automatically generated Verilog scripts should be placed within the hardware/scripts directory. Additionally, contributors are required to create a corresponding section in the README when adding a script. This section should detail the generated core and provide instructions on the script's usage. It is important that the section structure aligns with the structures of other script sections.

Development Environment

To utilize vs_build, all that's necessary is Python3 and support for the scripting languages in which your scripts are written.

Credits

This project idea came to me while I was working at IObundle. IObundle was developing a similar open-source tool called python-setup. The two projects are fundamentally different. Therefore I decided to create this project from 0 instead of contributing the ideas and tools directly to IObundle's python-setup.

Where the two projects are similar is both are being developed to generate automatic verilog.

Where they mainly differ is on the way the verilog is generated. The IObundle python-setup project aims to generate all the verilog core using a python framework. VeriSnip aims to substitute the .vs files present on the verilog code, generating the .vs code as needed. There may also exist scripts that generate .v modules.

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

verisnip-0.0.4.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

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

verisnip-0.0.4-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file verisnip-0.0.4.tar.gz.

File metadata

  • Download URL: verisnip-0.0.4.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for verisnip-0.0.4.tar.gz
Algorithm Hash digest
SHA256 56303d9ce831862d0254ce7538a576264d2899b549bbe7bafaadc74ed51f80d9
MD5 b87ffb0143860f7a88016a815208b31c
BLAKE2b-256 f1be0da0e00b2702091638e51751b7d55ff7c780ad17447c9b4c6db696489a45

See more details on using hashes here.

File details

Details for the file verisnip-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: verisnip-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for verisnip-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cf8dbd2216b1642fa30e7f0b8c1eec92fe036e4320e356207420ac08d239b78a
MD5 f04f44de71c5a416fc22d7e0a520b04d
BLAKE2b-256 9210e62a46c0a0db66caf046e0d40694c8d10c241c9e3fe04491278f37d7af66

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