怎样在systemverilog DPI中调用SV,C与C++(一)
2014-06-06 11:59
656 查看
网上有些例子只给了简单的print,文档里也只有在module中调用c,c中用module的函数,不能充分说明问题。既然希望在C里调用C++的函数,那么肯定要能访问到C++类里的变量那才有意义。这里给出一个简单的例子,示例代码如下:
调用关系:
top call sv_print();
top call c_print();
c_print() call c_print_call();
c_print() call cpp_print();
相较c调用c++, c++调用c会简单很多,详情请查看参考文献2.
参考文献:
1. SystemVerilog DPI (Direct Programming Interface) VCS 2006.06-SP2-2 by:Synopsys, Inc.
2. C++项目中的extern ”C“ {}by:吴秦
调用关系:
top call sv_print();
top call c_print();
c_print() call c_print_call();
c_print() call cpp_print();
// top.v module top; string s; c_sv sv_inst; import "DPI-C" function void c_print(input string s); initial begin s = "Hello DPI"; sv_inst = new(); sv_inst.sv_print(s); c_print(s); end endmodule
//c_dpi.c void c_print(const char* s) { c_print_call(s); cpp_print(s); }
//c_dpi_call.c #include <stdio.h> void c_print_call(const char* s) { printf("C:\t%0s\n", s); }
//cpp_dpi.cpp #include <stdio.h> #include <iostream> #ifdef __cplusplus extern "C" { #endif class c_cpp{ public: c_cpp(); ~c_cpp(); char* get_string(); private: char* prefix; }; void cpp_print(char* s); #ifdef __cplusplus } #endif using namespace std; c_cpp::c_cpp() { prefix = "CPP:\t"; } c_cpp::~c_cpp(){ } char* c_cpp::get_string(){ return prefix; } void cpp_print(char* s) { c_cpp inst; char* prefix; prefix = inst.get_string(); cout << prefix << s << endl; }
//sv_dpi.sv class c_sv; function new(); endfunction : new function void sv_print(string s); $display("SV:\t%0s", s); endfunction : sv_print endclass
相较c调用c++, c++调用c会简单很多,详情请查看参考文献2.
参考文献:
1. SystemVerilog DPI (Direct Programming Interface) VCS 2006.06-SP2-2 by:Synopsys, Inc.
2. C++项目中的extern ”C“ {}by:吴秦
相关文章推荐
- 怎样在systemverilog DPI中调用SV,C与C++(二)
- ncverilog 使用 systemverilog DPI调用C、C++
- 怎样在C中调用C++函数
- c++调用shell 或者dos命令—使用system函数
- C++使用system带参数调用exe程序并把结果输出到文件
- [system]c/c++调用cat命令
- SV通过DPI调用C
- ASP.NET中启用Windows集成验证,怎样在调用System.DirectoryServices下的组件时传递安全上下文,也就是说当前用户凭据,来实现权限管理
- Linux下c++调用自己编写的matlab函数:通过shell script system command实现
- RSA crt 签名与验签 systemverilog DPI 制作以及openssl genrsa生成RSA私钥与签名验证指令dgst使用
- linux系统下,c++程序,调用system命令失败,分析过程
- c++里的system()函数调用系统命令如何获取打印信息
- C++使用system带参数调用exe
- C++ 调用system()函数的多命令合并
- 关于在C++中调用system函数
- 怎样编写能够被C调用的C++函数
- C++使用system带参数调用exe
- c++怎样让返回对象的函数不调用拷贝构造函数
- c++怎样调用类的静态方法
- paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之全0/1/z/x的SV写法