需要计算 vhdl 中的常量名称

need to count constants names in vhdl

我有一个 constant 对象的列表,如下所示。他们是 record 类型。我正在尝试 运行 一个 loop,我可以在其中一一访问所有这些。有人可以建议一种方法吗?

type objecttype is record
      id, x_start, x_end, y_start, y_end : integer;
end record objecttype;   
constant C_OBJ1: objecttype :=(id       =>   0,
                               x_start  => 200,
                               x_end    => 300);
constant C_OBJ2: objecttype :=(id       =>   0,
                              x_start  => 400,
                              x_end    => 500);

我想做类似的事情:

for i in 0 to 5 loop C_OBJ(i)......... end loop;

创建一个对象数组。例如:

entity test_e is
end entity;

architecture test_a of test_e is
    type objecttype is record
        id, x_start, x_end, y_start, y_end : integer;
    end record objecttype;   

    type objectarray is array (natural range <>) of objecttype;

    constant C_OBJ : objectarray(0 to 5) := (
        (1, 2, 3, 4, 5),
        (1, 2, 3, 4, 5),
        (1, 2, 3, 4, 5),
        (1, 2, 3, 4, 5),
        (1, 2, 3, 4, 5),
        (1, 2, 3, 4, 5)
        );
begin
end architecture;

IEEE Std 1076-2008 5.3.2 数组类型,5.3.2.1 第 1 段(部分):

An array object is a composite object consisting of elements that have the same subtype. The name for an element of an array uses one or more index values belonging to specified discrete types. ...

这里的关键是所有记录命名元素都属于同一类型。

此处记录类型的使用可能源于面向对象的范例(使用字段名称来传达含义,这实际上应该是 VHDL 中用户定义的属性,但不符合合成条件)。

为数组类型和一个创建枚举索引类型 使用索引类型的数组类型:

package foo is
    type indx is (id, x_start, x_end, y_start, y_end);
    type objecttype is array (indx range id to y_end) of integer;
    constant C_OBJ1: objecttype := (id       =>   0,
                                    x_start  => 200,
                                    x_end    => 300,
                                    y_start  => 0,
                                    y_end    => 0);
    constant C_OBJ2: objecttype := (id       =>   0,
                                    x_start  => 400,
                                    x_end    => 500,
                                    y_start  => 0,
                                    y_end    => 0);
end package foo;

use work.foo.all; 
entity fum is
end entity;

architecture fie of fum is
begin
    process
    begin
        for i in objecttype'range loop
            report "C_OBJ1(" & indx'image(i) & ") = " &
                 integer'image(C_OBJ1(i));
        end loop;
        wait;
    end process;
end architecture;

请注意,预定义属性 'image 适用于任何标量类型(包括离散类型)或子类型,并且枚举类型符合条件。循环参数范围是一个数组类型的对象。

这给出了:

ghdl -r fum
fum.vhdl:25:13:@0ms:(report note): C_OBJ1(id) = 0
fum.vhdl:25:13:@0ms:(report note): C_OBJ1(x_start) = 200
fum.vhdl:25:13:@0ms:(report note): C_OBJ1(x_end) = 300
fum.vhdl:25:13:@0ms:(report note): C_OBJ1(y_start) = 0
fum.vhdl:25:13:@0ms:(report note): C_OBJ1(y_end) = 0

当 运行.

这也意味着您将访问数组的元素作为索引名称而不是选择的名称:C_OBJ1(id), C_OBJ1(x_start), ...

您可以将 indx 类型值 to/from 转换为具有预定义属性 'pos'val.

的整数类型