用于uvm_re_match函数

时间:2015-04-10 14:48:31

标签: uvm

我有uvm_re_match的以下代码:

int temp_int = 20;
temp_int = uvm_re_match(uvm_glob_to_re("abc"), "top.mydut_abc_comp_inst");
$display("\t uvm_re_match USAGE: The result - temp_int = %0d \n",temp_int);

我收到temp_int = 1,表示在提供的字符串中找不到"abc"

有关uvm_re_matchuvm_glob_to_re用法的任何建议。

1 个答案:

答案 0 :(得分:0)

首先,您必须确保将UVM与其DPI代码一起使用,即UVM_NO_DPI isn 定义。通过打印uvm_glob_to_re("abc")的结果可以轻松查看此内容。如果结果仍然是"abc",那么您将使用函数的SystemVerilog版本(它只返回参数)而不是DPI-C实现。有关代码,请参阅dpi/uvm_regex.svh

假设您正在使用DPI功能,那么您的glob表达式就会出错。 "abc"的glob表达式不应与您的字符串匹配。您需要使用"*abc*"(glob)来匹配它。通过查看两个表达式的正则表达式版本,您可以看到这不会起作用:

module top;
  import uvm_pkg::*;

  initial begin
    static string re1 = uvm_glob_to_re("abc");
    static string re2 = uvm_glob_to_re("*abc*");
    $display(re1);
    $display(re2);
  end
endmodule

您会发现re1包含的"/^abc$/"只能匹配"abc"re2包含/^.*abc.*$/,它匹配字符串中的任何"abc"子字符串。您可以忽略开头和结尾处的/个字符,因为这些字符会被删除(不知道为什么他们会在那里)。

如果您尝试匹配这两个表达式,您会看到第一个表达式不匹配,而第二个表达式则匹配:

if (!uvm_re_match(re1, "top.mydut_abc_comp_inst"))
  $display("matches re1");

if (!uvm_re_match(re2, "top.mydut_abc_comp_inst"))
  $display("matches re2");

额外奖励:另一个与您的字符串匹配的正则表达式为"abc",您可以看到它也适用于uvm_re_match(...)

if (!uvm_re_match("abc", "top.mydut_abc_comp_inst"))
  $display("matches re3");