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

`ifndef UVM_REGEX_NO_DPI
import "DPI-C" context function int uvm_re_match(string re, string str);
import "DPI-C" context function void uvm_dump_re_cache();
import "DPI-C" context function string uvm_glob_to_re(string glob); `else // The Verilog only version does not match regular expressions,
// it only does glob style matching.
function int uvm_re_match(string re, string str);
int e, es, s, ss;
string tmp;
e = ; s = ;
es = ; ss = ; if(re.len() == )
return ; // The ^ used to be used to remove the implicit wildcard, but now we don't
// use implicit wildcard so this character is just stripped.
if(re[] == "^")
re = re.substr(, re.len()-); //This loop is only needed when the first character of the re may not
//be a *.
while (s != str.len() && re.getc(e) != "*") begin
if ((re.getc(e) != str.getc(s)) && (re.getc(e) != "?"))
return ;
e++; s++;
end while (s != str.len()) begin
if (re.getc(e) == "*") begin
e++;
if (e == re.len()) begin
return ;
end
es = e;
ss = s+;
end
else if (re.getc(e) == str.getc(s) || re.getc(e) == "?") begin
e++;
s++;
end
else begin
e = es;
s = ss++;
end
end
while (e < re.len() && re.getc(e) == "*")
e++;
if(e == re.len()) begin
return ;
end
else begin
return ;
end
endfunction function void uvm_dump_re_cache();
endfunction function string uvm_glob_to_re(string glob);
return glob;
endfunction `endif

然后,再看看uvm_regex.cc的源代码:

#include "uvm_dpi.h"
#include <sys/types.h> const char uvm_re_bracket_char = '/';
#define UVM_REGEX_MAX_LENGTH 2048
static char uvm_re[UVM_REGEX_MAX_LENGTH+]; //--------------------------------------------------------------------
// uvm_re_match
//
// Match a string to a regular expression. The regex is first lookup
// up in the regex cache to see if it has already been compiled. If
// so, the compile version is retrieved from the cache. Otherwise, it
// is compiled and cached for future use. After compilation the
// matching is done using regexec().
//--------------------------------------------------------------------
int uvm_re_match(const char * re, const char *str)
{
regex_t *rexp;
int err; // safety check. Args should never be ~null~ since this is called
// from DPI. But we'll check anyway.
if(re == NULL)
return ;
if(str == NULL)
return ; int len = strlen(re);
char * rex = &uvm_re[]; if (len > UVM_REGEX_MAX_LENGTH) {
const char* err_str = "uvm_re_match : regular expression greater than max %0d: |%s|";
char buffer[strlen(err_str) + int_str_max() + strlen(re)];
sprintf(buffer, err_str, UVM_REGEX_MAX_LENGTH, re);
m_uvm_report_dpi(M_UVM_ERROR,
(char*) "UVM/DPI/REGEX_MAX",
&buffer[],
M_UVM_NONE,
(char*)__FILE__,
__LINE__);
return ;
} // we copy the regexp because we need to remove any brackets around it
strncpy(&uvm_re[],re,UVM_REGEX_MAX_LENGTH);
if (len> && (re[] == uvm_re_bracket_char) && re[len-] == uvm_re_bracket_char) {
uvm_re[len-] = '\0';
rex++;
} rexp = (regex_t*)malloc(sizeof(regex_t)); if (rexp == NULL) {
m_uvm_report_dpi(M_UVM_ERROR,
(char*) "UVM/DPI/REGEX_ALLOC",
(char*) "uvm_re_match: internal memory allocation error",
M_UVM_NONE,
(char*)__FILE__,
__LINE__);
return ;
} err = regcomp(rexp, rex, REG_EXTENDED); if (err != ) {
regerror(err,rexp,uvm_re,UVM_REGEX_MAX_LENGTH-);
const char * err_str = "uvm_re_match : invalid glob or regular expression: |%s||%s|";
char buffer[strlen(err_str) + strlen(re) + strlen(uvm_re)];
sprintf(buffer, err_str, re, uvm_re);
m_uvm_report_dpi(M_UVM_ERROR,
(char*) "UVM/DPI/REGEX_INV",
&buffer[],
M_UVM_NONE,
(char*)__FILE__,
__LINE__);
regfree(rexp);
free(rexp);
return err;
} err = regexec(rexp, str, , NULL, ); //vpi_printf((PLI_BYTE8*) "UVM_INFO: uvm_re_match: re=%s str=%s ERR=%0d\n",rex,str,err);
regfree(rexp);
free(rexp); return err;
} //--------------------------------------------------------------------
// uvm_glob_to_re
//
// Convert a glob expression to a normal regular expression.
//-------------------------------------------------------------------- const char * uvm_glob_to_re(const char *glob)
{
const char *p;
int len; // safety check. Glob should never be ~null~ since this is called
// from DPI. But we'll check anyway.
if(glob == NULL)
return NULL; len = strlen(glob); if (len > ) {
const char * err_str = "uvm_re_match : glob expression greater than max 2040: |%s|";
char buffer[strlen(err_str) + strlen(glob)];
sprintf(buffer, err_str, glob);
m_uvm_report_dpi(M_UVM_ERROR,
(char*) "UVM/DPI/REGEX_MAX",
&buffer[],
M_UVM_NONE,
(char*)__FILE__,
__LINE__);
return glob;
} // If either of the following cases appear then return an empty string
//
// 1. The glob string is empty (it has zero characters)
// 2. The glob string has a single character that is the
// uvm_re_bracket_char (i.e. "/")
if(len == || (len == && *glob == uvm_re_bracket_char))
{
uvm_re[] = '\0';
return &uvm_re[]; // return an empty string
} // If bracketed with the /glob/, then it's already a regex
if(glob[] == uvm_re_bracket_char && glob[len-] == uvm_re_bracket_char)
{
strcpy(uvm_re,glob);
return &uvm_re[];
}
else
{
// Convert the glob to a true regular expression (Posix syntax)
len = ; uvm_re[len++] = uvm_re_bracket_char; // ^ goes at the beginning...
if (*glob != '^')
uvm_re[len++] = '^'; for(p = glob; *p; p++)
{
// Replace the glob metacharacters with corresponding regular
// expression metacharacters.
switch(*p)
{
case '*':
uvm_re[len++] = '.';
uvm_re[len++] = '*';
break; case '+':
uvm_re[len++] = '.';
uvm_re[len++] = '+';
break; case '.':
uvm_re[len++] = '\\';
uvm_re[len++] = '.';
break; case '?':
uvm_re[len++] = '.';
break; case '[':
uvm_re[len++] = '\\';
uvm_re[len++] = '[';
break; case ']':
uvm_re[len++] = '\\';
uvm_re[len++] = ']';
break; case '(':
uvm_re[len++] = '\\';
uvm_re[len++] = '(';
break; case ')':
uvm_re[len++] = '\\';
uvm_re[len++] = ')';
break; default:
uvm_re[len++] = *p;
break;
}
}
} // Let's check to see if the regular expression is bounded by ^ at
// the beginning and $ at the end. If not, add those characters in
// the appropriate position. if (uvm_re[len-] != '$')
uvm_re[len++] = '$'; uvm_re[len++] = uvm_re_bracket_char; uvm_re[len++] = '\0'; return &uvm_re[];
} //--------------------------------------------------------------------
// uvm_dump_re_cache
//
// Dumps the set of regular expressions stored in the cache
//-------------------------------------------------------------------- void uvm_dump_re_cache()
{
m_uvm_report_dpi(M_UVM_INFO,
(char*) "UVM/DPI/REGEX_MAX",
(char*) "uvm_dump_re_cache: cache not implemented",
M_UVM_LOW,
(char*)__FILE__,
__LINE__);
}

uvm_regex——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_svcmd_dpi——DPI在UVM中的实现(二)

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

  4. UVM中的regmodel建模(三)

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

  5. UVM中的class

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

  6. UVM中的sequence使用(一)

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

  7. 转载:WinForm中播放声音的三种方法

    转载:WinForm中播放声音的三种方法 金刚 winForm 播放声音 本文是转载的文章.原文出处:http://blog.csdn.net/jijunwu/article/details/4753 ...

  8. Jquery中each的三种遍历方法

    Jquery中each的三种遍历方法 $.post("urladdr", { "data" : "data" }, function(dat ...

  9. C#中的线程三 (结合ProgressBar学习Control.BeginInvoke)

    C#中的线程三(结合ProgressBar学习Control.BeginInvoke) 本篇继上篇转载的关于Control.BeginInvoke的论述之后,再结合一个实例来说明Cotrol.Begi ...

随机推荐

  1. SpringMVC的国际化

    关于SpringMVC的国际化,http://www.cnblogs.com/liukemng/p/3750117.html这篇文章已经讲的很好了.它讲了有如下几种国际化方式 1:基于Http的hea ...

  2. 21. Bypass D盾_防火墙(旧版 and 新版)SQL注入防御(多姿势)

    D盾旧版: 00前言 D盾_IIS防火墙,目前只支持Win2003服务器,前阵子看见官方博客说D盾新版将近期推出,相信功能会更强大,这边分享一下之前的SQL注入防御的测试情况.D盾_IIS防火墙注入防 ...

  3. 【Qt官方例程学习笔记】Application Example(构成界面/QAction/退出时询问保存/用户偏好载入和保存/文本文件的载入和保存/QCommandLineParser解析运行参数)

    The Application example shows how to implement a standard GUI application with menus, toolbars, and ...

  4. Linux常用知识点汇总

    常用命令 1.ls 列出目录下的所有文件及文件夹 2.pwd 打印出当前所在目录 3. ./ 执行 .sh 文件命令 4.ip addr 查看ip地址 5.sudo  service network ...

  5. 网络应用(3):CDN与P2P的概念

    我前面说了流量的概念,流量是使用网络时经常要考虑的一个因素--如何才能更快的使用流量,如何才能节省流量使用的成本,对于这样的问题,你可能要了解一下什么是cdn,什么是p2p. (1)cdn是什么 cd ...

  6. SCUT - 337 - 岩殿居蟹 - 线段树 - 树状数组

    https://scut.online/p/337 这个东西是个阶梯状的.那么可以考虑存两棵树,一棵树是阶梯的,另一棵树的平的,随便一减就是需要的阶梯. 优化之后貌似速度比树状数组还惊人. #incl ...

  7. Ocelot(二)- 请求聚合与负载均衡

    Ocelot(二)- 请求聚合与负载均衡 作者:markjiang7m2 原文地址:https://www.cnblogs.com/markjiang7m2/p/10865511.html 源码地址: ...

  8. 一个MySQL中两表联合update的例子(并带有group by分组)

    内容简介 本文主要展示了在MySQL中,使用两表联合的方式来更新其中一个表字段值的SQL语句. 也就是update table1 join table2 on table1.col_name1=tab ...

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

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

  10. 51nod1428(优先队列)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 题意:中文题诶- 思路:贪心 问最少要多少教室就是求最多 ...