SystemVerilog通過DPI調用C++


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 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM