文件:
src/dpi/uvm_dpi.svh
类:
无
SystemVerilog DPI,全称SystemVerilog直接编程接口 (英语:SystemVerilog Direct Programming Interface)是SystemVerilog与其他外来编程语言的接口。能够使用的语言包括C语言、C++、SystemC等。直接编程接口由两个层次构成:SystemVerilog层和外来语言层。两个层次相互分离。对于SystemVerilog方面,另一边使用的编程语言是透明的,但它并不关注这一点。SystemVerilog和外来语言的编译器各自并不需要分析另一种语言的代码。由于不触及SystemVerilog层,因此支持使用不同的语言。不过,目前SystemVerilog仅为C语言定义了外来语言层。所以,每个函数DPI的文件都有*.svh和*.cc 两个文件,首先来看uvm_dpi.svh 该文件秉承了UVM风格,在该文件中实现include dpi目录下的所有文件。
uvm_dpi.svh源代码如下:
`ifndef UVM_DPI_SVH `define UVM_DPI_SVH // // Top-level file for DPI subroutines used by UVM. // // Tool-specific distribution overlays may be required. // // To use UVM without any tool-specific overlay, use +defin+UVM_NO_DPI // `ifdef UVM_NO_DPI `define UVM_HDL_NO_DPI `define UVM_REGEX_NO_DPI `define UVM_CMDLINE_NO_DPI `endif `include "dpi/uvm_hdl.svh" `include "dpi/uvm_svcmd_dpi.svh" `include "dpi/uvm_regex.svh" `endif // UVM_DPI_SVH
uvm_dpi.cc 的源代码如下:
// // Top-level file that includes all of the C/C++ files required // by UVM // // The C code may be compiled by compiling this top file only, // or by compiling individual files then linking them together. // #ifdef __cplusplus extern "C" { #endif #include <stdlib.h> #include "uvm_dpi.h" #include "uvm_common.c" #include "uvm_regex.cc" #include "uvm_hdl.c" #include "uvm_svcmd_dpi.c" #ifdef __cplusplus } #endif
uvm_dpi.cc 和uvm_dpi.svh相比多了<stdlib.h>标准库,"uvm_dpi.h"头文件和"uvm_common.c"源文件。
让我们看看uvm_dpi.h头文件(C语言的代码风格每个*.c文件配置一个*.h 文件),在该文件中声明了m_uvm_report_dpi和int_str_max()函数。这两个函数的定义在uvm_common.c中。
// // Top level header filke that wraps all requirements which // are common to the various C/C++ files in UVM. // #ifndef UVM_DPI__H #define UVM_DPI__H #include <stdlib.h> #include "vpi_user.h" #include "veriuser.h" #include "svdpi.h" #include <malloc.h> #include <string.h> #include <stdio.h> #include <regex.h> #include <limits.h> // The following consts and method call are for // internal usage by the UVM DPI implementation, // and are not intended for public use. static const int M_UVM_INFO = 0; static const int M_UVM_WARNING = 1; static const int M_UVM_ERROR = 2; static const int M_UVM_FATAL = 3; static const int M_UVM_NONE = 0; static const int M_UVM_LOW = 100; static const int M_UVM_MEDIUM = 200; static const int M_UVM_HIGH = 300; static const int M_UVM_FULL = 400; static const int M_UVM_DEBUG = 500; void m_uvm_report_dpi(int severity, char* id, char* message, int verbosity, char* file, int linenum); int int_str_max( int ); #endif
让我们来看看uvm_common.c 的内容,这个文件就是实现了m_uvm_report_dpi()和int_str_max()函数.
// Implementation of common methods for DPI extern void m__uvm_report_dpi(int,const char*,const char*,int,const char*, int); #if defined(INCA) || defined(NCSC) const static char* uvm_package_scope_name = "uvm_pkg::"; #else const static char* uvm_package_scope_name = "uvm_pkg"; #endif void m_uvm_report_dpi( int severity, char* id, char* message, int verbosity, char* file, int linenum) { svScope old_scope = svSetScope(svGetScopeFromName(uvm_package_scope_name)); m__uvm_report_dpi(severity, id, message, verbosity, file, linenum); svSetScope(old_scope); } int int_str_max ( int radix_bits ) { int val = INT_MAX; int ret = 1; while ((val = (val /radix_bits))) ret++; return ret; }
参考文献:
1 PLI, DPI, DiectC, TLi-1. http://www.cnblogs.com/chenrui/archive/2012/09/18/2689956.html
2 PLI, DPI, DirectC,TLI - 2. http://www.cnblogs.com/chenrui/archive/2012/09/18/2689957.html
3 Verilog PLI已死,SystemVerilog当立.
http://www.doc88.com/p-0867195577584.html
4 深入浅出FPGA-18-VPI.
blog.csdn.net/rill_zhen/article/details/21986363