xref: /Universal-ctags/Units/parser-verilog.r/systemverilog-parameter.d/input.sv (revision e1d64241ad79390a82d178e8d48fdd7eb16f9876)
1//
2// parameter defintion tests
3//
4
5// LRM 8.25.1 Class scope resolution operator for parameterized classes
6class C #(
7  int p = 1
8);
9  parameter int q = 5;  // local parameter
10  static task t;
11    int p;
12    int x = C::p;  // C::p disambiguates p
13    // C::p is not p in the default specialization
14  endtask
15endclass
16
17class C #(
18    int p = 1,
19    type T = int
20);
21  extern static function T f();
22endclass
23
24function C::T C::f();
25  return p + C::p;
26endfunction
27
28// LRM 13.8 Parameterized tasks and functions
29virtual class C#(parameter DECODE_W, parameter ENCODE_W = $clog2(DECODE_W));
30  static function logic [ENCODE_W-1:0] ENCODER_f
31      (input logic [DECODE_W-1:0] DecodeIn);
32    ENCODER_f = '0;
33    for (int i = 0; i < DECODE_W; i++) begin
34      if (DecodeIn[i]) begin
35        ENCODER_f = i[ENCODE_W - 1:0];
36        break;
37      end
38    end
39  endfunction
40  static function logic [DECODE_W-1:0] DECODER_f
41      (input logic [ENCODE_W-1:0] EncodeIn);
42    DECODER_f = '0;
43    DECODER_f[EncodeIn] = 1'b1;
44  endfunction
45endclass
46
47// LRM 8.26 Interface classes
48interface class PutImp #(type PUT_T = logic);
49  pure virtual function void put(PUT_T a);
50endclass
51
52interface class GetImp #(type GET_T = logic);
53  pure virtual function GET_T get();
54endclass
55
56class Fifo #(type T = logic, int DEPTH = 1) implements PutImp#(T), GetImp#(T);
57  T myFifo[$:DEPTH-1];
58  virtual function void put(T a);
59    myFifo.push_back(a);
60  endfunction
61  virtual function T get();
62    get = myFifo.pop_front();
63  endfunction
64endclass
65
66class Stack #(type T = logic, int DEPTH = 1) implements PutImp#(T), GetImp#(T);
67  T myFifo[$:DEPTH-1];
68  virtual function void put(T a);
69    myFifo.push_front(a);
70  endfunction
71  virtual function T get();
72    get = myFifo.pop_front();
73  endfunction
74endclass
75
76// 8.26.3 Type access
77interface class IntfA #(type T1 = logic);
78  typedef T1[1:0] T2;
79  pure virtual function T2 funcA();
80endclass : IntfA
81
82interface class IntfB #(type T = bit) extends IntfA #(T);
83  pure virtual function T2 funcB(); // legal, type T2 is inherited
84endclass : IntfB
85
86// 23.2.3 Parameterized modules
87module generic_fifo
88  #(parameter MSB=3, LSB=0, DEPTH=4) // these parameters can be redefined
89   (input  wire [MSB:LSB] in,
90    input  wire clk, read, write, reset,
91    output logic [MSB:LSB] out,
92    output logic full, empty );
93    //...
94endmodule
95
96module generic_decoder
97  #(num_code_bits = 3, localparam num_out_bits = 1 << num_code_bits)
98   (input [num_code_bits-1:0] A, output reg [num_out_bits-1:0] Y);
99endmodule
100
101// additional test
102typedef int int_t;
103module user_defined_type_param
104  #(int_t num_code_bits = 3, localparam num_out_bits = 1 << num_code_bits)
105   (input [num_code_bits-1:0] A, output reg [num_out_bits-1:0] Y);
106endmodule
107
108//
109// LRM 6.20.1 Parameter declaration syntax (#2537)
110//
111
112// compilation unit scope
113parameter L1 = 0;  //  synonym for the localparam
114
115module module_with_parameter_port_list #(P1, P2, localparam L2 = P1+1, L3=P2*2, parameter P3, P4)
116( /*port list...*/ );
117  parameter  L4 = "local parameter";  // synonym for the localparam
118  localparam L5 = "local parameter";
119  // ...
120endmodule
121
122module module_with_empty_parameter_port_list #()
123( /*port list...*/ );
124  parameter  L6 = "local parameter";  // synonym for the localparam
125  localparam L7 = "local parameter";
126  // ...
127endmodule
128
129module module_no_parameter_port_list
130( /*port list...*/ );
131  parameter  P5 = "parameter";
132  localparam L8 = "local parameter";
133  // ...
134endmodule
135
136class class_with_parameter_port_list #(P1, P2, localparam L2 = P1+1, L3=P2*2, parameter P3, P4);
137  parameter  L4 = "local parameter";  // synonym for the localparam
138  localparam L5 = "local parameter";
139  // ...
140endclass
141
142class class_with_empty_parameter_port_list #();
143  parameter  L6 = "local parameter";  // synonym for the localparam
144  localparam L7 = "local parameter";
145  // ...
146endclass
147
148class class_no_parameter_port_list;
149  parameter  L8 = "local parameter";  // synonym for the localparam (class only)
150  localparam L9 = "local parameter";
151  // ...
152endclass
153
154program program_with_parameter_port_list #(P1, P2, localparam L2 = P1+1, L3=P2*2, parameter P3, P4)
155( /*port list...*/ );
156  parameter  L4 = "local parameter";  // synonym for the localparam
157  localparam L5 = "local parameter";
158  // ...
159endprogram
160
161program program_with_empty_parameter_port_list #()
162( /*port list...*/ );
163  parameter  L6 = "local parameter";  // synonym for the localparam
164  localparam L7 = "local parameter";
165  // ...
166endprogram
167
168program program_no_parameter_port_list
169( /*port list...*/ );
170  parameter  P5 = "parameter";
171  localparam L8 = "local parameter";
172  // ...
173endprogram
174
175interface interface_with_parameter_port_list #(P1, P2, localparam L2 = P1+1, L3=P2*2, parameter P3, P4)
176( /*port list...*/ );
177  parameter  L4 = "local parameter";  // synonym for the localparam
178  localparam L5 = "local parameter";
179  // ...
180endinterface
181
182interface interface_with_empty_parameter_port_list #()
183( /*port list...*/ );
184  parameter  L6 = "local parameter";  // synonym for the localparam
185  localparam L7 = "local parameter";
186  // ...
187endinterface
188
189interface interface_no_parameter_port_list
190( /*port list...*/ );
191  parameter  P5 = "parameter";
192  localparam L8 = "local parameter";
193  // ...
194endinterface
195
196package package_has_no_parameter_port_list;
197  parameter  L1 = "local parameter";
198  localparam L2 = "local parameter";
199endpackage
200
201module generate_constructs;
202  generate
203    parameter  L1 = "local parameter";  // FIXME
204    localparam L2 = "local parameter";
205  endgenerate
206endmodule
207