DVT SystemVerilog IDE User Guide
Rev. 19.1.34, 11 October 2019

41.3 Preprocessed Files Support

This application note describes how use DVT with source files which contain preprocessing code in a general-purpose scripting language like perl, python, ruby or php.

A tool applies preprocessing and the resulting SystemVerilog files are actually compiled and simulated.

For simplicity, files containing preprocessing code are referred to as (p) files while generated files are referred to as (g) files.

Configure DVT to compile the generated (g) files

In order to provide advanced functionality (like hyperlinks, autocomplete, design and class hierarchy, error signaling, etc.) DVT must analyze the generated (g) source code files.

If the preprocessing (p) files are provided for analysis instead, DVT will trigger syntax errors, since the files do not have a valid SystemVerilog syntax, and functionality within these files (and possibly others) might be broken.

Map preprocessing (p) to generated (g) files

You must specify how (p) files are mapped to (g) files using one of the following build configuration directives in .dvt/default.build:

  • Direct mapping

   +dvt_pverilog_map+<(p) file path>=<(g) file path>

For example:

   +dvt_pverilog_map+$SOURCE/file.svp=$GENERATED/file.sv

You may specify this directive multiple times for several file pairs.

  • Map by extension

   +dvt_pverilog_ext_map+<(p) files extension>=<(g) files extension>

For example:

   +dvt_pverilog_ext_map+.svp=.sv

A (p) file is mapped to a (g) file if they have the same basename and mapped extensions, regardless of their location inside the project. If multiple such files exist, there is no guarantee on the chosen pair.

You may specify this directive multiple times for different extension pairs.

  • Map by path prefix

   +dvt_pverilog_path_map+<path prefix of (p) files>=<path prefix of (g) files>

for example:

   +dvt_pverilog_path_map+${PREPROCESS_SOURCE}=${PREPROCESS_TARGET}

A (p) file is mapped to a (g) file if they have the same subpath relative to the (p) path prefix respectively to the (g) path prefix.

You may specify this directive multiple times for different path prefix pairs.

  • Map by comment

   +dvt_pverilog_comment_map+"<pattern>"

For example:

   +dvt_pverilog_comment_map+"Source file: (?<PFILE>\S+)"

The mapping is inferred from the (g) file, assuming it contains a comment pointing to the corresponding (p) source file.

Specify a regular expression pattern containing a named capturing group called PFILE. The pattern is applied to all comments at full build time.

To debug use:

   +dvt_pverilog_comment_map_debug

Debug information will be printed in the DVT Build Console.

Using the PVerilog editor

Whenever you open a (p) or (g) file (from any view, or by jumping into it with a hyperlink) it gets opened using the PVerilog editor.

It's a multi-page editor which provides a convenient way to work with preprocessed/generated code. It has 3 tabs:

  • (p) - Shows the preprocessing file with syntax highlighting. None of the advanced navigation and editing features of DVT are available.

  • (g) - Shows the generated code in a regular SystemVerilog editor. All of the advanced navigation and editing features of DVT are available (hyperlinks, autocomplete, erros as you type etc). Whenever you edit this file, a visual indicator reminds you that the file is generated.

  • Compare - A compare viewer of the (p) and (g) files. It is editable and allows you to move pieces of code between the two files. The (p) and (g) editors are synchronously scrolled.

A possible usage flow is to edit/debug code in the (g) tab of the PVerilog editor, and thus benefit from all the advanced DVT functionality. When done, quickly bring (p) and (g) files into sync using the compare viewer's "Copy from ..." buttons.

Integration of the preprocessing tool

You can define a DVT Generic Run Configuration to invoke the preprocessing tool.

You can instruct DVT to run this configuration every time you save the preprocessing file either in the (p) or © tab of the PVerilog editor. Use this directive in the .dvt/default.build build configuration file:

   +dvt_pverilog_run_on_save+run_preprocess
   +dvt_pverilog_run_on_save+"run configuration name"

Note that you need to enclose the run configuration name in quotes if it contains whitespace characters.

The run configuration script or command can use the following environment variables:

$DVT_PVERILOG_G_FILE

path to the generated (g) file

$DVT_PVERILOG_P_FILE

path to the preprocessing (p) file

Tip For convenience you can also use a custom toolbar button to quickly apply preprocessing.