Issue with parameters in Modelsim

吃可爱长大的小学妹 提交于 2019-12-13 15:41:25

问题


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?


回答1:


IEEE Std 1800-2012 § 23.2.1 Module header definition state two header types:

There are two styles of module header definitions, the non-ANSI header and the ANSI header.

The non-ANSI header style separates the definition of the module header from the declarations of the module ports and internal data. The informal syntax of a non-ANSI style module header is as follows:

module_name ( port_list ) ;
  parameter_declaration_list
  port_direction_and_size_declarations
  port_type_declarations

The module header definition is syntactically completed by the semicolon after the closing parenthesis of the port list. Declarations that define the characteristics of the ports (direction, size, data type, signedness, etc.) are local definitions within the module.

The ANSI header style makes the declarations of the port characteristics part of the module header (which is still terminated by a semicolon). The informal general syntax of an ANSI style module header is as follows:

module_name #( parameter_port_list )
             ( port_direction_and_type_list ) ;

There is no mentioning of a header syntax matching:

 module_name ( port_direction_and_type_list ) ;
    parameter_declaration_list

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 parameters and localparams 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



来源:https://stackoverflow.com/questions/33219106/issue-with-parameters-in-modelsim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!