2

I have some verilog VPI code that I'm porting to use SystemVerilog DPI, to be run in Modelsim and Verilator.

In VPI, I use vpi_printf() for debugging and status information. This doesn't work when running the DPI in Verilator. Should I just be using regular printf() instead?

(This feels like it ought to be a simple question, but good SystemVerilog examples seem to be scarce)

pjc50
  • 46,725
  • 4
  • 65
  • 126

1 Answers1

6

DPI doesn't have special print commands. You can use regular C printf() or std::cout << "Your Message Here" << std::end. Some reasonable tutorials can be found with your preferred search engine with [systemverilog dpi] as your search term.

If you want to be lazy, you can keep #include <vpi_user.h> in your DPI files to keep using vpi_printf()

Alternatively, have your DPI call a SV function. With this method, adding the simulator's time-stamp is possible. Example:

my_sv.sv:

// ...
export "DPI-C" function dpi_print;
function void dpi_print(input string msg);
  $display("%t :: %s", $time, msg);
endfunction : dpi_print
// ...

my_dpi.c :

#include <stdlib.h>
#include <stdio.h>
#include "svdpi.h"
...
extern dpi_print(const char* msg);
....
int some_c_func( /* ... */ ) {
  // ...
  dpi_print("message");
  // ...
}
Greg
  • 4,333
  • 1
  • 22
  • 32
  • When I am using vpi_printf(), the printed message is complete in the terminal, however, when saved as a logfile by Verdi simulator, it is truncated to ~70 characters. Any ideas why? – Nazar Nov 15 '21 at 17:54