Import Example Using -sv_lib, -sv_liblist, and -sv_root - 2022.1 English

Vivado Design Suite User Guide: Logic Simulation (UG900)

Document ID
UG900
Release Date
2022-04-21
Version
2022.1 English

Code

Assume that there are:

  • Two files each containing a C function
  • A SystemVerilog file that uses the following functions:
    • function1.c
    • function2.c
    • file.sv

function1.c

#include "svdpi.h"
DPI_DLLESPEC
int myFunction1()
{
    return 5;
}

function2.c

#include <svdpi.h>
DPI_DLLESPEC
int myFunction2()
{
    return 10;
}

file.sv

module m();
import "DPI-C" pure function int myFunction1 (); 
import "DPI-C" pure function int myFunction2 ();
integer i, j;
initial
begin
#1;
  i = myFunction1();
  j = myFunction2();
  $display(i, j);
  if( i == 5 && j == 10)
    $display("PASSED");
  else
    $display("FAILED");
end
endmodule

Usage

Methods for compiling and linking the C files into the Vivado simulator are described below.

Single-step flow (simplest flow)

xsc function1.c function2.c
xelab -svlog file.sv -sv_lib dpi

Flow description:

The xsc compiler compiles and links the C code to create the shared library xsim.dir/xsc/dpi.so, and xelab references the shared library through the switch -sv_lib.

Two-step flow

xsc -compile function1.c function2.c -work abc
xsc -shared/-shared_systemc abc/function1.lnx64.o abc/function2.lnx64.o -work abc 
xelab -svlog file.sv -sv_root abc -sv_lib dpi -R

Flow description:

  • Compile the two C files into corresponding object code in the work directory abc.
  • Link these two files together to create the shared library dpi.so.
  • Make sure that this library is picked up from the work library abc via the -sv_root switch.
    Tip: -sv_root specifies where to look for the shared library specified through the switch -sv_lib. On Linux, if -sv_root is not specified and the DPI library is named with the prefix lib and the suffix .so, then use the LD_LIBRARY_PATH environment variable for the location of shared library.

Two-step flow (same as above with few extra options)

xsc -compile function1.c function2.c -work "abc" -v 1
xsc -shared/-shared_systemc "abc/function1.lnx64.o" "abc/function2.lnx64.o" -work "abc" -o final -v 1 
xelab -svlog file.sv -sv_root "abc" -sv_lib final -R

Flow description:

If you want to do your own compilation and linking, you can use the -verbose switch to see the path and the options with which the compiler was invoked. You can then tailor those to suit your needs. In the example above, a distinct shared library final is created. This example also demonstrates how spaces in file path work.