我正在創建一個需要對測試臺的配置對象進行引用的類。由於配置在整個模擬過程中必須保持完整,我將它作爲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