uvm_regex——DPI在UVM中的实现(三)
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中的实现(三)的更多相关文章
- 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_svcmd_dpi——DPI在UVM中的实现(二)
UVM中有需要从cmmand line 输入参数的需求,所有uvm_svcmd_dpi.svh和uvm_svcmd_dpi.cc 文件就是实现功能. uvm_svcmd_dpi.svh的源代码如下,我 ...
- UVM中的regmodel建模(三)
总结一下UVM中的寄存器访问实现: 后门访问通过add_hdl_path命令来添加寄存器路径,并扩展uvm_reg_backdoor基类,定义read与write函数,最后在uvm_reg_block ...
- UVM中的class
UVM中的类包括:基类(base)------------uvm_void/uvm_object/uvm_transaction/uvm_root/uvm_phase/uvm_port_base 报告 ...
- UVM中的sequence使用(一)
UVM中Driver,transaction,sequence,sequencer之间的关系. UVM将原来在Driver中的数据定义部分,单独拿出来成为Transaction,主要完成数据的rand ...
- 转载:WinForm中播放声音的三种方法
转载:WinForm中播放声音的三种方法 金刚 winForm 播放声音 本文是转载的文章.原文出处:http://blog.csdn.net/jijunwu/article/details/4753 ...
- Jquery中each的三种遍历方法
Jquery中each的三种遍历方法 $.post("urladdr", { "data" : "data" }, function(dat ...
- C#中的线程三 (结合ProgressBar学习Control.BeginInvoke)
C#中的线程三(结合ProgressBar学习Control.BeginInvoke) 本篇继上篇转载的关于Control.BeginInvoke的论述之后,再结合一个实例来说明Cotrol.Begi ...
随机推荐
- LeetCode第20题:有效的括号
问题描述: 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空 ...
- java笔记--关于线程同步(5种同步方式)
转自:http://www.2cto.com/kf/201408/324061.html 为何要使用同步? java允许多线程并发控制,当多个线程同时操作一个可共享的资源变量时(如数据的增删改 ...
- 工作随记--div最小高度
给div添加最小高度 min-height:1000px;//IE7\FF height:100%;//IE6\IE7\FF 这个很重要,IE6定死高度后,需要再加上这条,才能自动延伸. _heigh ...
- C# 字节转换
1.字符串与字节数组 System.Text.Encoding.UTF-8.GetBytes() 汉字转换后3个字节,数字转换和数字位数一样 GetString() 2.Int32值类型与字节数组 B ...
- [CentOS7] at, bash, cron, anacron
声明:本文主要总结自:鸟哥的Linux私房菜-第十五章.例行性工作排程(crontab),如有侵权,请通知博主 at => /var/spool/at /etc/at.allow, /etc/a ...
- php5.6安装window7安装memcache.dll库所遇到的误区
问题: window7 64位,下载的库 memcache.dll 为64位的,且对应php的版本.但是重启后phpstudy查看phpinfo依然没有memcache: 根源: 发现是下载的 mem ...
- Ocelot(二)- 请求聚合与负载均衡
Ocelot(二)- 请求聚合与负载均衡 作者:markjiang7m2 原文地址:https://www.cnblogs.com/markjiang7m2/p/10865511.html 源码地址: ...
- 《OD学spark》20160924scala基础
拓展: Hadoop 3.0 NameNode HA NameNode是Active NameNode是Standby可以有多个 HBase Cluster 单节点故障? HBaster -> ...
- C#之抽象类、虚方法、重写、接口、密封类
前言 学了这么长时间的C#,我想说对于这个东东还是不是特别了解它,以至于让我频频郁闷.每次敲代码的时候都没有一种随心所欲的感觉.所以不得不在网上搜集一些资料,look 了 look~ 内容 ...
- 51nod1305(简单逻辑)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1305 题意:中文题诶- 思路:1e5的数据直接暴力肯定是不行 ...