为什么我不能在常量声明中调用在 ModelSim 同一个包中定义的函数?

Why can't I call a function in a constant declaration, that is defined in the same package in ModelSim?

我有一个 VHDL 包,它定义了一个函数(前向声明)和一个常量。常量的值由该函数计算,其主体位于包主体中。

截至目前,ModelSim/QuestaSim 是唯一不喜欢此代码的工具。它需要 2 个包,所以主体在常量声明之前被解析。

package test is
  function mytest(param : boolean ) return boolean;

  constant value : boolean := mytest(TRUE);
end package;

package body test is
  function mytest(param : boolean ) return boolean is
  begin
    return not param;
  end function;
end package body;

这在 VHDL 和其他使用宽松解析规则的工具中是不允许的,还是 ModelSim 的问题?

使用延迟常量,并在 mytest 函数详细说明后在包体中赋值,即使在 ModelSim 中也是可能的:

package test is
  function mytest(param : boolean ) return boolean;
  constant value : boolean;
end package;

package body test is
  function mytest(param : boolean ) return boolean is
  begin
    return not param;
  end function;
  constant value : boolean := mytest(TRUE);
end package body;

不同工具之间的处理似乎不一致,因为正如您所注意到的,ModelSim 需要延迟常量,但 Altera Quartus II 允许在函数细化之前分配常量,因此没有延迟常量。

VHDL-2008 标准涵盖以下子程序的详细说明:

14.4.2.1 General: ..., it is illegal to call a subprogram before its corresponding body is elaborated.

子程序体详细说明的作用在:

14.4.2.2 Subprogram declarations, bodies, and instantiations: ... Elaboration of a subprogram body, other than the subprogram body of an uninstantiated subprogram, has no effect other than to establish that the body can, from then on, be used for the execution of calls of the subprogram.

另一种方法是通过将以下行插入 modelsim.ini 文件来抑制此警告:

[msg_system]
; Downgrade the following error:
; Error (suppressible): (vcom-1594) Cannot call subprogram before it is elaborated.
; See more on: 
warning = 1594