How to Work with Preprocessed Files in the DVT IDE for VS Code

Overview

This video covers how to use DVT IDE for VS Code with SystemVerilog source files which contain preprocessing code written in a different language, like python and jinja, perl or any other language. The support allows users to benefit from DVT features like hyperlinks, content assist and errors as you type even in files which are not pure SystemVerilog.

This video was shot using DVT 24.1.4 and VS Code 1.81.1.

VS Code Tasks details: https://dvteclipse.com/demo-movies/dvt-ide-for-vs-code-tasks-how-to-run-external-tools

Details

Introduction

This video covers how to use DVT IDE with SystemVerilog source files, which contain preprocessing code written in a different language, like Python and Jinja, Perl, or any other language.

In a typical flow, the source files get preprocessed and pure SystemVerilog code is generated. Subsequently, all tools in the toolchain, like the compiler, simulator, or linter, actually use the generated files.

Sections of code that will be preprocessed will have distinct background highlight, helping you quickly identify and differentiate them from standard SystemVerilog code.

IDE Capabilities in SystemVerilog Sections

Full IDE capabilities are available when editing inside a pure SystemVerilog section. The IDE immediately flags errors, offers quick fixes, and content assist. Of course, the typical navigation capabilities are also in place, for example, various hyperlinks or searching for usages.

Speaking of navigation, to see the code generated from a particular preprocessing section, use the Peek Definition or Peek Declaration command.

To go from anywhere inside the file to the corresponding generated code section, simply use the DVT Show Generated File command.

Errors in generated sections are back-annotated to the corresponding preprocessed section, allowing for a seamless debugging experience.

To prevent accidental overwrites by the preprocessing tool, generated files are treated as read-only by default. This safeguard ensures your changes are made in the right place.

Configuring Your Project for Preprocessing

Configuring your project for preprocessing is straightforward. In the project's build configuration file, you need to specify the mapping from preprocessed to generated files.

Several mapping types are available:

  • Direct mapping
  • Extension mapping
  • Pattern tag mapping
  • Path prefix mapping
  • Comment mapping, which instructs the tool to figure the corresponding preprocessing file from a header comment in the generated file

Running the Preprocessor on Save

Finally, you can achieve a completely streamlined flow by running the preprocessing tool or script every time you save the file. You just need to define a VS Code task, which calls the preprocessor.

Use the +dvt_pverilog_run_on_save build configuration directive to specify the task label in the project's build file.

Now, every time you edit and save the file, the preprocessing gets executed and any changes are immediately reflected, for example, any new errors.