• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Manipulating Strings Using DPI

Stats

  • Locked Locked
  • Replies 0
  • Subscribers 64
  • Views 14076
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Manipulating Strings Using DPI

archive
archive over 18 years ago

I'm sharing this code. This is an example of passing strings back and forth from SystemVerilog and DPI. Some of these features aren't available until IUS6.0. ----file top.v-------- module top (); import "DPI-C" context pass_string_c= task pass_string_sv(input string a); import "DPI-C" context string_c2v_c= function string string_c2v_sv(); string some_string; // This doesnt work in IUS583, will work in IUS6.0 export "DPI-C" print_string_c = function print_string_sv; function void print_string_sv(input string aaa); $display("Exported Verilog String= %s", aaa); endfunction initial begin some_string = "pass it ON"; // enable when running IUS6.0 pass_string_sv(some_string); // pass string to C $display("Verilog: %s \n", string_c2v_sv() ); // get string from C $finish; end endmodule -----file main_task.c----- #include #include // to use io_printf (prints to ncsim.log) #include void pass_string_c(const char* a) { io_printf("DPI: %s\n", a); // now call exported function print_string_c("string passed from C"); // This wont work in IUS583 } const char* string_c2v_c(void) { io_printf("C: give up a string\n"); return "Gimme String"; } -----file: RUN_NC (script)------ rm -r INCA_libs rm *.so rm *.log rm *.h # Create .h file for Exported tasks/functions only # (imported function do NOT need .h file): ncverilog +sv top.v +ncdpiheader+dpi.h +elaborate +ncelabargs+-messages # ncvlog -sv top.v -mess # ncelab top -sv -dpiheader dpi.h -mess gcc -fPIC -shared -o main_task.so main_task.c -I/`ncroot`/tools/inca/include ncverilog +sv top.v +sv_lib=main_task.so +access+r +ncsimargs+"-sv_root ./" ----file: ncverilog.log (IUS6.02)----------- ncsim> run DPI: pass it ON Exported Verilog String= string passed from C Verilog: C: give up a string Gimme String Simulation complete via $finish(1) at time 0 FS + 0 ./top.v:22 $finish; ncsim> exit


Originally posted in cdnusers.org by tmackett
  • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information