2016-07-04 3 views
2

рассмотрим типаназначения VHDL для типа массива

type foo is array (0 downto 0) of std_logic_vector(7 downto 0); 

Почему я получаю ошибку компиляции, когда я пытаюсь создать постоянное значение этого типа, например. Обратите внимание, что я только пытался использовать Altera Quartus II.

constant cFoo : foo := (x"11"); 

Error: VHDL Type mismatch error at [filename.vhd](line number): cFoo type does not match string literal.

Однако все нормально, если мой тип

type foo is array (0 downto 0) of std_logic_vector(7 downto 0); 

с примером присвоения константы:

constant cFoo : foo := (x"00", x"11"); 

Кроме того считают, что я пытаюсь присвоить индекс 0 с другой константой. Например.

type foo is array (0 downto 0) of std_logic_vector(7 downto 0); 
constant cBar : std_logic_vector(7 downto 0); 
constant cFoo : foo := (cBar ); 

Для которой ошибка компилятор выплевывает теперь:

VHDL error at [filename.vhd](line number): type of identifier "cBar" does not agree with its usage as "foo" type.

Поэтому в основном его говорил мне, что компилятор не понимает, что присвоение индексу 0, но вместо того, чтобы присваивание тип массива.

Как я могу сообщить компилятору, что задание состоит только в индексе 0?

ответ

4

IEEE Std 1076 9.3.3 Заполнители, 9.3.3.1 пункт 4:

Both named and positional associations can be used in the same aggregate, with all positional associations appearing first (in textual order) and all named associations appearing next (in any order, except that it is an error if any associations follow an others association). Aggregates containing a single element association shall always be specified using named association in order to distinguish them from parenthesized expressions.

С MCVE:

library ieee; 
use ieee.std_logic_1164.all; 

package ceefoo is 
    type foo is array (0 downto 0) of std_logic_vector(7 downto 0); 
    -- constant cFoo : foo := (x"11"); 
    constant cfoo: foo := (0 => x"11"); 
    -- or 
    constant cefoo: foo := (others => x"11"); 
end package; 

Вы должны использовать именованный ассоциацию с одним элементом. Первый пример указывает индекс 0, второй - любые элементы.

Para 3 из процитированной выше части:

Each element association associates an expression with elements (possibly none). An element association is said to be named if the elements are specified explicitly by choices; otherwise, it is said to be positional. For a positional association, each element is implicitly specified by position in the textual order of the elements in the corresponding type declaration.

Это полезно, чтобы увидеть BNF:

aggregate ::=
( element_association { , element_association } )

element_association ::=
     [ choices => ] expression

choices ::= choice { | choice }

choice ::=
     simple_expression
     | discrete_range
     |element_simple_name
     |others

+0

Champion. Спасибо, что восполнили пробел в моем понимании. – CJC

Смежные вопросы