User guide
22-6
SystemVerilog Design Constructs
In this example we have declared shortint variables northsouth
and eastwest, that can hold a set of unassigned constants named
green, yellow, and red.
The default data type for an enumerated data type is int. If you omit
the data type in the enumeration, the variables declared have the int
data type.
You can make assignments to the constants in the enumeration.
For example:
enum{now=0,next=1,old=2}cs,ns,tmp;
You can declare a user-defined data type and then use it as the base
type for an enumeration. For example:
typedef bit [1:0] mybit;
typedef enum mybit {red=2’b00, green=2’b01, blue=2’b10,
yellow=2’b11} colors;
You can use the following data types as the base type of an
enumeration:
reg logic int integer shortint longint byte
Unpacked dimensions are not allowed in the base type.
Methods for Enumerations
SystemVerilog contains a number of methods for enumerations.
These methods do the following:
.first
Displays the value of the first constant of the enumeration.