VeriGEN, Versatile Text Generator

VeriGEN is a simple, general-purpose text generation tool that reads any text source and processes the python script embedded within it. The output text is a mixture of original text and python script output.

_images/verigen_logo_1.png

The aim was to create a single-file module that can be easily incorporated in a project build system, for example, CMake.

Project origins

I started this project once I observed quite a frequent need for having portions of source code generated in an automated way during the build process. In the meantime, I was working on open source NVDLA architecture. In their hardware project available on GitHub I found an interesting script called epython. It is exceptionally simple in implementation, but I noticed how powerful it can be when used wisely :).

Here are example use cases from real projects, where I partially managed to use or I have seen used automated code generation:

  1. Given register specification in SystemRDL domain specific language generate:

    • RTL synthesisable register backend
    • RTL simulation test vectors
    • Register documentation
  2. Given domain specific YAML specification with list of process variables:

    • Generate documentation describing each varibale, their limits, measurement unit, etc.
    • Generate C++ and Python wrapper around Redis database communication where process variables are actually stored
    • Generate XML or JSON description file that can be incorporated in third party tools

The RTL code generation is an especially interesting topic. There are already very good tools for interpreting SystemRDL specifications, like systemrdl-compiler.

VeriGEN is not

  • … a runtime engine for dynamic content creation basing on templates. The embedded code execution is not sandboxed, which makes VeriGEN vulnerable when run on untrusted source files.
  • … an alternative to Jinja2 or any similar template engine. Generating C-header files and some restructuredText when building CMake project checked out from controlled repository is probably OK. Generating HTML content basing on user provided input is not OK.