Search code examples
system-verilogsystem-verilog-dpi

how to print from c side with Verilog or SystemVerilog


The question was how to log data from C model into terminal while running test. The answer is using vpi_print in C code instead of regular printf.

I have got some strikes for this question and have desided to make it clear.

The original version is right below

"While using DPI in SystemVerilog I faced an issue to redirect stdout of C side into stdout of SystemVerilog to get all log writes in one place (In my case printf from C were displayed in terminal but not seemed in log file from EDA).

I know the 100% works solution it is export function from SV side and use it in C to print, but it does not seem to me clever.

I tried to use some sort of redirection using reopen functions to changed address stdout var points to (as far as I understand the stdout it is an address for program to write into), but eventually it redirects all logging into this stdout including SystemVerilog log.

What is a better way to keep all logs in one stream?

Maybe there is a way to get C know the IDE stdout?"


Solution

  • The answer had been given by https://stackoverflow.com/users/1143850/serge

    Use vpi_print function from C side. The vpi_print will put its output into the same stream as EDI does