How to implement $sformatf on register models


I have four regmodels with names cp_0,cp_1,cp_2, and cp_3. While using the register models the code for all four is the same instead of doing repetitive work I wanted to use $sformatf in place of numerics


where regr is number between 0 to 2 .

I’m having compilation errors saying cant have an identifier .

Any help in formating this reg model ?

In reply to Sv-hustler:

You want to implement a hierarchical path using $sformatf. A hierarchical path consists of instance/object names, but $sformatf creares string and not a name.

In reply to chr_sue:

Thanks for the reply. So the only way possible is to repeat the code for different models ?

I wanted to avoid this repetitive work

In reply to Sv-hustler:

The RAL allows you to look up a register by name. While not as clean as accessing a register directly, it gives you the flexibility to use $sformatf() to get a register handle.

In reply to cgales:

regr= $sformatf(“m_cp%0d”,quad_var);


This has an error : registers not a class item /

In reply to Sv-hustler:

The get_block_by_name() returns a uvm_reg_block handle. You will need to $cast it to your specific block type to be able to access the registers.

In reply to cgales:

Thanks cgales . $cast didn’t pop up in my thoughts