Struct 如何在系统verilog-generate中改变通过端口的结构不起作用

Struct 如何在系统verilog-generate中改变通过端口的结构不起作用,struct,parameters,verilog,system,generate,Struct,Parameters,Verilog,System,Generate,我得到这个错误: module testy #( parameter W = 10, parameter C = 2 ) ( aa ); generate if (W == 8) begin:W8 if(C == 1) begin:W8C1 typedef struct {

我得到这个错误:

module testy
    #(
        parameter W = 10,
        parameter C = 2
     )
     (
         aa
     );

   generate
      if (W == 8)
        begin:W8
           if(C == 1)
                begin:W8C1
                typedef struct {
                   logic [8:0] so;
                }my_struct;

                end 
           if(C == 2)
             begin:W8C2
                typedef struct {
                   logic [10:0] so;
                }my_struct;
             end
        end
   endgenerate

input my_struct aa;

endmodule
我认为生成是静态确定的,但我在编译它时遇到了问题,因为参数不能在包中重写,也无法在需要合成的设计中想到这样做的方法,并且不想添加接口或类。有没有办法做到这一点。我的结构有100多个条目,如果我包括所有的组合,并且只使用我想要的,但我认为使用generates可以根据一组参数将其修剪为我想要的


谢谢

您的问题是
typedef
的范围是
generate
语句中块的局部范围。如果您所需要做的只是更改数据类型的大小,则可以使用静态确定的常量函数调用。但是,您的解包结构声明会遇到另一个问题—它仍然是模块的本地声明,您将无法使用匹配的数据类型将另一个结构连接到它。接口将是一个更好的解决方案,并且是可综合的


另一种可能是传递类型参数。

我有一个限制,不能使用接口,尽管它们是可合成的。这是一个简单的例子,实际上struct有几个条目,对于一个配置,它有一组信号,而对于另一个配置,它有一组完全不同的信号。我实现了它的socpe,因为如果我删除它在单独生成下工作的if语句,那么我需要使它在模块中的任何地方都可见,但我无法理解它。除非你想忘记结构,否则接口实际上是实现你想做的事情的唯一方法。
irun(64): 14.20-p001: (c) Copyright 1995-2015 Cadence Design Systems, Inc.
file: testy.v
input my_struct aa;
              |
ncvlog: *E,SVNOTY (testy.v,30|14): Syntactically this identifier appears to begin a datatype but it does not refer to a visible datatype in the current scope.
    module worklib.testy:v
        errors: 1, warnings: 0
ncvlog: *F,NOTOPL: no top-level unit found, must have recursive instances.
irun: *E,VLGERR: An error occurred during parsing.  Review the log file for errors with the code *E and fix those identified problems to proceed.  Exiting with code (status 2).