Consider a scenario where an array of a small interface is instantiated within a top interface which is set to config_db from top module. An ENV class gets this top interface handle and distributes the small interfaces to agents as required. I wanted to write a code in ENV build phase which would look like this :
//Get top interface handle to top_intf here
for (int i=0; i<10; i++) begin
uvm_config_db#(virtual req_ack_if)::set(this,$sformatf("agent[%0d]*",i),"req_ack_if",top_intf.sub_intf[i].req_ack_inf);
end
The above code won’t compile because compiler won’t be able to find sub_intf without a constant value inside to determine hierarchy. Can this code be modified so as to not manually unroll the loop?
No, but you should be setting the config_db() handles at the top-level of your testbench, not inside any class hierarchy. I missed that you were trying to do this in your environment, so move those assignments outside of the environment.