有没有办法在 UVM 层次结构中获取给定类型的所有对象?

问题描述

我正在寻找一种方法获取给定 uvm_object 类的所有实例,最好使用层次结构/范围和名称进行过滤。这可以在 UVM 1.2 中实现吗?我尝试了以下方法,看起来可能有效

uvm_resource_pool rp = uvm_resource_pool::get();
uvm_resource#(T) _type = new();
uvm_queue#(uvm_resource_base) q;

q = rp.lookup_regex_names(parent.get_full_name(),"*name*",_type);

q.size() 始终为 0。诚然,这是我第一次接触 uvm_resource_pool 等,所以我什至不确定它是否可以这样使用。我的设置有问题吗?或者有没有更好的方法来实现我想要做的事情?

解决方法

uvm_component 有一个方法 get_children。使用这个函数可以直接从根组件开始遍历组件树。

function enumerate_components(uvm_component root);
begin
  uvm_component children[$];
  foreach(children[i]) begin
    enumerate_components(children[i]);
  end
end
endfunction

您可以扩展此函数以使用 uvm_object 中的 get_type_name 检查类型。

function enumerate_components(uvm_component root,ref uvm_component components[$],string type_name);
begin
  uvm_component children[$];
  if(root.get_type_name() == type_name) begin
    components.push_back(root);
  end
  foreach(children[i]) begin
    enumerate_components(children[i],components,type_name);
  end
end
endfunction

那么你就可以这样使用了

uvm_component components[$];
enumerate_components(uvm_root::get(),"InterestingComponent");
foreach(components[i]) begin
  // do interesting things
end

我没有测试它,让我知道它是怎么回事。