如何约束VHDL-2008整数_向量?

如何约束VHDL-2008整数_向量?,vhdl,Vhdl,VHDL-2008定义了 type integer_vector is array (natural range <>) of integer 但是,如何声明受约束整数数组,例如: -- does not work: -- signal sConstrainedTestIntA : integer_vector(0 to 1) range 0 to 3 := (others => 0); -- ** Error: filetest.vhd(65): Range constra

VHDL-2008定义了

type integer_vector is array (natural range <>) of integer
但是,如何声明受约束整数数组,例如:

-- does not work:
-- signal sConstrainedTestIntA : integer_vector(0 to 1) range 0 to 3 := (others => 0);
-- ** Error: filetest.vhd(65): Range constraints cannot be applied to array types.
-- ** Error: filetest.vhd(65): Range expression is type Integer; expecting type std.STANDARD.INTEGER_VECTOR

-- What you can do is:
type my_int_array is array (natural range <>) of integer range 0 to 3;
signal sConstrainedIntA : my_int_array(0 to 1) := (others => 0);
--不工作:
--信号sConstrainedTestIntA:整数向量(0到1)范围0到3:=(其他=>0);
--**错误:filetest.vhd(65):范围约束无法应用于数组类型。
--**错误:filetest.vhd(65):范围表达式为整型;应为std.STANDARD.INTEGER\u VECTOR类型
--您可以做的是:
键入my_int_array是整数范围为0到3的数组(自然范围);
信号SConstrainedData:my_int_数组(0到1):=(其他=>0);

有没有办法在没有自定义类型的情况下约束数组中的整数?

VHDL 2008支持包泛型参数。您可以尝试以下方法:

package foo_pkg is
    generic(l, h: integer);
    subtype my_integer is integer range l to h;
    type my_integer_vector is array(natural range <>) of my_integer;
end package foo_pkg;

package foo_pkg_m17_p39 is new work.foo_pkg
    generic map(l => -17, h => 39);

package foo_pkg_p57_p134 is new work.foo_pkg
    generic map(l => 57, h => 134);

entity foo is
    port(iv1: work.foo_pkg_m17_p39.my_integer_vector(0 to 7);
         iv2: work.foo_pkg_p57_p134.my_integer_vector(0 to 7)
     );
end entity foo;
foo_包装是
泛型(l,h:整数);
子类型my_integer是从l到h的整数范围;
键入my_integer_vector是my_integer的数组(自然范围);
终包foo_包装;
包foo_pkg_m17_p39是新的工作。foo_pkg
通用图(l=>17,h=>39);
包foo_pkg_p57_p134是新的工作。foo_pkg
通用图(l=>57,h=>134);
实体foo是
端口(iv1:work.foo_pkg_m17_p39.my_integer_vector(0到7);
iv2:work.foo_pkg_p57_p134.my_integer_向量(0到7)
);
最终实体foo;
不是很友好,因为每个整数约束需要一个包实例化声明。但我发现最像你所要求的


即使它看起来比您预期的更复杂,它仍然允许您将自定义代码分解为my_integer_vector的所有变体。

我想不是
integer\u vector
是一个完整范围的整数数组,如您所写。如果你想改变这一点,你必须自己定义一个不同的类型。如何定义一个自定义类型,然后可以在以后进行约束,比如类型slv_array是std_logic_vector的数组(自然范围);信号sSlvA:slv_阵列(0到1)(1到0):=(其他=>(其他=>“0”);我对VHDL-2008不太清楚,但在这之前,你不能做这样的事情。我猜这在VHDL-2008中仍然是不可能的。Type
integer
是一种受约束的类型(标量类型、数字类型),而
std\u logic\u vector
是枚举类型的一种无约束数组类型(
std\u logic
)。
package foo_pkg is
    generic(l, h: integer);
    subtype my_integer is integer range l to h;
    type my_integer_vector is array(natural range <>) of my_integer;
end package foo_pkg;

package foo_pkg_m17_p39 is new work.foo_pkg
    generic map(l => -17, h => 39);

package foo_pkg_p57_p134 is new work.foo_pkg
    generic map(l => 57, h => 134);

entity foo is
    port(iv1: work.foo_pkg_m17_p39.my_integer_vector(0 to 7);
         iv2: work.foo_pkg_p57_p134.my_integer_vector(0 to 7)
     );
end entity foo;