User guide
22-7
SystemVerilog Design Constructs
.last
Displays the value of the last constant of the enumeration.
.next
Displays the value of the next constant of the enumeration.
.prev
Displays the value of the previous constant in the enumeration.
.num
Displays the total number of constants in the enumeration.
.name
Displays the name of the constant in the enumeration.
The following is an example of the use of these methods:
module top;
typedef enum {red, green, blue, yellow} Colors;
Here is an enumeration named Colors. It has four constants named
red, green, blue and yellow and ranging in value from 0 to 3.
Colors color = color.first;
We declare a Colors variable named color and initialize it to the value
of the first constant in the enumeration.
initial
begin
$display("Type Colors:\n");
$display("name\tvalue\ttotal\tprevious\tnext\tlast\tfirst\n");
forever begin
$display("%0s\t%0d\t%0d\t%0d\t\t%0d\t%0d\t%0d\n",
color.name,color,color.num,color.prev,color.next,color.last,
color.first);
if (color == color.last) break;
color = color.next;
end
end