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中的实现(二)的更多相关文章

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

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

  2. uvm_dpi——DPI在UVM中的实现(一)

    文件: src/dpi/uvm_dpi.svh 类:  无   SystemVerilog DPI,全称SystemVerilog直接编程接口 (英语:SystemVerilog Direct Pro ...

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

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

  4. C#中的线程二(Cotrol.BeginInvoke和Control.Invoke)

    C#中的线程二(Cotrol.BeginInvoke和Control.Invoke) 原文地址:http://www.cnblogs.com/whssunboy/archive/2007/06/07/ ...

  5. C语言中如何将二维数组作为函数的参数传递

    今天写程序的时候要用到二维数组作参数传给一个函数,我发现将二维数组作参数进行传递还不是想象得那么简单里,但是最后我也解决了遇到的问题,所以这篇文章主要介绍如何处理二维数组当作参数传递的情况,希望大家不 ...

  6. UVM中的class

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

  7. IT公司100题-35- 求一个矩阵中最大的二维矩阵(元素和最大)

    问题描述: 求一个矩阵中最大的二维矩阵(元素和最大).如: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 中最大的是: 4 5 9 10   分析: 2*2子数组的最大和.遍历求和,时 ...

  8. C++中的异常处理(二)

    C++中的异常处理(二) 标签: c++C++异常处理 2012-11-24 20:56 1713人阅读 评论(2) 收藏 举报  分类: C++编程语言(24)  版权声明:本文为博主原创文章,未经 ...

  9. c#中的linq二

    c#中的linq二   using System; using System.Collections.Generic; using System.Linq; using System.Text; us ...

随机推荐

  1. JavaScript中创建对象的三种模式

    JS中,便于批量创建对象的三种模式: 1.工厂模式:用一个函数封装创建对象的细节,传入必要的参数,在函数内部new一个对象并返回. 缺点:创建的对象无法识别类型(全是Object) 2.构造函数模式: ...

  2. bash字符串匹配

    #!/bin/shfoo(){    local basedir=$1    local all_entries=`ls -c`    for entry in $all_entries    do ...

  3. raspberry是个什么玩意

    今天Wilson同学取回一个书本大小的包裹,说买回来一台小电脑,只有信用卡大小! 这是第一次听说和看见raspberry Pi. 一块开发板上有四个USB.一个视频接口.一个音频接口.一个网线接口和电 ...

  4. Good Bye 2014 B. New Year Permutation(floyd )

    题目链接 题意:给n个数,要求这n个数字小的尽量放到前面,求一个最小的. 给一个矩阵s[i][j]==1,表示位置 i 的数字可以和 位置 j 的数字交换. 分析: 刚开始用的是3个循环,每次都找一个 ...

  5. Wannafly挑战赛27B(DFS,链表头插法)

    #include<bits/stdc++.h>using namespace std;int cnt=0;int flag=0;int to[400007],nex[400007],vis ...

  6. 2018宁夏邀请赛G(DFS,动态规划【VECTOR<PAIR>】)

    //代码跑的很慢四秒会超时,结尾附两秒代码(标程) #include<bits/stdc++.h>using namespace std;typedef long long ll;cons ...

  7. PAT1089【归并排序】

    这题略...恶心.. 他说归并排序依次是相邻有序两块合并,而一向打惯了递归??? #include <bits/stdc++.h> using namespace std; typedef ...

  8. “Enterprise Architect”和数据库的不解之缘

    前言 在这个大数据盛行的时代,和数据打交道变的必不可少了,所有如果有工具来规范我们的数据库会更加方便我们的生活.这次机房,我们利用EA(Enterprise Architect)自动生成SQL语句来达 ...

  9. MCP|LQ|DIAlignR provides precise retention time alignment across distant runs in DIA and targeted proteomics

    文献名: DIAlignR provides precise retention time alignment across distant runs in DIA and targeted prot ...

  10. ios 检测是否安装微信异常

    解决方法 在info.plist 添加LSApplicationQueriesSchemes 类型是Array weixin wechat