Configuring a variable without uvm_config_db::get

Hi,

I have seen few working codes where a variable is set using uvm_config_db::set but it doesn’t require a get method to get the variable value.

For an example:

module top
initial begin
environment = new(“env”);
uvm_config_db#(string)::set(top.environment,“”,“myString”,“StringHasBeenSet”);
end
endmodule

class env extends uvm_env;
string myString;
function void connect_phase(uvm_phase phase);
`uvm_info(“LABEL”, $psprintf(“Value of myString = %0s”,myString), UVM_NONE);
endfunction: connect_phase
endclass

Output:

Value of myString = StringHasBeenSet


Without calling uvm_config_db::get, how myString var gets the value?

In reply to dharamvir:

There are several possibilities:

  • The value is set by the parent.
  • The class uses the field automation macros, which will attempt to get the value from the config_db() using the variable name.

Neither of these methods are recommended. Instead, you should have a configuration object which encapsulates all of the configuration variables, reducing the number of calls to the config_db.

In reply to cgales:

I think it’s the second method which is assigning the value in this case.
I was not aware of this feature.

Could you please elaborate on how this works or could you please point me out that particular macro which looks into config_db?

In reply to dharamvir:

The uvm_object_defines.svh file has all of the different uvm_field_* macros defined. I believe that it has to do with the UVM_SET* parts of the macros.

In reply to cgales:

Thanks.

I have one more doubt, this field_automation_macro will affect only in build_phase, correct?

I mean if I call config_db::set after build_phase then this will not happen.

In reply to dharamvir:

I’m not sure what will happen, as it is HIGHLY recommended to NOT USE the field macros, and therefore I have never tried.

My assumption is that if nothing has been set() in the config_db for the specified variable, then the get() will silently fail. The implicit assigning of values by the macro does nothing to prevent you from calling get() when you need to.

In reply to cgales:

Thanks cgales for your time.

Out of curiosity I just tried this, it will not affect if you set the variable after the build_phase started.

One non-technical thing, (it’s technical though :))

I got a mail saying “chr_sue” replied to this thread but I don’t see it here.