【问题标题】:How do I populate a dynamic array via uvm factory如何通过 uvm 工厂填充动态数组
【发布时间】:2019-05-14 20:10:52
【问题描述】:

您好,假设我有这样的代码,参数 NUM_MASTERS 和 NUM_SLAVES 是在配置对象中定义的:

class abc extends uvm_scoreboard;
configuration cfg;
wrapper_class master[]; //i am instantiating a dynamic array of class objects, one each for all masters and another for slaves 
wrapper_class slave[];
extern function new(string name = "abc", uvm_component parent = null);
extern function void build_phase(uvm_phase phase);
endclass


function abc::new(string name = "abc", uvm_component parent = null);
super.new(name, parent);
end
function void abc::build_phase(uvm_phase phase);
super.build_phase(phase);
uvm_config_db#(config_type)::get)this."*","configuration", cfg);
//this is where the error is happening
for(int i = 0; i < cfg.NUM_MASTERS : i++) 
  masters[i] = wrapper_class::type_id::create($sformatf("masters[%0d]",i),this);
for(int i = 0;i < cfg.NUM_SLAVES; i++) 
  slaves[i] =wrapper_class::type_id::create($sformatf("slaves[%0d]",i),this);
endfunction

谁能告诉我如何填充这些动态数组?我必须从构建阶段开始执行它们,因为只有这样我才能从 cfg 对象访问 NUM_MASTERS 和 NUM_SLAVES。非常感谢任何帮助/建议。谢谢。

【问题讨论】:

    标签: arrays dynamic system-verilog uvm


    【解决方案1】:

    你需要new动态数组才能访问它们。

    function void abc::build_phase(uvm_phase phase);
      super.build_phase(phase);
      uvm_config_db#(config_type)::get)this."*","configuration", cfg);
      masters = new[cfg.NUM_MASTERS];
      foreach( masters[i] ) 
        masters[i] = wrapper_class::type_id::create($sformatf("masters[%0d]",i),this);
      slaves = new[cfg.NUM_SLAVES];
      foreach( slaves[i] )
        slaves[i] =wrapper_class::type_id::create($sformatf("slaves[%0d]",i),this);
    endfunction
    

    【讨论】:

    • 谢谢戴夫。成功了!,你很擅长这些东西。
    猜你喜欢
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 2015-08-15
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多