英文:
In SystemVerilog Is it possible to place a generate block in a static function?
问题
I'm using a virtual class + static function to implement parameterized functions in SystemVerilog. This works well. However, I'm now trying to make the function implementation conditional on the parameter values. For example:
virtual class C#(integer A);
static function logic func(input a, input b);
generate
if (A == 1) begin
return a & b;
end
else if (A == 2) begin
return a ^ b;
end
else begin
$error("Invalid parameter value.");
end
endgenerate
endfunction
endclass
QuestaSim complains with "near "generate": syntax error, unexpected generate."
Is this illegal syntax? Is there any way to achieve the functionality above?
Please note that this is a contrived example, as I can't share the actual code I'm using, but it should illustrate the issue.
英文:
I'm using a virtual class + static function to implement parameterized functions in SystemVerilog. This works well. However, I'm now trying to make the function implementation conditional on the parameter values. For example:
virtual class C#(integer A);
static function logic func(input a, input b);
generate
if (A == 1) begin
return a & b;
end
else if (A == 2) begin
return a ^ b;
end
else begin
$error("Invalid parameter value.");
end
endgenerate
endfunction
endclass
QuestaSim complains with "near "generate": syntax error, unexpected generate."
Is this illegal syntax? Is there any way to achieve the functionality above?
Please note that this is a contrived example, as I can't share the actual code I'm using, but it should illustrate the issue.
答案1
得分: 1
你不能将 generate
结构放在类定义内部。但在你的示例中,没有必要这样做。你可以简单地删除 generate/endgenerate
关键字,generate-if 就变成了 procedural-if。
英文:
You cannot put a generate
construct inside a class definition. But in your example, there is no need to. You can simply remove the generate/endgenerate
keywords and the generate-if becomes a procedural-if.
答案2
得分: 1
这张图支持 @dave_59 的回答。
发布它是因为它支持答案,并且我已经发现它比一次有用。
来源:
what-goes-where-in-systemverilog
英文:
This chart supports the @dave_59 answer.
Posting it because its supports the answer and have have found it useful more than once.
Source:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论