在SystemVerilog中,是否可以在静态函数中放置一个生成块?

huangapple go评论63阅读模式
英文:

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 的回答。

在SystemVerilog中,是否可以在静态函数中放置一个生成块?

发布它是因为它支持答案,并且我已经发现它比一次有用。

来源:
what-goes-where-in-systemverilog

英文:

This chart supports the @dave_59 answer.

在SystemVerilog中,是否可以在静态函数中放置一个生成块?

Posting it because its supports the answer and have have found it useful more than once.
Source:

what-goes-where-in-systemverilog

huangapple
  • 本文由 发表于 2023年3月21日 01:52:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793676-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定