2016-08-25 208 views
1
--in the package 
type t_array is array (natural range <>) of std_logic_vector (7 downto 0); 
type p_array is access t_array; 

--in my testbench 
variable my_array : p_array := null; 
begin 
my_array := new t_array(0 to 19); 
my_array := (X"00",X"00",X"00",X"00",X"FF", 
       X"FF",X"FF",X"FF",X"00",X"00", 
       X"FF",X"FF",X"FF",X"FF",X"FF", 
       X"FF",X"FF",X"FF",X"FF",X"FF"); 

Error: Target type util_lib.tb_pkg.p_array in variable assignment is different from expression type util_lib.tb_pkg.t_array.初始化动态数组VHDL

我怎样才能紧凑分配阵列中的所有元素? (1)

+0

'my_array(my_array'range):=(X “00”,X “00”,X“00”,X“00”,X“FF”,“... – user1155120

+0

这个问题是区分访问和它访问的东西 – user1155120

回答

3

(1)。取消您的指点咳嗽访问类型。

my_array.all := (...); 

(2)从一个函数初始化它

begin 
    my_array := new_array(20); 

初始化可以埋在功能,这可能算法计算所述值的底层细节,将它们复制从恒定阵列,或甚至从文件中读取内容。

constant initialiser : t_array := (...); 

function new_array(length : natural range initialiser'range) return t_array is 
    variable temp : p_array := new t_array(0 to length - 1); 
begin 
    -- either this 
    for i in temp'range loop 
     temp(i) := initialiser(i); 
    end loop; 
    -- or simply this 
    temp.all := initialiser(temp'range); 
    return temp; 
end new_array; 

(注意参数的约束new_array:确保它不会产生比初始化器大的阵列)

+0

这是完美的,非常感谢 – StanOverflow

1

你如何访问和它所指向的东西区别?

library ieee; 
use ieee.std_logic_1164.all; 

package initialize is 
--in the package 
type t_array is array (natural range <>) of std_logic_vector (7 downto 0); 
type p_array is access t_array; 
end package; 

library ieee; 
use ieee.std_logic_1164.all; 
use work.initialize.all; 

entity testbench is 
end entity; 

architecture fum of testbench is 

begin 
    process 
    --in my testbench 
    variable my_array : p_array := null; 
    begin 
     my_array := new t_array(0 to 19); 
     my_array (my_array'range) := (X"00",X"00",X"00",X"00",X"FF", 
         X"FF",X"FF",X"FF",X"00",X"00", 
         X"FF",X"FF",X"FF",X"FF",X"FF", 
         X"FF",X"FF",X"FF",X"FF",X"FF"); 
     wait; 
    end process; 
end architecture; 

IEEE标准1076至2008年8名称8.1一般第3段 - 4:

Certain forms of name (indexed and selected names, slice names, and attribute names) include a prefix that is a name or a function call. If the prefix of a name is a function call, then the name denotes an element, a slice, or an attribute, either of the result of the function call, or (if the result is an access value) of the object designated by the result. Function calls are defined in 9.3.4.

A prefix is said to be appropriate for a type in either of the following cases:
— The type of the prefix is the type considered.
— The type of the prefix is an access type whose designated type is the type considered.

这有助于理解是用于描述之间的关系为的同义词表示访问类型的值及其引用的对象。

第5款:

The evaluation of a name determines the named entity denoted by the name. The evaluation of a name that has a prefix includes the evaluation of the prefix, that is, of the corresponding name or function call. If the type of the prefix is an access type, the evaluation of the prefix includes the determination of the object designated by the corresponding access value. In such a case, it is an error if the value of the prefix is a null access value. It is an error if, after all type analysis (including overload resolution), the name is ambiguous.

在这种情况下,你可以使用包含整个阵列片名称。

此外访问元素,可以使用所选择的名称:

  my_array.all := (X"00",X"00",X"00",X"00",X"FF", 

8.3选定的名称第5段:

For a selected name that is used to denote the object designated by an access value, the suffix shall be the reserved word all. The prefix shall belong to an access type.