使用可能范围(0 到 0)的数组类型的数组时有什么问题?

发布于 2025-01-16 22:56:51 字数 1076 浏览 1 评论 0原文

我真的不明白出了什么问题:

我有一个不受约束的类型

type int_matrix_type is array (natural range <>, natural range <>) of integer;

,用于创建不同大小的矩阵,即使我想要一个范围为 (0 到 1, 0 to 0) 我认为这会给出一个 2 行 1 列的矩阵(对吗?),就像这个例子中的 signal example2_matrix

library ieee;
use ieee.std_logic_1164.all;

entity toto is
    port (
        clk : in std_logic
    );
end entity;

architecture test of toto is

    -- type declaration
    type int_matrix_type is array (natural range <> ,natural range <>) of integer;
    -- examples of matrix signals
    signal example1_matrix : int_matrix_type (0 to 1, 0 to 1) 
    := ((0, 1),
        (2, 3)
        );
    signal example2_matrix : int_matrix_type (0 to 1, 0 to 0)
    := ((0), -- here line 20
        (2)  --      line 21
        );  
        
begin

end test;

但是当我编译时,Quartus 返回错误

在此处输入图像描述

那么出了什么问题呢?

提前致谢 !

I don't really understand what is wrong :

I have an unconstrained type

type int_matrix_type is array (natural range <>, natural range <>) of integer;

that I'm using to create different sizes of matrices, even I want a matrix with the range (0 to 1, 0 to 0) which I consider will give a matrix of 2 lines and 1 column (right?), like in this example signal example2_matrix :

library ieee;
use ieee.std_logic_1164.all;

entity toto is
    port (
        clk : in std_logic
    );
end entity;

architecture test of toto is

    -- type declaration
    type int_matrix_type is array (natural range <> ,natural range <>) of integer;
    -- examples of matrix signals
    signal example1_matrix : int_matrix_type (0 to 1, 0 to 1) 
    := ((0, 1),
        (2, 3)
        );
    signal example2_matrix : int_matrix_type (0 to 1, 0 to 0)
    := ((0), -- here line 20
        (2)  --      line 21
        );  
        
begin

end test;

But when I compile, Quartus returns errors

enter image description here

So what is wrong ?

Thanks in advance !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2025-01-23 22:56:51

解决方案已在主帖下的评论中给出。所以我只是在这里为其他人重写一个明确的解决方案。我引用:

@user16145658

语义规则可在 IEEE Std 1076-2008 9.3.3 聚合、9.3.3.1 常规中找到,“包含单个元素关联的聚合应始终使用命名关联来指定,以便将它们与括号表达式区分开来。”

这意味着我的代码应该看起来更像:

library ieee;
use ieee.std_logic_1164.all;

entity toto is
    port (
        clk : in std_logic
    );
end entity;

architecture test of toto is

    -- type declaration
    type int_matrix_type is array (natural range <> ,natural range <>) of integer;
    -- examples of matrix signals
    signal example1_matrix : int_matrix_type (0 to 1, 0 to 1) 
    := ((0, 1),
         (2, 3)
        );
    -- this not ok
    --signal example2_matrix : int_matrix_type (0 to 1, 0 to 0)
    --:= ((0), -- here line 20
    --    (2)  --      line 21
    --    ); 
    -- this ok
    signal example2_matrix : int_matrix_type (0 to 1, 0 to 0) 
    := (0 => (0 => 0),
        1 => (0 => 1)); 
    -- or
    signal example2bis_matrix : int_matrix_type (0 to 1, 0 to 0)  
    := ((0 => 0),
        (0 => 1));
         
begin

end test;

希望它能帮助其他人!

Solutions were given in the comments under the main post. So I'm just rewritting here a clear solution for others. I quote :

@user16145658

The semantic rule is found in IEEE Std 1076-2008 9.3.3 Aggregates, 9.3.3.1 General "Aggregates containing a single element association shall always be specified using named association in order to distinguish them from parenthesized expressions."

which means that my code should look more like :

library ieee;
use ieee.std_logic_1164.all;

entity toto is
    port (
        clk : in std_logic
    );
end entity;

architecture test of toto is

    -- type declaration
    type int_matrix_type is array (natural range <> ,natural range <>) of integer;
    -- examples of matrix signals
    signal example1_matrix : int_matrix_type (0 to 1, 0 to 1) 
    := ((0, 1),
         (2, 3)
        );
    -- this not ok
    --signal example2_matrix : int_matrix_type (0 to 1, 0 to 0)
    --:= ((0), -- here line 20
    --    (2)  --      line 21
    --    ); 
    -- this ok
    signal example2_matrix : int_matrix_type (0 to 1, 0 to 0) 
    := (0 => (0 => 0),
        1 => (0 => 1)); 
    -- or
    signal example2bis_matrix : int_matrix_type (0 to 1, 0 to 0)  
    := ((0 => 0),
        (0 => 1));
         
begin

end test;

Hope it will help others !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文