uvm_dpi——DPIのUVMにおける実現(一)

12628 ワード

ファイル:
src/dpi/uvm_dpi.svh
クラス:
なし
 
  SystemVerilog DPI,フルネームSystemVerilogダイレクトプログラミングインタフェース(英語:SystemVerilog Direct Programming Interface)は、SystemVerilogと他の外来プログラミング言語とのインターフェースである.使用可能な言語としては、C言語、C++、SystemCなどがある.直接プログラミングインターフェースは、2つの階層で構成されている:SystemVerilog層と外来言語層.2つの階層は互いに分離されている.SystemVerilogでは、反対側で使用されるプログラミング言語は透明であるが、それはこの点に注目していません.SystemVerilogと外来言語のコンパイラはそれぞれ別の言語のコードを分析する必要はありません.SystemVerilogレイヤには触れないため、異なる言語の使用がサポートされています.ただし、SystemVerilogは現在、C言語に対して外来言語層を定義しているだけです.したがって、各関数DPIのファイルには*がある.svhと*.ccの2つのファイル、まず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 
#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は標準ライブラリより多く、「uvm_dpi.h」ヘッダファイルと「uvm_common.c」ソースファイルです.
uvm_を見てみましょうdpi.hヘッダファイル(C言語のコードスタイル*.cファイルごとに*.hファイルが構成されている)は、m_uvm_report_dpiとint_str_max()関数が宣言されている.この2つの関数の定義は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 
#include "vpi_user.h"
#include "veriuser.h"
#include "svdpi.h"
#include <malloc.h>
#include <string.h>
#include 
#include 
#include 

// 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
転載先:https://www.cnblogs.com/dpc525/p/8066104.html