我正在创建一个需要对测试台的配置对象进行引用的类。由于配置在整个模拟过程中必须保持完整,我将它作为const ref对象传递。这里是我想要运行的sudo代码:Systemverilog构造对象时的const ref arg位置
class tb_config;
int unsigned rate;
int unsigned chnls[];
const int unsigned nb_chnls;
function new (int unsigned rate, int unsigned nb_chnls);
this.rate = rate;
this.nb_chnls = nb_chnls;
chnls = new[nb_chnls];
endfunction
endclass
class tx_phy;
static int phy_id;
tb_config cfg;
function new (int unsigned phy_id, const ref tb_config cfg);
this.phy_id = phy_id;
this.cfg = cfg;
endfunction
endclass
module test;
tb_config cfg = new(100, 4);
tx_phy phy = new(1234, cfg);
endmodule
上面的代码工作得很好,符合我的期望。但是,如果我将tx_phy :: new中的参数更改为函数new(const ref tb_config cfg,int unsigned phy_id);并将值传递给构造相应我得到Cadence公司的Incisive以下错误:
invalid ref argument usage because actual argument is not a variable.
而且当我在edaplayground与Aldec公司的测试同样的事情发生:https://www.edaplayground.com/x/5PWV
我认为这是一个语言的限制,但是有没有其他原因?
非常感谢!现在它是有道理的。我只添加了ref,因为编译器在我没有指定它的时候给了我错误:期望的记号:'ref'。“”testbench.sv“ – maskarih