我的记录定义如下
type ifx_t is
record
data : std_logic_vector(127 downto 0);
address : std_logic_vector (19 downto 0);
WrReq : std_logic;--
RdReq : std_logic; --
end record;
type Array_ifx_t is array (0 to 2) of ifx_t;
我必须初始化这个记录数组的一个实例,我尝试了以下方法,它不起作用
signal pair_in : Array_ifx_t:= (others =>((others =>'0'),(others=>'0'),'0','0'));
请帮助。
答案 0 :(得分:9)
如评论中所述,ModelSim在使用ModelSim编译问题代码时起作用。但是,对于Array_ifx_t
中的元素使用类型值,其他工具可能更为严格。
对于命名记录元素的类型赋值和使用,我认为它给出了getter概述并避免了位置引用的错误,你可以使用以下命令进行初始化:
constant IFX_T_0S : ifx_t := (data => (others =>'0'),
address => (others=>'0'),
WrReq => '0',
RdReq => '0');
signal pair_in : Array_ifx_t:= (others => IFX_T_0S);
答案 1 :(得分:2)
我最初看到对于pair_in的默认值中的聚合反应是“其他”太多了,所以我独立地使用记录类型声明本身写了一个:
library ieee;
use ieee.std_logic_1164.all;
package some_record is
type ifx_t is
record
data : std_logic_vector(127 downto 0);
address : std_logic_vector (19 downto 0);
WrReq : std_logic;--
RdReq : std_logic; --
end record;
type Array_ifx_t is array (0 to 2) of ifx_t;
-- positional association in an aggregate used for initialization:
signal pair_in: ifx_t := ((others => '0'), (others => '0'),'0','0');
end package;
这成功分析了。聚合有两种类型的关联,位置或命名。上面的默认值表达式是位置。使用命名关联:
signal pair_in: ifx_t := -- named association of record elements:
(
data => (others => '0'),
address => (others =>'0'),
WrReq => '0',
RdReq => '0'
);
你会注意到这与Morten接受的答案的常量声明中的值表达式有着惊人的相似之处,并且实际上讲述了聚合表达式的兼容性故事。
与记录类型兼容的聚合包含与记录类型的每个元素兼容的值表达式。这是通过为其默认值提供聚合来为数组元素数据和地址完成的,而WrReq和RdReq直接提供其默认值。
如果pair_in
是由ifx_t
记录类型元素组成的数组组成的复合类型,那么在原始尝试中找到的额外其他语句将是合适的。
LRM(例如IEEE Std 1076-1993)有一个关于表达式的部分,一个关于聚合的子部分,还有一个关于记录聚合的子部分。
还有一个关于类型的部分,一个关于复合类型的小节,还有一个关于记录类型的小节。