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

本秂侑毒 提交于 2020-01-02 08:38:33

问题


I have a VHDL package that defines a function (forward declaration) and a constant. The constant's value is calculated by that function, whose body is located in the package body.

As of now ModelSim/QuestaSim is the only tool that does not like this code. It needs 2 packages so the body was parsed before the constant declaration.

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;

Is this not allowed in VHDL and other tools use relaxed parsing rules, or is that a ModelSim issue?


回答1:


With a deferred constant, and assign in package body after mytest function is elaborated, it is possible even in 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;

Handling across different tools appears to be inconsistent, since as you notice ModelSim requires the deferred constant, but Altera Quartus II allows assign of constant before function elaboration, thus without deferred constant.

The VHDL-2008 standards covers subprogram elaboration in:

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

Effect of subprogram body elaboration is described in:

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.




回答2:


Alternative way is to suppress this warning by inserting the following lines into modelsim.ini file:

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


来源:https://stackoverflow.com/questions/29764083/why-cant-i-call-a-function-in-a-constant-declaration-that-is-defined-in-the-sa

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