Previous

Enumeration Types

An enumeration type is defined by listing (enumerating) all possible values of that type.

The syntax of an enumeration type definition follows.

     type type_name is ( enumeration_literal 
                        {, enumeration_literal} );

type_name is an identifier, and each enumeration_literal is either an identifier (enum_6) or a character literal ('A').

An identifier is a sequence of letters, underscores, and numbers. An identifier must start with a letter and cannot be a VHDL reserved word, such as TYPE.

A character literal is any value of type CHARACTER, in single quotes.

The following example shows two enumeration type definitions and the corresponding variable and signal declarations.

     type COLOR is (BLUE, GREEN, YELLOW, RED);
    
     type MY_LOGIC is ('0', '1', 'U', 'Z');
    
     variable HUE: COLOR;
    
     signal SIG: MY_LOGIC;
     . . .
     HUE := BLUE;
     SIG <= 'Z';

Enumeration Overloading

You can overload an enumeration literal by including it in the definition of two or more enumeration types. When you use such an overloaded enumeration literal, Foundation Express can usually determine the literal's type. However, under certain circumstances, determination may be impossible. In these cases, you must qualify the literal by explicitly stating its type. (See the “Qualified Expressions” section of the “Expressions” chapter.) The following example shows how you can qualify an overloaded enumeration literal.

    type COLOR is (RED, GREEN, YELLOW, BLUE, VIOLET);
    type PRIMARY_COLOR is (RED, YELLOW, BLUE);
    ...
    A <= COLOR'(RED);

Enumeration Encoding

Enumeration types are ordered by enumeration value. By default, the first enumeration literal is assigned the value 0, the next enumeration literal is assigned the value 1, and so forth.

Foundation Express automatically encodes enumeration values into bit vectors that are based on each value's position. The length of the encoding bit vector is the minimum number of bits required to encode the number of enumerated values. For example, an enumeration type with five values has a three-bit encoding vector.

The following example shows the default encoding of an enumeration type with five values.

   type COLOR is (RED, GREEN, YELLOW, BLUE, VIOLET);

The enumeration values are encoded as follows.

    RED  ; ; ;= “000”
    GREEN  ;= “001”
    YELLOW = “010”
    BLUE  ; ;= “011”
    VIOLET = “100”

The result is RED < GREEN < YELLOW < BLUE < VIOLET.

You can override the automatic enumeration encodings and specify your own enumeration encodings with the ENUM_ENCODING attribute.


NOTE

The interpretation of the ENUM_ENCODING attribute is specific to Foundation Express. Other VHDL tools, such as simulators, use the standard encoding (ordering).


The ENUM_ENCODING attribute must be a STRING containing a series of vectors, one for each enumeration literal in the associated type. The encoding vector is specified by 0s, 1s, Ds, Us, and Zs separated by blank spaces. The meaning of these encoding vectors is described in the “Enumeration Encoding Values” section of this chapter.

The first vector in the attribute string specifies the encoding for the first enumeration literal. The second vector specifies the encoding for the second enumeration literal, and so on. The ENUM_ENCODING attribute must immediately follow the type declaration.


NOTE

Several VHDL synthesis-related attributes are declared in the ATTRIBUTES package supplied with Foundation Express.


A VHDL attribute is defined by its name and type and is then declared with a value for the attributed type, as shown in the example below which illustrates how the default encodings from the previous example can be changed with the ENUM_ENCODING attribute.

   attribute ENUM_ENCODING: STRING;
            -- Attribute definition
    
   type COLOR is (RED, GREEN, YELLOW, BLUE, VIOLET);
   attribute ENUM_ENCODING of
   COLOR: type is "010 000 011 100 001";
             -- Attribute declaration

The enumeration values are encoded as follows.

    RED    = "010"
    GREEN  = "000"
    YELLOW = "011"
    BLUE   = "100"
    VIOLET = "001"

The result is GREEN<VIOLET<RED<YELLOW<BLUE.

Enumeration Encoding Values

The possible encoding values for the ENUM_ENCODING attribute follow.

See the “Three-State Inference” section in the chapter “Register Inference” for more information.

Next