SystemVerilog测试代码:
1 `timescale 1ns / 1ns 2 module dpi_test; 3 4 real a; 5 real s; 6 string str; 7 8 import "DPI-C" function real c_sin(real x); 9 10 initial begin 11 void'($value$plusargs("str=%s", str)); 12 $display("arg = %s", str); 13 14 a = 3.141592654/6.0; 15 s = c_sin(a); 16 $display("s = sin(a) = %f", s); 17 $finish; 18 end 19 20 endmodule
C++程序:
1 #include "svdpi.h" 2 #include "math.h" 3 #include "vc_hdrs.h" 4 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 double c_sin(double x) 10 { 11 return sin(x); 12 } 13 14 #ifdef __cplusplus 15 } 16 #endif
使用VCS编译运行:
cmp: @vcs -LDFLAGS -Wl,--no-as-needed -debug_all +lint=TFIPC-L +lint=PCWM -P ${NOVAS_HOME}/share/PLI/VCS/LINUX/novas.tab ${NOVAS_HOME}/share/PLI/VCS/LINUX/pli.a -sverilog dpi_test.sv dpi_sin.c -top dpi_test -l vcs.log
run: @./simv +str=myars -l simv.log