0

I'm stuck in a problem and would appreciate any input/suggestion:

I've an agent for my test bench which has following components: a base class A- it defines two static variables- X and Y two new classes B and C, BOTH extended from A. They both use the static variable declared in base class. Another class D which utilizes B and C to do something.

Lets say class D is my top agent and I call it bfm_agent. This bfm_agent can be instantiated multiple times in my test bench. Now the problem is, X and Y will be shared to all bfm_agent. I don't want that. I just want X and Y to be static so that class B and C inside each bfm_agent can use these two variables to do some work.

How can I achieve this? I just want the scope of these two static variable to be valid only within each instance of bfm_agent.

1 Answer 1

2

You should use a configuration object that contains the variables X and Y. Then have the base class A construct the config object if it does not exist and then do set it for each instance of the agent.

class A extends uvm_component;

my_config_c myconfig;

function void build_phase(uvm_phase phase);
...
  if(!uvm_config_db#(myconfig)::get(get_parent(),"","myconfig",myconfig)) begin
     myconfig = my_config_c::type_id::create("myconfig");
     uvm_config_db#(myconfig)::set(get_parent(),"","myconfig",myconfig)
  end
endfunction

Now both classes B and C will be able to refer to myconfig.X and myconfig.Y.

Sign up to request clarification or add additional context in comments.

2 Comments

@newbie static means across all instances. What you want are instance variables. If you declared your X and Y variables as static in order to do this kind of sharing I would say you remove the static keyword and assign the correct values for each instance. Dave's approach works best if you're using UVM.
Since the post was tagged with UVM I assumed they were already using it. If notm you could still do something similar by sharing handles, not the variables themselves.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.