41.8 Preprocessed Files Support
This application note describes how to 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:
+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.
+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.
+dvt_pverilog_pattern_tag_map+<(p) pattern1>=<(g) pattern2>
For example:
+dvt_pverilog_pattern_tag_map+<tag>.svp=<tag>_suffix.sv
A (p) file is mapped to a (g) file if their names match the specified patterns, regardless of their location inside the project. A pattern is defined by an alternation of constant fragments and tags.
You may specify this directive multiple times for different pattern pairs.
+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.
+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:
Hyperlink navigation options are available (Open Declaration, Show Usages, etc).
DVT detects the element under cursor by advanced analysis of the diff between the (p) and the (g) files, however in certain situations (for example in case of massive diffs) several hyperlink candidates might be available.
To see the full list, click on
Show more....
From the pop-up dialog, choose the hyperlink navigation option and the element for which it should be applied.
(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.
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.