使用自定义包导致循环依赖

Using Custom Packages Causes Circular Dependency

我正在尝试在包中声明一个无符号数组,以便我可以在我的所有组件中使用相同类型的数组。我是先在顶层组件中声明的,然后在各个组件中使用work库和use命令对包进行调用。我收到一条警告

WARNING:ProjectMgmt:454 - File circular dependency detected using rule: define-before-use.

我也收到一条错误消息

Line 27: Cannot find <test2> in library <work>. Please ensure that the library was compiled, and that a library and a use clause are present in the VHDL file.

为什么会出现循环依赖,我是否正确地创建和使用了包?

顶级组件

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

package pkg is
  type array_unsigned is array (99 downto 0) of UNSIGNED(7 downto 0);
end package;

package body pkg is
end package body;

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library work;
use work.pkg.ALL;

entity test1 is
end test1;

architecture Behavioral of test1 is
    signal input : array_unsigned;
begin
sub: entity work.test2(Behavioral)
    port map(input=>input);
end Behavioral;

下级组件

library IEEE;
library work;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use work.pkg.ALL;

entity test2 is
    Port (input : in array_unsigned);
end test2;

architecture Behavioral of test2 is

begin


end Behavioral;

您的包 pkg 似乎是在与实体 test1 相同的文件中定义的,它本身 use 就是这个包。虽然我不认为这是完全错误的,但看起来 ISE 已经发现它需要编译你的第一个文件(编译包),然后才能编译同一个文件来编译实体 test1,并且产生了一个错误。实际上,如果它只是简单地继续编译文件,一切就OK了。

通过将包移动到它自己的文件中,这种明显的自我依赖性被删除了。

问题不在于第一个文件同时包含 pkg 程序包和 test1 实体。这很好,不是循环依赖。许多人,包括我自己,可能会认为这是一种不好的做法。真正的问题是 test1 从一个单独的文件实例化 test2 实体,该文件也使用 pkg。因此循环依赖 test2 依赖于 pkg 但包含 pkgtest1 的文件依赖于 test2 因为它是在那里实例化的。

Modelsim 仅支持编译文件中的特定设计单元,因此它可能能够处理这种情况。