【发布时间】:2020-07-14 12:26:29
【问题描述】:
我正在使用 Modelsim 的 VHDL 编译器 (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 控制台中输入 verror 1320 来签入 Modelsim,它给出了以下解释:
vcom 消息 #1320: 数组聚合的每个元素关联的表达式可以是 元素类型或聚合本身的类型。当一个数组 聚合是一个数组类型,其元素子类型是复合的,它是 它的某些类型的元素关联表达式可能是 被解释为可能是这两种类型中的任何一种。这会 通常只有当模棱两可的表达式本身是一个聚合时才会发生 (因为聚合的类型必须完全从 聚合出现的上下文,不包括聚合本身 但是使用聚合的类型应该是复合的事实 type) 或标识两个重载函数的函数调用。 解决了这种歧义,有利于支持的元素类型 与以前版本的 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 选项不能用于不受约束的数组聚合。
【问题讨论】:
-
追踪和消除警告总是一个好主意。即使当前的警告都不重要,但如果您习惯于忽略它们,您将来可能会错过重要的警告。
-
你能把这个例子提交给1076工作组eda-twiki.org/cgi-bin/view.cgi/P1076/WebHome
-
你试过了吗:`signal s_event_reg : t_a_reg(1 downto 0) := (1 downto 0 => (others => '0'));`
-
@JimLewis 感谢您的意见。我刚试过,警告仍然存在。
signal s_event_reg : t_a_reg(1 downto 0) := (others => (15 downto 0 => '0'));和signal s_event_reg : t_a_reg(1 downto 0) := (1 downto 0 => (15 downto 0 => '0'));也不要进行更改。另外:如何将此示例提交给 1076 工作组?通过电子邮件将其发送给 Pete Ladow 还是我必须创建一个新主题? -
ActiveHDL 没有这样的警告
标签: arrays initialization vhdl fpga modelsim