如何使用数组字段创建记录,而不在VHDL中定义数组类型?

如何使用数组字段创建记录,而不在VHDL中定义数组类型?,vhdl,Vhdl,我可以写: type bit2_t is array (0 to 1) of bit; type record0 is record bit2 : bit2_t; end record; 但我不想定义bit2\t,因为我不需要它,比如: type record0 is record bit2 : array (0 to 1) of bit; end record; 但如果我尝试一下,GHDL 0.34会说: type mark expected in a subtype in

我可以写:

type bit2_t is array (0 to 1) of bit;
type record0 is record
    bit2 : bit2_t;
end record;
但我不想定义
bit2\t
,因为我不需要它,比如:

type record0 is record
    bit2 : array (0 to 1) of bit;
end record;
但如果我尝试一下,GHDL 0.34会说:

type mark expected in a subtype indication

您只是错误地声明了数组实例。而不是

type bit2_t is array (0 to 1) of bit;
type record0 is record
  bit2 : array (0 to 1) of bit;
end record;
你需要使用

type bit2_t is array (integer range <>) of bit;
type record0 is record
  bit2 : bit2_t(0 to 1);
end record;
type bit2\u t是位的数组(整数范围);
类型record0是record
比特2:比特2(0到1);
结束记录;
如果你想要一个2位数组,你可以使用

type bit2_t is array (0 to 1) of bit;
type bit2_array_t is array (integer range <>) of bit2_t;
type record0 is record
  bit2 : bit2_array_t(0 to 7);  -- '7' or whatever your range needs to be
end record;
类型bit2是位的数组(0到1);
类型bit2_array_t是bit2_t的数组(整数范围);
类型record0是record
bit2:bit2_数组(0到7);——'7英尺或任何您需要的范围
结束记录;
您可以通过将
7
更改为常量,例如
bit2:bit2_数组_t(0到bit2_数组长度-1)

如果您想让记录类型以某种方式参数化,据我所知,您只能使用包泛型来实现这一点,如中所述。您的代码将使用如上所述的包,此包将根据
generic
参数使用数组大小声明您的记录类型。通过在每种情况下使用不同的
通用
值实例化包,您的
记录
在这些不同情况下可能具有不同的元素大小


我要指出的是,我不相信包泛型被合成工具广泛支持。

我不太明白,您的第二个示例仍然定义了
bit2\u t
类型,这是我想要避免的。@CiroSantilli巴拿馬文件六四事件法轮功 嗯,我不明白那样的话你想要什么,对不起。听起来您想定义一个记录类型,而不预定义其中一个元素的类型?如果是的话,我不确定这是否可行。是的,就是这样。只是为了少写点。就像我们在C.CiroSantilli做的那样巴拿馬文件六四事件法轮功 这是不可能的。@CiroSantilli巴拿馬文件六四事件法轮功 我更新了我的答案链接到另一个现有的答案,这可能会有帮助吗?我认为把答案中的代码复制到我的答案中没有多大意义。