我有一个记录type(REC
),其中包含一个类型VECTOR
为元素的不受约束的2d数组的元素STD_LOGIC
:
package TEST is
type VECTOR is array (NATURAL range <>, NATURAL range <>) of STD_LOGIC;
type REC is record
data : VECTOR;
end record REC;
function con(
a : REC;
b : REC)
return REC;
end package TEST;
在声明con
函数的主体时,我想指定REC.data
数组的大小,如下所示:
package body TEST is
function con(
a : REC;
b : REC)
return REC is variable r : REC(
data(a.data'length(1) + b.data'length(1) - 1 downto 0, a.data'length(2) - 1 downto 0));
begin
-- . . . do things
end function con;
end package body TEST;
但是在我尝试设置数据大小的那一行中,Vivado引发了以下错误:
Sliced name is allowed only on single-dimensional arrays
这是否意味着我不能在记录中拥有不受约束的2d杂色,还是在con
函数中定义其大小的方法不同?
- - 编辑 - -
由于我现在了解在这种情况下不可能使用2d数组,因此我应该使用哪种方法来创建一个函数,该函数应:
user1155120 I don't think I fully understand what you are trying to say. Are you saying my code is not
a minimal reproducible example, because except for me forgetting to include the STD_LOGIC library
the code reproduces the problem when I paste it into Vivado, and it is about as minimal as I can get it.
Or are you saying that the code you linked as this works works for you, because at least in my
Vivado it still throws the same error ? – Mercury 4 hours ago
最初的评论是针对Tricky的。函数中缺少一个return语句,con
这会阻止在示例中使用它。
目前尚不清楚Vivado Simulator是否支持记录约束(-2008功能)。在Vivado综合指南UG901 2020.1中,我们看到了记录类型的各种奇妙用法,从所有内容到推断ram到记录类型的记录元素。Xilinx一直很忙。
如果支持记录类型声明中的非约束元素而不是记录约束,这似乎很奇怪(顺便说一句,它们几乎是一揽子交易)。请注意该注释称为-2008功能。
记录约束被限制为提供不受约束类型(通常为数组)的元素或子元素的约束。VHDL一直能够提供多维数组约束。该标准的语言基于语法的灵活性而特别。
此代码符合VHDL -2008并提供了记录约束:
library ieee; -- ADDED for MCVe
use ieee.std_logic_1164.all; -- ADDED
package TEST is
type VECTOR is array (NATURAL range <>, NATURAL range <>) of STD_LOGIC;
type REC is record
data: VECTOR;
end record REC;
function con (a: REC; b: REC) return REC;
end package TEST;
package body TEST is
function con (a: REC; b: REC) return REC is
variable r:
REC ( -- record constraint:
data (
natural range a.data'length(1) + b.data'length(1) - 1 downto 0,
natural range a.data'length(2) - 1 downto 0
)
);
begin
-- . . . do things
return r; -- ADDED required return statement
end function con;
end package body TEST;
你会注意到对记录约束的更改是natural range
在元素数据约束的每个范围之前添加。
根据IEEE Std 1076-2008 5.3.3记录类型:
record_constraint :: =
(record_element_constraint {,record_element_constraint})record_element_constraint :: = record_element _simple_name element_constraint
从6.3子类型声明:
element_constraint :: =
array_constraint
| record_constraint
这里的元素数据是一个数组,因此array_constraint是合适的。
从5.3.2数组类型开始,5.3.2.1:
array_constraint :: =
index_constraint [array_element_constraint]
| (打开)[array_element_constraint]
因为元素数据数组元素是标量(枚举类型为STD_LOGIC),所以我们遵循index_constraint。
index_constraint :: =(离散范围{,离散范围})
离散范围:: =离散_subtype_indication | 范围
上面显示的代码对元素数据维的索引范围使用离散的子类型指示,并成功进行了分析(编译)。
从5.2.2标量类型开始,5.2.2.1:
范围:: =
range_attribute_name
| simple_expression方向simple_expression方向:: =到| 向下
问题中的约束使用带有简单表达式和方向的范围。
那么,为什么会产生有关多维切片的错误消息呢?
在9. Expressions,9.1 BNF中,simple_expression-> term-> factor-> primary-> name。
在8.名称(8.1名称-> slice_name)中,BNF告诉我们在语法上有效的8.5切片名称中,仅语义上不允许多维切片。
slice_name :: =前缀(离散范围)
切片的前缀应适合于一维数组对象。此数组类型的基本类型是切片的类型。
在语义上,该前缀data
不适用于一维数组对象。
这些注释为问题提供了更多的背景信息,尽管目前尚不清楚你在报告的最终成功中使用的记录约束是哪个版本:
@Mercury when you add a (VHDL) file to Vivado, it's by default set to use VHDL 93, but not 2008. Go
to the property Window and change the file type from VHDL to VHDL 2008. I'm not sure why it
prints the wrong error message in your case. (Vivado likes to confuse users with wrong error messages
...). Anyhow, it should have reported your feature is only supported in 2008 mode. – Paebbels 3 hours
ago
@Paebbels Thank you, that fixed the problem, maybe add it as a sub note to your response so I can
mark it as accepted answer. You just saved me hours of frustration. And I'm already getting familiar with
Vivado's shenanigans, my Favorit one of which is "ERROR close to ..." which has to be one of the most
useless error messages I have experience in a long time :) – Mercury 3 hours ago
就检测到-2008源而言,在主单元或辅助单元中都没有-1993语法错误,也没有-2008新保留字,定界符,分隔符或图形字符。
这就让你受制于失败的语义分析。你还可能会注意到,在分析包声明时未报告不受约束的记录元素。它发生在变量评估期间r
。所有声明的对象都必须受到约束。VHDL并不具备所有功能,因此语义也可能是限制性的。在某些地方具有不受限制的元素和对象是合法的。
将在标准文本中找到的语义规则与特定声明或声明的文本元素相关联可能很困难,吱吱作响的轮子会产生润滑剂。记录约束对于VHDL实现而言是相对较新的。
该问题似乎是工具熟悉的问题之一。
非常感谢您的全面答复,我现在看到您的第一条评论包含了解决方案,但这不是很容易理解。作为一种后续操作,我想问一下文件彗星本身是否可以使用任何方式来表示,
VHDL-2008
这样,如果我在其他地方使用过此文件,就不必在IDE中再次指定它吗?