gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:25:22 27 4
gpt4 key购买 nike

我有一个 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.

关于vhdl - 为什么我不能在常量声明中调用在 ModelSim 同一个包中定义的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764083/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com