Is it not allowed to use $sformat inside generate statement?

Hello Folks,

Is it not allowed to use $sformat inside the generate statement as shown below? And the simulator throws an error saying “Expecting the keyword ‘end’” at the $sformat line.
Share in your comments!


genvar num;
generate
 for (num = 0; num < 12; num++) begin
  $sformat(out_str, "`HELLO.fruit_num%0d", num);
  assign  hello_if.fruit[num] = out_str;
 end
endgenerate

Thanks!!

In reply to desperadorocks:
You are allowed to use $sformat inside a generate block, but the statements inside the generate block are not procedural unless you put it into that context. For example, you can use an initial block inside the generate.

generate
 for (ganvar num = 0; num < 12; num++) begin
  strong out_str; // this declaration has to be inside the for-loop
  initial begin
   $sformat(out_str, "`HELLO.fruit_num%0d", num);
   hello_if.fruit[num] = out_str;
  end
 end
endgenerate

If you want to keep the continuous assignment, then you need to use $sformatf

generate
 for (ganvar num = 0; num < 12; num++) begin
   assign hello_if.fruit[num] = $sformatf("`HELLO.fruit_num%0d", num);
 end
endgenerate

In reply to dave_59:

In reply to desperadorocks:
You are allowed to use $sformat inside a generate block, but the statements inside the generate block are not procedural unless you put it into that context. For example, you can use an initial block inside the generate.

generate
for (ganvar num = 0; num < 12; num++) begin
strong out_str; // this declaration has to be inside the for-loop
initial begin
$sformat(out_str, "`HELLO.fruit_num%0d", num);
hello_if.fruit[num] = out_str;
end
end
endgenerate

If you want to keep the continuous assignment, then you need to use $sformatf

generate
for (ganvar num = 0; num < 12; num++) begin
assign hello_if.fruit[num] = $sformatf("`HELLO.fruit_num%0d", num);
end
endgenerate

Hi dave_59,

This solution will work for UVM testbench. What if we want to use $sformat and $sformatf in formal testbench where only synthesizable constructs will be allowed?

Thanks.

In reply to ankit1312:

A specific tool determines which constraints are synthesizable. You’ll have to consult your tool’s User Manual to contact them for support. The Mentor sponsored public forum is not for tool specific issues.