uvm_dpi——DPI在UVM中的實現(一)

文件:
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源代碼以下: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

3 Verilog PLI已死,SystemVerilog當立.  http://www.doc88.com/p-0867195577584.html
相關文章
相關標籤/搜索