2016-07-04 6 views
2

Betrachten wir eine ArtVHDL Zuordnung zu einem Array-Typ

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

Warum muss ich einen Compiler-Fehler, wenn ich versuche, einen konstanten Wert dieser Art zu schaffen, zum Beispiel. Beachten Sie, dass ich nur Alteras Quartus II versucht habe.

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

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

aber alles ist in Ordnung, wenn mein Typ

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

mit einem Beispiel die Zuordnung zu einer Konstante ist:

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

Darüber hinaus der Ansicht, dass ich versuche, Index 0 zuweisen mit einer anderen Konstante. Beispielsweise.

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 ); 

die Compiler, um der der Fehler ist jetzt spucken:

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

Also im Grunde seine mir zu sagen, dass der Compiler nicht erkennen, dass die Zuordnung zu dem Index von 0 ist, sondern eine Zuordnung zu der Array-Typ.

Wie kann ich den Compiler wissen lassen, dass die Zuweisung nur 0 indizieren soll?

Antwort

4

IEEE Std 1076 9.3.3 Aggregate, 9.3.3.1 Abs 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.

Mit einem 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; 

Sie müssen mit einem einzelnen Element mit dem Namen Vereinigung verwenden. Das erste Beispiel gibt den Index 0, das zweite beliebige Elemente an.

Abs 3 des obigen Abschnitt zitiert:

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.

Es ist hilfreich, die BNF zu sehen:

aggregate ::=
( element_association { , element_association } )

element_association ::=
     [ choices => ] expression

choices ::= choice { | choice }

choice ::=
     simple_expression
     | discrete_range
     |element_simple_name
     |others

+0

Meister. Danke, dass Sie die Lücke in meinem Verständnis geschlossen haben. – CJC