1// DESCRIPTION: Verilator: Verilog Test module
2//
3// This file ONLY is placed into the Public Domain, for any use,
4// without warranty, 2017 by Matt Myers.
5// SPDX-License-Identifier: CC0-1.0
6
7`define checkd(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d:  got=%0d exp=%0d\n", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0);
8
9package config_pkg;
10   typedef struct packed {
11      int 	  UPPER0;
12      struct 	  packed {
13         int 	  USE_QUAD0;
14         int 	  USE_QUAD1;
15         int 	  USE_QUAD2;
16      } mac;
17      int 	  UPPER2;
18   } config_struct;
19
20   function automatic config_struct static_config(int selector);
21      config_struct return_config;
22      return_config = '0;
23      return_config.UPPER0 = 10;
24      return_config.UPPER2 = 20;
25      return_config.mac.USE_QUAD0 = 4;
26      return_config.mac.USE_QUAD2 = 6;
27      case (selector)
28        1: return_config.mac.USE_QUAD1 = 5;
29      endcase
30      return return_config;
31   endfunction
32endpackage : config_pkg
33
34module t;
35    import config_pkg::*;
36
37    localparam config_struct MY_CONFIG = static_config(1);
38
39    struct_submodule #(.MY_CONFIG(MY_CONFIG)) a_submodule_I ();
40endmodule : t
41
42module struct_submodule
43  import config_pkg::*;
44   #(parameter config_struct MY_CONFIG = '0);
45
46   initial begin
47      `checkd(MY_CONFIG.UPPER0, 10);
48      `checkd(MY_CONFIG.mac.USE_QUAD0, 4);
49      `checkd(MY_CONFIG.mac.USE_QUAD1, 5);
50      `checkd(MY_CONFIG.mac.USE_QUAD2, 6);
51      `checkd(MY_CONFIG.UPPER2, 20);
52      $write("*-* All Finished *-*\n");
53      $finish;
54   end
55endmodule : struct_submodule
56