文件:
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 = ;
static const int M_UVM_WARNING = ;
static const int M_UVM_ERROR = ;
static const int M_UVM_FATAL = ; static const int M_UVM_NONE = ;
static const int M_UVM_LOW = ;
static const int M_UVM_MEDIUM = ;
static const int M_UVM_HIGH = ;
static const int M_UVM_FULL = ;
static const int M_UVM_DEBUG = ; 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 = ;
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

uvm_dpi——DPI在UVM中的实现(一)的更多相关文章

  1. uvm_hdl——DPI在UVM中的实现(四)

    我们可以在uvm中实现HDL的后门访问,具体包括的function有uvm_hdl_check_path,uvm_hdl_deposit, uvm_hdl_force,uvm_hdl_release, ...

  2. uvm_regex——DPI在UVM中的实现(三)

    UVM的正则表达是在uvm_regex.cc 和uvm_regex.svh 中实现的,uvm_regex.svh实现UVM的正则表达式的源代码如下: `ifndef UVM_REGEX_NO_DPI ...

  3. uvm_svcmd_dpi——DPI在UVM中的实现(二)

    UVM中有需要从cmmand line 输入参数的需求,所有uvm_svcmd_dpi.svh和uvm_svcmd_dpi.cc 文件就是实现功能. uvm_svcmd_dpi.svh的源代码如下,我 ...

  4. UVM中的class

    UVM中的类包括:基类(base)------------uvm_void/uvm_object/uvm_transaction/uvm_root/uvm_phase/uvm_port_base 报告 ...

  5. UVM中的sequence使用(一)

    UVM中Driver,transaction,sequence,sequencer之间的关系. UVM将原来在Driver中的数据定义部分,单独拿出来成为Transaction,主要完成数据的rand ...

  6. UVM中的regmodel建模(三)

    总结一下UVM中的寄存器访问实现: 后门访问通过add_hdl_path命令来添加寄存器路径,并扩展uvm_reg_backdoor基类,定义read与write函数,最后在uvm_reg_block ...

  7. UVM中的regmodel建模(一)

    UVM中的regmodel继承自VMM的RAL(Register Abstract Layer),现在可以先将寄存器模型进行XML建模,再通过Synopsys 家的工具ralgen来直接生成regmo ...

  8. UVM中factory机制的使用

    UVM中的factory机制一般用在sequence的重载,尤其是virtual sequence.当Test_case变化时,通过virtual sequence的重载,可以很容易构建新的测试. 因 ...

  9. UVM中的factory机制实现

    首先在Systemverilog中便有对于重载的最基本的支持. 1)定义task/function时,使用virtual关键字.那之后在test_case中调用时,便使用句柄指向的对象的类型而不是句柄 ...

随机推荐

  1. Ping++中的AlipaySDK和AlicloudUTDID冲突解决方案

    今天维护一个老项目发现阿里框架冲突 问题截图: 解决方案: 去阿里文档中心 https://docs.open.alipay.com/54/104509 重新下载没有UTDID冲突的库 下载SDK解压 ...

  2. Python中配置文件解析模块-ConfigParser

    Python中有ConfigParser类,可以很方便的从配置文件中读取数据(如DB的配置,路径的配置).配置文件的格式是: []包含的叫section, section 下有option=value ...

  3. 反射实现数据库增删改查DAO及DAOImpl源代码(二)

    配置文件源码 配置文件主要用于配置数据库对象(javaBean),配置表名,配置查询条件,配置删除条件 文件名称:objectConfigPath.properties 这个配置文件里面配置的是另外一 ...

  4. 洛谷P1275 魔板

    P1275 魔板 题目描述 有这样一种魔板:它是一个长方形的面板,被划分成n行m列的n*m个方格.每个方格内有一个小灯泡,灯泡的状态有两种(亮或暗).我们可以通过若干操作使魔板从一个状态改变为另一个状 ...

  5. [Xcode 实际操作]四、常用控件-(3)UILabel文本标签的使用

    目录:[Swift]Xcode实际操作 本文将演示标签控件的基础用法, 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit class Vie ...

  6. 开发整理-Javaweb应用的系统升级功能

    web应用有一个功能菜单是系统升级,通过调用升级脚本,将新发布的war替换原来的tomcat的webapps下的应用,然后停掉tomcate,再重启tomcate.最初实现就是通过简单的用在web项目 ...

  7. AngularJs详细

    正经的来啦 (MVC) View(视图), 即 HTML. Model(模型), 当前视图中可用的数据. Controller(控制器), 即 JavaScript 函数,可以添加或修改属性. 修改了 ...

  8. POJ1321-棋盘问题

    题目链接:点击打开链接 Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和 ...

  9. css奇技淫巧之—多列等高

    什么是等高布局? 先来看一个案例: 上图中的页面的主体内容是两列结构,左列是用来导航的,右列是用来显示内容的.我们看到它们有一个共同的边框,中间还有一条分隔线,左右两列的高度都是不固定的.这种情况下就 ...

  10. angular学习笔记【ng2-charts】插件添加

    原文:https://segmentfault.com/a/1190000008077830 1. 安装 ng2-charts npm install ng2-charts --save2. 还必须引 ...