Recently I've came across following issue: in Quartus software I've defined my Verilog module as follows:
module module_name(
input [w1-1:0] in1,
input [w2-1:0] in2,
output [w1-1:0] out1
);
parameter w1 = 16;
parameter w2 = 8;
...
endmodule
This module compiled without any issues. But, when I tried to simulate that code in Modelsim(-Altera) 10.3d, I got following errors:
(vlog-2730) Undefined variable: 'w1'.
(vlog-2388) 'in1' already declared in this scope (module_name)
(vlog-2730) Undefined variable: 'w2'.
...
Identifier must be declared with a port mode: in1
Identifier must be declared with a port mode: in2
I found the way to bypass this issue with following code:
module module_name(
in1,
in2,
out1
);
parameter w1 = 16;
parameter w2 = 8;
input [w1-1:0] in1;
input [w2-1:0] in2;
output [w1-1:0] out1;
...
endmodule
The other way is also to use the following construct:
module module_name #(parameter w1 = 16, parameter w2 = 8)(
input [w1-1:0] in1,
input [w2-1:0] in2,
output [w1-1:0] out1
);
...
endmodule
But: is it illegal (Quartus suggests it's not) to define parameters after input/output signals that uses this parameters?
IEEE Std 1800-2012 § 23.2.1 Module header definition state two header types:
There is no mentioning of a header syntax matching:
Based on the LRM, your sample header is non complaint. Anything that supports that syntax would be from outside the standard.
It is legal to define
parameter
s andlocalparam
s after the header with with ANSI style headers so long as the header does not references them. Example in IEEE Std 1800-2012 § 23.10 Overriding module parameters