Usage for Uvm_Re_Match Function

Usage for Uvm_Re_Match Function

I am having following code for 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);

I am getting temp_int = 1, indicating "abc" not found in the string provided.

Any suggestions on uvm_re_match and uvm_glob_to_re usage.

1 Answer

First of all, you have to make sure that you are using UVM together with its DPI code, i.e. the UVM_NO_DPI isn't defined. It's easy to check this by printing the result of uvm_glob_to_re("abc"). If the result is still "abc", then you're using the SystemVerilog version of the function (which just returns the argument) and not the DPI-C implementation. See dpi/uvm_regex.svh for the code.

Assuming you're using the DPI functions, you're making a mistake with your glob expression. A glob expression of "abc" isn't supposed to match your string. You need to use "*abc*" (glob) to match it. You can see that this wouldn't work by looking at the regex versions of the two expressions:

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

You'll see that re1 contains "/^abc$/" which can only ever match "abc". re2 contains /^.*abc.*$/, which matches any "abc" sub-string in a string. You can just ignore the / characters at the beginning and the end as these will get stripped away (not sure why they're there).

If you try to match the two expressions you'll see that the first one doesn't match, whereas the second one does:

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");

Bonus: another regular expression that would match your string is "abc", which you can see also works with uvm_re_match(...):

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.