uvm_dpi.svh源代碼以下:html
`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()函數.ui
// 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; }
參考文獻:this
1 PLI, DPI, DiectC, TLi-1. http://www.cnblogs.com/chenrui/archive/2012/09/18/2689956.htmlspa
2 PLI, DPI, DirectC,TLI - 2. http://www.cnblogs.com/chenrui/archive/2012/09/18/2689957.html.net