如何将参数化类传递给模块实例?

时间:2016-01-12 13:34:50

标签: system-verilog

include "cls.sv"
module top();

    int x;
    spl_cls #(10) o_spl_cls;
    /*Code Continues, here o_spl_cls object has been created using  
     new();*/ 
    dummy  i_dummy(o_spl_cls); //I instantiated another module and passed  
                               //object 
endmodule

//This is my dummy module
module dummy(spl_cls i_spl_cls);
....
endmodule

//my spl_cls is
class spl_cls#(int data=0);
//...rest code
endclass

我收到错误。 如何将参数化对象传递给另一个模块实例或类?

1 个答案:

答案 0 :(得分:1)

您需要参数化您想要进行分配的spl_cls的所有引用。

module dummy(spl_cls#(10) i_spl_cls);
....
endmodule

更好的解决方案是使用typedef

module top();
    typedef spl_cls #(10) spl_cls_10;
    int x;
    spl_cls_10 o_spl_cls;
    /*Code Continues, here o_spl_cls object has been created using  
     new();*/ 
    dummy #(spl_cls_10) i_dummy(o_spl_cls); //I instantiated another module and passed  
                               //object 
endmodule

//This is my dummy module
module dummy #(type C)(C i_spl_cls);
....
endmodule