copy fields from one class to another inside sequence item

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



copy fields from one class to another inside sequence item



I have two class handles inside my sequence item. One of the classes contains a handle for the other class. pseudo code looks like this:


class seq_item extends uvm_sequence_item;
rand class_a a;
rand class_b b;
endclass// seq_item

class class_a extends uvm_object;
rand bit field_1;
rand bit field_2;
endclass//class_a

class class_b extends uvm_object;
class_a a_handle;
rand bit field_3;
rand bit field_4;
endclass // class_b



So, when I randomize; I'd like a_handle to have field_1 and field_2 values as that of 'a' from seq_item. I tried cloning ($cast(b.a_handle, a.clone()) inside post_randomize of seq_item, but it isn't working.
How do I make sure that values of b.a_handle.field_1, b.a_handle.field_2 are same as that of a.field_1, a.field_2 ?





It would help to explain what "It isn't working" means. Compiler error or results different from what you expect?
– dave_59
Aug 12 at 3:23






I have a_handle.field_1 accessed inside class_b method. At run time, I am getting 'Null object access error' on a_handle.field_1 from that method.
– Pri
Aug 12 at 5:26





I was able to fix, 'Null object access' error. I was trying to 'new' class_b.a_handle inside seq_item's pre_randomize method, which was incorrect I guess. I moved it to class_b's 'new' method.
– Pri
Aug 12 at 5:48




1 Answer
1



You can have a constraint do this for you inside seq_item


constraint fields
a.field_1 == b.a_handle.field_1;
a.field_2 == b.a_handle.field_2;



You also need to declare a_handle as rand in class_b


a_handle


rand


class_b





Ok. I'll try that. But, just wanted to know if there is any other way to do it, since I have about 30 fields in class_a. I'll have to constrain them one by one otherwise. And would you be able to tell why clone won't work in this case? Is it because the fields are of 'rand' type?
– Pri
Aug 12 at 5:30





I'm not sure what you are trying to do, so can't help much more. Why do you need to separate objects of class_a? Can they point to the same object.
– dave_59
Aug 12 at 5:58





I don't need separate objects of class_a. But, without doing that, how can I access fields of object a (from seq_item) inside object b's methods?
– Pri
Aug 12 at 6:29





After constructing b, b.a_handle = a;
– dave_59
Aug 12 at 7:37


b


b.a_handle = a;





Ideally, what you mentioned should work, but somehow inside class_b, I still don't see field_1, field_2 from class_a. Need to debug more. Thanks for your input.
– Pri
Aug 13 at 2:06






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS