使用 QuestaSim 编译 VHDL 时出现警告 "Range choice direction does not determine aggregate index range direction"

Warning "Range choice direction does not determine aggregate index range direction" when compiling VHDL with QuestaSim

我在 QuestaSim 中编译 VHDL 时收到一条我不理解的警告:

(vcom-1514) 范围选择方向(downto)不决定聚合指数范围方向(to)。

触发警告的代码类似于

signal foo : unsigned(4 downto 0);

begin 之前的体系结构中,然后在某些进程中

if foo = (foo'high => '1', foo'high - 1 downto foo'low => '0') then

上面的行会在

时触发警告
if foo = (foo'high => '1', foo'low to foo'high - 1 => '0') then

不会,即使 foo 的索引方向是 downto 而不是 to

有人知道为什么在这种情况下我应该使用 to 而不是 downto 进行索引吗?

合计

(foo'high => '1', foo'high - 1 downto foo'low => '0')

具有索引范围方向'to'。你的警告是:不要想象它的方向是 'downto' 仅仅因为你包含了一个数组,其中定义为 'downto'.

为什么默认方向是'to'?那么,我们需要考虑这个聚合是什么类型。 (来吧 - 这是 VHDL - 它必须有一个类型)。

在我的代码中,它的类型是unsigned。为什么?好吧,因为我已将它与类型为 unsigned 的过程的输入相关联。在您的代码中,它的类型也是 unsigned。为什么?好吧,因为它是 = 运算符的右手参数,其左手参数肯定是 unsigned= 运算符只有一种可能的版本,即测试两个 unsigned 的版本。

现在,我们需要查看类型 unsigned 是如何声明的,当我们看到它被声明为索引类型为 natural:[=23 的无约束数组时=]

type unsigned is array (natural range <>) of std_logic;

类型 natural 的左侧值为 0。因此,这就是为什么您的聚合具有索引范围方向 'to' 的原因。


如果你执行这段代码,你可以看到 VHDL 是如何定义聚合索引的:

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

entity E is
end entity ;

architecture A of E is
  signal foo : unsigned(4 downto 0);
begin

  process
    procedure display (constant foo : in unsigned) is
    begin
      report "foo'left= " & integer'image(foo'left);
      report "foo'right= " & integer'image(foo'right);
      report "foo'high= " & integer'image(foo'high);
      report "foo'low= " & integer'image(foo'low);
     end procedure;
  begin
    display((foo'high => '1', foo'high - 1 downto foo'low => '0'));
    wait;
  end process;

end architecture A;