Printing an enum by name


While displaying messages, how do I print an enum’s name?


You can call the .name() function on a variable of enum type to return the enum type as a string.

You can also just use .name without the braces.

module test_enum;
    typedef enum {
        REG0, REG1, REG2
    } regname_e;

    initial begin
        regname_e regname;

        regname = REG1;
        $display("regname is %s",;

        regname = REG2;
        $display("regname is %s",;


regname is REG1
regname is REG2