How to use array return function in Constraint?

In reply to Pawan Kalyan:

Hi,
Please tell me how to use array return type function in constraint, Below I attached one example.

module array_return_test();
class array_test;
typedef bit [3:0] arr[$];
bit [3:0] g_arr[$];
rand bit [3:0] c_arr[$];
constraint AAA  {
c_arr == test(1,2);
}
function arr test(input bit [3:0] a=1,b=2);
bit [3:0] lcl_arr[$];
for(int i=0;i<5;i++)
begin
lcl_arr.push_back(a+b);
end
return lcl_arr;
endfunction
endclass
array_test at= new();
initial
for(int i=0;i<5;i++)
begin
at.randomize();
at.g_arr = at.test(i,i+1);
$display($time," C_ARRY = %p; gbl array is %p",at.c_arr,at.g_arr);
end
endmodule

You can’t just constraint a queue equal a queue. Several options to fix this:

  1. Calculate c_arr queue at post_randomize function
  2. Declare a temporarily to hold test(1,2) and constraint:

  constraint AAA  {
    c_arr.size() == temp_arr.size();
    foreach(temp_arr[i]) c_arr[i] = temp_arr[i];
  }