Jump to content
Sign in to follow this  
Kinjal

Cloning on dynamic objects

Recommended Posts

Is UVM clone/copy works for dynamic objects too?

I am trying with below code and it looks something wrong.

Can someone help?

----------------------------------------------------------------------------------------------------

class abc extends uvm_sequence_item;

rand byte data[];

constraint size_data { data.size() <= 1000; };

`uvm_object_utils_begin(abc)

`uvm_field_array_int(data, UVM_ALL_ON)

`uvm_object_utils_end

endclass

class xbus_transfer extends uvm_sequence_item;

abc abc_inst[];

function void pre_randomize();

.........

abc_inst = new[5];

endfunction

`uvm_object_utils_begin(xbus_transfer)

....................

`uvm_field_array_object(abc_inst, UVM_ALL_ON)

`uvm_object_utils_end

......

......

-----------------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites

UVM_DEFAULT (as opposed to UVM_ALL_ON) sets UVM_DEEP which will cause the sub-object to the cloned as well. You can also explicitly set: UVM_ALL_ON | UVM_DEEP, UVM_ALL_ON | UVM_SHALLOW, or UVM_ALL_ON | UVM_REFERENCE when specifying object fields.

UVM_SHALLOW may not be completely implemented.

Share this post


Link to post
Share on other sites

I tried with UVM_DEEP / UVM_SHALLOW. It doesn't work. I can't use UVM_REFERENCE as I am modifying and thats why I am using copy().

Can you show some good example for UVM_DEEP targeting this case? It will be really good.

Share this post


Link to post
Share on other sites

Here's what I did:

class my_sub extends uvm_object;

int val;

`uvm_object_utils_begin(my_sub)

`uvm_field_int(val,UVM_DEFAULT)

`uvm_object_utils_end

endclass

class my_obj extends uvm_object;

my_sub sub;

`uvm_object_utils_begin(my_obj)

`uvm_field_object(sub,UVM_DEFAULT)

`uvm_object_utils_end

endclass

class my_vseq extends uvm_sequence#();

`uvm_object_utils(my_vseq)

task body();

`uvm_info( get_type_name(), "sequence", UVM_MEDIUM )

begin

my_obj obj = my_obj::type_id::create("obj",,get_full_name());

my_obj obj2;

obj.sub = my_sub::type_id::create("sub",,obj.get_full_name());

obj.sub.val = 3;

`uvm_info( get_type_name(), $sformatf("obj val=%0d\n%0s", obj.sub.val, obj.sprint() ), UVM_LOW )

$cast(obj2, obj.clone());

`uvm_info( get_type_name(), $sformatf("obj2 val=%0d\n%0s", obj2.sub.val, obj2.sprint() ), UVM_LOW )

end

endtask

endclass

I get:

UVM_INFO my_pkg.sv(28) @ 0: reporter [my_vseq] sequence

UVM_INFO my_pkg.sv(34) @ 0: reporter [my_vseq] obj val=3

----------------------------------------------------------------------

Name Type Size Value

----------------------------------------------------------------------

obj my_obj - @2018

sub my_sub - @2011

val integral 32 'h3

----------------------------------------------------------------------

UVM_INFO my_pkg.sv(37) @ 0: reporter [my_vseq] obj2 val=3

----------------------------------------------------------------------

Name Type Size Value

----------------------------------------------------------------------

obj my_obj - @2017

sub my_sub - @1990

val integral 32 'h3

----------------------------------------------------------------------

You can see that clone() creates a new sub object.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×