Parameterized sequence item

I am working on a verification environment that instantiates different versions of DUT’s. for instance:


module DUT_v1 ();
   parameter size = 1;
   reg [size -1:0] mem;
endmodule

module DUT_v2 ();
   parameter size = 2;
   reg [size -1:0] mem;
endmodule

where in the test bench the user can write

DUT_v1 DUT ();

or

DUT_v2 DUT ();

etc. according to his needs.

I would like to write a sequence item that is parameterized automatically according to the version of the DUT that the user puts in the test bench. iv’e tried-


class item extends ovm_sequence_item;
   parameter size = $root.tb.DUT.size;
   rand reg[size - 1: 0 ] mem;
endclass

but that doesn’t work. How am I to achieve this?

Thanks

In reply to harry_torch:

Two problems with your approach: parameters can’t be assigned with hierarchical references to other parameters, and you can’t have hierarchical references to anything within a package (assuming your class is defined inside a package).

Something in your compilation script had to choose between the testbench that instantiates DUT_V1 or DUT_V2. That same script could choose between two packages that define global parameters for your verification environment. i.e.

// package for DUT_V1
package ver_env;
 parameter size = 1;
endpackage

rand reg[ver_env::size - 1: 0 ] mem;

Even better would be if the DUT and testbench used the parameter from the same package.

Another option is to declare your mem with the maximum size, and then use a config_db variable to retrieve the actual size of the mem,

initial begin
    uvm_config_db#int::set(null,"DUT","size",$root.tb.DUT.size);