Modelsim VHDL 数组初始化发出警告 (vcom-1320)

Pet*_*ter 5 arrays initialization fpga vhdl modelsim

我正在使用 Modelsim 的 VHDL 编译器 (vcom) 与 SublimeText (VHDL 2008) 进行代码检查。在初始化 standard_logic_vector 数组时,我收到以下警告:

vcom: warning 警告 - (vcom-1320) 表达式类型“(OTHERS => '0')”不明确;使用元素类型 STD_LOGIC_VECTOR,而不是聚合类型 t_a_reg。

一个最小的代码示例如下:

library ieee;
use ieee.std_logic_1164.all;

entity module is
  port
  (
    clk : in std_logic;
    rst : in std_logic;
    ...
  );
end entity;

architecture rtl of module is

  type t_a_reg is array (integer range <>) of std_logic_vector(15 downto 0);
  signal s_event_reg : t_a_reg(1 downto 0) := (others => (others => '0'));   -- this gives the warning

  ...

begin
  ...

end architecture;
Run Code Online (Sandbox Code Playgroud)

我通过在 tcl 控制台中输入来检查 Modelsim verror 1320,它给出了以下解释:

vcom 消息#1320:数组聚合的每个元素关联的表达式可以是元素类型或聚合本身的类型。当数组聚合属于其元素子类型为复合的数组类型时,其某些类型的元素关联表达式可能会被解释为可能是这两种类型中的任何一种。仅当不明确的表达式本身是聚合时,通常才会发生这种情况(因为聚合的类型必须仅根据聚合出现的上下文来确定,不包括聚合本身,但使用聚合的类型应为聚合的事实)复合类型)或标识两个重载函数的函数调用。这种歧义得到了解决,有利于元素类型支持与 VHDL 先前版本的向后兼容性,其中元素类型是唯一考虑的类型。[DOC:IEEE Std 1076-2008 VHDL LRM - 9.3.3.3 数组聚合]

我找到了两种在没有收到警告的情况下初始化数组的方法,但这两种方法都有缺陷。

第一个是有问题的,如果 std_logic_vector 的大小发生变化,因为我必须修改初始化:

  type t_a_reg is array (integer range <>) of std_logic_vector(15 downto 0);
  signal s_event_reg : t_a_reg(1 downto 0) := (others => x"0000");            -- no warning
Run Code Online (Sandbox Code Playgroud)

第二种方法非常冗长,我不太喜欢:

  subtype t_vec is std_logic_vector(15 downto 0);
  constant c_vec_init : t_vec := (others => '0');
  type t_a_reg is array (integer range <>) of std_logic_vector(15 downto 0);
  signal s_event_reg : t_a_reg(1 downto 0) := (others => c_vec_init);        -- no warning
Run Code Online (Sandbox Code Playgroud)

问题是:是否有正确的 VHDL-2008 初始化数组的方法,这样我就不会收到警告?这个问题更多的是一个哲学问题,因为代码是有效的。我只是想知道我是否遗漏了什么。

提前致谢!

彼得

编辑:我忘了提及,我还尝试了限定表达式:

  type t_a_reg is array (integer range <>) of std_logic_vector(15 downto 0);
  signal s_event_reg : t_a_reg(1 downto 0) := (others => std_logic_vector'(others => '0'));
Run Code Online (Sandbox Code Playgroud)

然而,这会产生一个真正的错误:

vcom:错误 - 错误 - (vcom-1076) 其他选择不能用于无约束数组聚合。

Mat*_*lor 1

使用类型限定怎么样:

signal s_event_reg : t_a_reg(1 downto 0) := (others => std_logic_vector'(others => '0'));
--                                                     ^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)