Hi,
I am trying to print a 3-dimensional array and getting the second and third dimension getting printed (duplicated) for first dimension. Here is the code I have:
foreach(result_bytes[i]) begin
printer.print_array_header($sformatf("result_bytes[%0d]",i), result_bytes[i].size(), "result_bytes[]");
foreach(result_bytes[i,j,k]) begin
printer.print_generic($sformatf("[%0d][%0d][%0d]",i,j,k), "bit", (result_bytes[i].size * result_bytes[i][j].size() ), $sformatf("0x%x",result_bytes[i][j][k]));
end
printer.print_array_footer(result_bytes[i].size());
end
Also what would be the equivalent print using the field macros?
Thanks,
Madhu
Your inner foreach loop iterates over the entire array.
You can either change your inner foreach loop to two nested for loops, or you can copy the 3-D array to a 2-D array for each iteration of the outer foreach loop.
foreach(result_bytes[i]) begin
printer.print_array_header($sformatf("result_bytes[%0d]",i), result_bytes[i].size(), "result_bytes[]");
for(int j = $low(result_bytes,2), j<= $high(result_bytes,2); j++)
for(int k = $low(result_bytes,3), k<= $high(result_bytes,3); k++) printer.print_generic($sformatf("[%0d][%0d][%0d]",i,j,k), "bit", (result_bytes[i].size * result_bytes[i][j].size() ), $sformatf("0x%x",result_bytes[i][j][k]));
printer.print_array_footer(result_bytes[i].size());
end
foreach(result_bytes[I]) begin
my_type results2d[][];
results2d = result_bytes[i]; printer.print_array_header($sformatf("result_bytes[%0d]",i), result_bytes[I].size(), "result_bytes[]");
foreach(result_2d[j,k]) begin
printer.print_generic($sformatf("[%0d][%0d][%0d]",i,j,k), "bit", (result_bytes[i].size * result_bytes[i][j].size() ), $sformatf("0x%x",result_bytes[i][j][k]));
end
printer.print_array_footer(result_bytes[i].size());
end
In reply to dave_59:
Hi Dave,
Thanks for the reply. Leaving aside the discussion of whether using a field macro is efficient or not, is there a way to represent this print using the field macros?
Thanks,
Madhu
In reply to mseyunni:
No. There are a limited number of types supported by the field macros. They only support 1-D arrays.