首页 > 解决方案 > Modelsim VHDL 数组初始化给出警告 (vcom-1320)

问题描述

我正在使用 Modelsim 的 VHDL-Compiler (vcom) 对 SublimeText (VHDL 2008) 进行代码检查。在初始化一个标准逻辑向量数组时,我收到以下警告:

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;

我通过在 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

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

  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

问题是:是否有正确的 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'));

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

vcom: error - 错误 - (vcom-1076) OTHERS 选项不能用于不受​​约束的数组聚合。

标签: arraysinitializationvhdlfpgamodelsim

解决方案


如何使用类型限定

signal s_event_reg : t_a_reg(1 downto 0) := (others => std_logic_vector'(others => '0'));
--                                                     ^^^^^^^^^^^^^^^^^

推荐阅读