UVM: Regular Expression with UVM - IKSciting
1999
post-template-default,single,single-post,postid-1999,single-format-standard,bridge-core-2.8.7,qodef-qi--no-touch,qi-addons-for-elementor-1.7.1,qode-page-transition-enabled,ajax_fade,page_not_loaded,,qode-title-hidden,qode_grid_1300,footer_responsive_adv,qode-content-sidebar-responsive,qode-theme-ver-27.1,qode-theme-bridge,qode_header_in_grid,wpb-js-composer js-comp-ver-6.6.0,vc_responsive,elementor-default,elementor-kit-838

Regular Expression with UVM

간혹 instance hierarchy를 기반으로 filtering 하는 등 testbench 내에서 regular expression, 즉, 정규식을 사용하면 유용한 경우가 있다. 이를 위해 UVM은 regular expression matching을 할 수 있도록 아래와 같이 uvm_re_match라는 DPI-C function을 제공한다. 해당 function은 POSIX function인 regexec를 call 하도록 되어 있다.

import "DPI-C" function int uvm_re_match(string re, string str);

Function 사용 방법은 간단하다. String str이 regular expression re와 일치하는 경우 0을 return 하고, 그렇지 않은 경우 1과 같은 error code를 return 한다. 아래 예제를 참고하자. 한 가지 주의할 점은 escaped character를 표현하기 위해 사용되는 \는 한 번 더 escape 하여 \\로 표현해야 한다는 점이다.

string str, re;

str = "uvm_test_top.env.agent[0]";
re = "uvm_test_top\\.env\\.agent\\[[0-9]\\]";

if (uvm_re_match(re, str) == 0) begin
  `uvm_info("REGEX", "match", UVM_MEDIUM)
end
else begin
  `uvm_error("REGEX", "no match")
end

참고로 이러한 regular expression matching은 UVM에서 DPI를 사용하는 경우에만 유효하다. 즉, UVM_NO_DPI 또는 UVM_REGEX_NO_DPI와 같은 text macro가 define 되는 경우 uvm_re_match는 regular expression matching이 아닌 glob style matching을 수행한다. Glob style matching은 *? 등의 wildcard character를 이용한 단순한 matching만을 지원한다.

`ifdef UVM_NO_DPI
  // ...
  `define UVM_REGEX_NO_DPI
  // ...
`endif
`ifndef UVM_REGEX_NO_DPI
import "DPI-C" function int uvm_re_match(string re, string str);
import "DPI-C" function void uvm_dump_re_cache();
import "DPI-C" 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);
  // ...
endfunction

function void uvm_dump_re_cache();
endfunction

function string uvm_glob_to_re(string glob);
  // ...
endfunction

`endif

마지막으로 regular expression에 대해 참고하거나 실시간으로 테스트 할 수 있는 RegExr 웹사이트를 추천하며 마친다.

References

No Comments

Post A Comment