SystemVerilog Print enum as String

SystemVerilog print enum name

As we know enum defines a set of named values.
refer to SystemVerilog enum for detailed description.

Printing or displaying the enum name is easy for debug, by using enum method “name”, enum name can be displayed.

module enum_datatype;
  typedef enum int { red=0, green=1, blue=4, yellow, white=6, black=9 } Colors;
  Colors color;
  initial begin
    color = 4;
    $display("Colors  ::  Value of %0s is \t= %0d",,color);

Simulator Output

Colors :: Value of blue is = 4

Click to execute on