User guide

24-15
SystemVerilog Testbench Constructs
The following example illustrates the usage of the backref() function
call.
integer i;
string str, patt, str1, str2;
str = "1234 is a number."
patt = "([0-9]+) ([a-zA-Z .]+)";
i = str.match(patt);
str1 = str.backref(0);
str2 = str.backref(1);
This example checks the Perl expressions given by string patt with
string str. It assigns the value “1234” to string str1 because of the
match to the expression “[0-9]+”. It assigns the value “is a number.”
to string str2 because of the match to the expression “[a-zA-Z .]+”.
Any number of additional Perl expressions can be listed in the patt
definition, and then called using sequential index numbers with the
backref() function.
Program Blocks
A program block contains the testbench for a design. In the default
implementation of SystemVerilog testbench constructs, all these
constructs must be in one program block. Multiple program blocks is
an LCA feature.
Requiring these constructs in a program block help to distinguish
between the code that is the testbench and the code that is the design.