为什么我不能在常量声明中调用函数,它是在 ModelSim 的同一个包中定义的? [英] Why can't I call a function in a constant declaration, that is defined in the same package in ModelSim?

查看:28
本文介绍了为什么我不能在常量声明中调用函数,它是在 ModelSim 的同一个包中定义的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

到目前为止,ModelSim/QuestaSim 是唯一不喜欢此代码的工具.它需要 2 个包,因此主体在常量声明之前被解析.

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;

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

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

推荐答案

带一个延迟常量,在mytest函数详细说明后在包体中赋值,即使在ModelSim中也可以:

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;

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

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.

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

The VHDL-2008 standards covers subprogram elaboration in:

14.4.2.1 概述:...,在未详细说明子程序的相应主体之前调用子程序是非法的.

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 子程序声明、主体和实例化: ... 子程序主体的细化,而不是未实例化子程序的子程序主体,除了确定主体可以从那时起用于执行调用子程序.

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 的同一个包中定义的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆