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__);
}

最新文章

  1. 单片机与控制实验(2)——LED点阵显示屏
  2. Hibernate criteria 增加排序项
  3. 关于duplicate symbol _main in的解决办法
  4. (转)【Android测试工具】03. ApkTool在Mac上的安装和使用(2.0版本)
  5. poj 3468 A Simple Problem with Integers【线段树区间修改】
  6. WCF服务发布到IIS时候,只能根据hostname访问,不能根据IP地址访问的解决办法
  7. Qt Lite
  8. Eclipse中导入第三方源码的问题和备用解决方案
  9. jQuery.extend()源码解读
  10. BZOJ 2083: [Poi2010]Intelligence test [vector+二分]
  11. UNIX网络编程——ICMP报文分析:端口不可达
  12. springMVC框架在js中使用window.location.href请求url时IE不兼容问题解决
  13. Java的内存 -JVM 内存管理
  14. CSRF与SSRF区别
  15. PE结构学习笔记--关于AddressOfEntryPoint位置在文件中怎么确定问题
  16. 签名Cookie
  17. CSS border系列
  18. UVA.11427.Expect the Expected(期望)
  19. 斑马Zebra驱动下载
  20. localstorage在safri下的坑

热门文章

  1. 自定义map对象,用于再不支持es6的map的时候
  2. python 学习笔记12(事件驱动、IO多路复用、异步IO)
  3. const define区别
  4. 1、kubernetes系统基础190622
  5. [USACO1.4]等差数列 Arithmetic Progressions
  6. C.0689-The 2019 ICPC China Shaanxi Provincial Programming Contest
  7. AT2402 Dam
  8. POJ1020 Anniversary Cake
  9. 利用Python的smtplib和email发送邮件
  10. Sandcastle Help File Builder 生成NET帮助文档