Define and print enum vector in UVM

Hi,

I am trying to print a vector of enum type as shown below in code, but getting errors:

class mem_seq_item extends uvm_sequence_item;

  typedef enum logic [2:0] { 
    CL_INVALID    = 2'b00,
    CL_CLEAN      = 2'b01,
    CL_DIRTY      = 2'b10
  } t_cacheline_state;
  
  typedef t_cacheline_state [3:0] v_cacheline_state;
  rand v_cacheline_state  cacheline_state;

  //expectation is that cacheline_state should store value of 4 lines like {CL_INVALID,CL_CLEAN,CL_INVALID,CL_DIRTY}, it gets this value in uvm_monitor from interface. interface signal store the value in above format.
  
   
  //Utility and Field macros,
  `uvm_object_utils_begin(mem_seq_item)
  `uvm_field_enum(t_cacheline_state ,cacheline_state,UVM_DEFAULT)
  `uvm_object_utils_end


  
  //Constructor
  function new(string name = "mem_seq_item");
    super.new(name);
  endfunction
   
   virtual function void do_print(uvm_printer printer);
     printer.print_string("curent_CL_STATE",cacheline_state.name());
   endfunction
  
endclass


module seq_item_tb;
  
  //instance
  mem_seq_item seq_item;
  
  initial begin
    //create method
    seq_item = mem_seq_item::type_id::create(); 
    
    //randomizing the seq_item
    seq_item.randomize();
    
    //printing the seq_item
    seq_item.print();   
  end  
endmodule

I’m getting the below error for uvm_field_enum and do_print() both:

$unit, “this.cacheline_state.name”
The expression ‘this.cacheline_state’ is not an instance of an enum
variable.
Please refer to Section 6.19.5 ‘Enumerated type methods’ of the
SystemVerilog LRM Std. 1800-2012

is there any way to define the enum type to store multiple values of cache_line and print them?

Thanks,
Vineet

In reply to vineet_sharma:

The first recommendation is to not use the `uvm_field_XXX macros.

Second, cacheline_state is an array of enums. You most likely want to iterate over each item to print the name.


// Implementation example:
function string convert2string();
 string s;
 
 s = super.convert2string();
 // Note the use of \t (tab) and \n (newline) to format the data in columns
 // The enumerated cacheline_state types .name() method returns a string corresponding to its value
 foreach(cacheline_state[i]) begin
   $sformat(s, "%s cacheline_state[%0d] \t%s\n", s, i, cacheline_state[i].name());
 end
 return s;
endfunction: convert2string

function void do_print(uvm_printer printer);
  printer.m_string = convert2string();   
endfunction: do_print


In reply to vineet_sharma:

If extremely needed by your testbench you could use uvm_field_array_enum(T,ARG,FLAG). But again is not really recommend as suggested you could use the foreach or a do_print with customized implementation.

Regards