0
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

I get this error:

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).

I thought generates were statically determined but I have problems compiling it - since parameters cant be overridden in packages and couldn't think of a way to do this in design which needs to be synthesized and didn't want to add interfaces or classes. Is there a bettwe way to do this. My struct has over 100 entries if I include all the combinations and use only what I want but I thought using generates I could trim it to what I want based on a set of parameters.

Thanks

dave_59
  • 39,096
  • 3
  • 24
  • 63
user9906612
  • 77
  • 1
  • 9

1 Answers1

0

Your problem is the scope of the typedef is local to the blocks inside your generate statements. If all you need to do is change the size of a data type, you can use a constant function call, with is statically determined. But then you run into another problem with your unpacked struct declaration - it is still local to the module and you will not be able to connect another struct to it with a matching data type. An interface would be a better solution and is synthesizable.

Another possibility is passing down a type parameter.

dave_59
  • 39,096
  • 3
  • 24
  • 63
  • I have a restriction and cant use interfaces although they are synthesizable. This is a simple example in reality the struct has several entries and for one config it will have one set of signals and for another it has a completely different set of signals. I realized its socpe because if I remove the if statements it works under generate alone so I need to make it visible everywhere within the module but couldnt figure it out. – user9906612 Sep 03 '18 at 03:40
  • An interface is really the only way to achieve what you want to do unless you want to forget about the struct. – dave_59 Sep 03 '18 at 05:02