uvm_svcmd_dpi——DPI在UVM中的实现(二)
UVM中有需要从cmmand line 输入参数的需求,所有uvm_svcmd_dpi.svh和uvm_svcmd_dpi.cc 文件就是实现功能。
uvm_svcmd_dpi.svh的源代码如下,我们可以看SV采用import的方式导入C代码函数,所有者写函数的实现在uvm_svcmd_dpi.cc 中。当定义了UVM_CMDLINE_NO_DPI的宏时,所有函数返回值要么是NULL,要么是“?”。
// Import DPI functions used by the interface to generate the
// lists. `ifndef UVM_CMDLINE_NO_DPI
import "DPI-C" function string uvm_dpi_get_next_arg_c (int init);
import "DPI-C" function string uvm_dpi_get_tool_name_c ();
import "DPI-C" function string uvm_dpi_get_tool_version_c (); function string uvm_dpi_get_next_arg(int init=);
return uvm_dpi_get_next_arg_c(init);
endfunction function string uvm_dpi_get_tool_name();
return uvm_dpi_get_tool_name_c();
endfunction function string uvm_dpi_get_tool_version();
return uvm_dpi_get_tool_version_c();
endfunction import "DPI-C" function chandle uvm_dpi_regcomp(string regex);
import "DPI-C" function int uvm_dpi_regexec(chandle preg, string str);
import "DPI-C" function void uvm_dpi_regfree(chandle preg); `else
function string uvm_dpi_get_next_arg(int init=);
return "";
endfunction function string uvm_dpi_get_tool_name();
return "?";
endfunction function string uvm_dpi_get_tool_version();
return "?";
endfunction function chandle uvm_dpi_regcomp(string regex); return null; endfunction
function int uvm_dpi_regexec(chandle preg, string str); return ; endfunction
function void uvm_dpi_regfree(chandle preg); endfunction `endif
看完了uvm_svcmd_dpi.svh的源代码,让我们再看看uvm_svcmd_dpi.cc的源代码,这里面的函数是采用vpi方式实现的。
#include "uvm_dpi.h"
#include <assert.h> #define ARGV_STACK_PTR_SIZE 32 // the total number of arguments (minus the -f/-F minus associated filenames)
int argc_total;
// the ptr to the array of ptrs to the args
char** argv_stack=NULL; char ** argv_ptr=NULL; void push_data(int lvl,char *entry, int cmd) {
if(cmd==)
argc_total++;
else
*argv_ptr++=entry;
} // walk one level (potentially recursive)
void walk_level(int lvl, int argc, char**argv,int cmd) {
int idx;
for(idx=; ((lvl==) && idx<argc) || ((lvl>) && (*argv));idx++,argv++) {
if(strcmp(*argv, "-f") && strcmp(*argv, "-F")) {
push_data(lvl,*argv,cmd);
} else {
argv++;
idx++;
char **n=(char**) *argv;
walk_level(lvl+,argc,++n,cmd);
}
}
} const char *uvm_dpi_get_next_arg_c (int init) {
s_vpi_vlog_info info;
static int idx=; if(init==)
{
// free if necessary
free(argv_stack);
argc_total=; vpi_get_vlog_info(&info);
walk_level(,info.argc,info.argv,); argv_stack = (char**) malloc (sizeof(char*)*argc_total);
argv_ptr=argv_stack;
walk_level(,info.argc,info.argv,);
idx=;
argv_ptr=argv_stack;
} if(idx++>=argc_total)
return NULL; return *argv_ptr++;
} extern char* uvm_dpi_get_tool_name_c ()
{
s_vpi_vlog_info info;
vpi_get_vlog_info(&info);
return info.product;
} extern char* uvm_dpi_get_tool_version_c ()
{
s_vpi_vlog_info info;
vpi_get_vlog_info(&info);
return info.version;
} extern regex_t* uvm_dpi_regcomp (char* pattern)
{
regex_t* re = (regex_t*) malloc (sizeof(regex_t));
int status = regcomp(re, pattern, REG_NOSUB|REG_EXTENDED);
if(status)
{
const char * err_str = "uvm_dpi_regcomp : Unable to compile regex: |%s|, Element 0 is: %c";
char buffer[strlen(err_str) + strlen(pattern) + ];
sprintf(buffer, err_str, pattern, pattern[]);
m_uvm_report_dpi(M_UVM_ERROR,
(char*)"UVM/DPI/REGCOMP",
&buffer[],
M_UVM_NONE,
(char*) __FILE__,
__LINE__);
regfree(re);
free (re);
return NULL;
}
return re;
} extern int uvm_dpi_regexec (regex_t* re, char* str)
{
if(!re )
{
return ;
}
return regexec(re, str, (size_t), NULL, );
} extern void uvm_dpi_regfree (regex_t* re)
{
if(!re) return;
regfree(re);
free (re);
}
uvm_svcmd_dpi——DPI在UVM中的实现(二)的更多相关文章
- uvm_hdl——DPI在UVM中的实现(四)
我们可以在uvm中实现HDL的后门访问,具体包括的function有uvm_hdl_check_path,uvm_hdl_deposit, uvm_hdl_force,uvm_hdl_release, ...
- uvm_dpi——DPI在UVM中的实现(一)
文件: src/dpi/uvm_dpi.svh 类: 无 SystemVerilog DPI,全称SystemVerilog直接编程接口 (英语:SystemVerilog Direct Pro ...
- uvm_regex——DPI在UVM中的实现(三)
UVM的正则表达是在uvm_regex.cc 和uvm_regex.svh 中实现的,uvm_regex.svh实现UVM的正则表达式的源代码如下: `ifndef UVM_REGEX_NO_DPI ...
- C#中的线程二(Cotrol.BeginInvoke和Control.Invoke)
C#中的线程二(Cotrol.BeginInvoke和Control.Invoke) 原文地址:http://www.cnblogs.com/whssunboy/archive/2007/06/07/ ...
- C语言中如何将二维数组作为函数的参数传递
今天写程序的时候要用到二维数组作参数传给一个函数,我发现将二维数组作参数进行传递还不是想象得那么简单里,但是最后我也解决了遇到的问题,所以这篇文章主要介绍如何处理二维数组当作参数传递的情况,希望大家不 ...
- UVM中的class
UVM中的类包括:基类(base)------------uvm_void/uvm_object/uvm_transaction/uvm_root/uvm_phase/uvm_port_base 报告 ...
- IT公司100题-35- 求一个矩阵中最大的二维矩阵(元素和最大)
问题描述: 求一个矩阵中最大的二维矩阵(元素和最大).如: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 中最大的是: 4 5 9 10 分析: 2*2子数组的最大和.遍历求和,时 ...
- C++中的异常处理(二)
C++中的异常处理(二) 标签: c++C++异常处理 2012-11-24 20:56 1713人阅读 评论(2) 收藏 举报 分类: C++编程语言(24) 版权声明:本文为博主原创文章,未经 ...
- c#中的linq二
c#中的linq二 using System; using System.Collections.Generic; using System.Linq; using System.Text; us ...
随机推荐
- 【机器学习】关联规则挖掘(二):频繁模式树FP-growth
Apriori算法的一个主要瓶颈在于,为了获得较长的频繁模式,需要生成大量的候选短频繁模式.FP-Growth算法是针对这个瓶颈提出来的全新的一种算法模式.目前,在数据挖掘领域,Apriori和FP- ...
- 在VM12中安装ubuntu系统下的VMTOOLS
转载自http://www.jb51.net/article/97387.htm 一.下载Ubuntu镜像: Ubuntu官网下载地址 二.创建虚拟机 打开VMware Workstation,点击创 ...
- PCC-S-02201, Encountered the symbol "DB_USER_OPER_COUNT"
今天编译PROC程序时,遇到这个错误.最后发现原因是.pc文件里声明变量块时,不识别结构体. 今天时间紧知识用第一种方法暂时解决了.晚上抽时间用第二种方法优化一下代码. 查了很多资料,发现只有这个答案 ...
- 【QtAV】QtAV中的工厂模式
QtAV中的各个模块大量使用的工厂模式,下面对其实现进行介绍. 工厂模式的使用 以 VideoRenderer 类为例子,他含有下面3个工厂模式相关的方法,Register方法用于给一个产品<c ...
- POJ 2398 Toy Storage (叉积判断点和线段的关系)
题目链接 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4104 Accepted: 2433 ...
- 【hibernate-笔记】
//1 创建,调用空参构造 Configuration conf = new Configuration().configure(); //2 根据配置信息,创建 SessionFactory对象 S ...
- 线程池和Thread
1.线程池 创建线程需要时间.如果有不同的短任务要完成,就可以事先创建许多线程,在应完成这些任务时发出请求.这个线程数最好在需要更多线程时增加,在需要释放资源时减少.不需要自己创建这样一个列表.该列表 ...
- Fiddler开启Https的时候出现unable to configure windows to trust Fiddler Root certificate问题
前言 通过log页面看到错误为:访问控制列表(ACL)结构无效. 网上(baidu,bing,google)各种方式都试过了: 如重置证书(Reset all certificates) 导出证书到本 ...
- Postman使用-2
转载:https://www.cnblogs.com/yunman/p/7884537.html Postman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件. 接口请求流程 一.g ...
- Note: OBLIVIATE: A Data Oblivious File System for Intel SGX
OBLIVIATE redesigned ORAM for SGX filesystem operations for confuse access patterns to protect user ...