SystemVerilogのclassでパラメータを使う
継承したクラスからベースクラスへパラメータを渡す。
classの最初で受け渡してやればOK。
superクラスのvirtual interfaceのbit幅のパラメータってどうやって設定するんだろう。。。
ってなったのがきっかけ。
virtual function になってはいますが、名前が違うのでオーバーライドはしていません。
基底クラス
1 2 3 4 5 6 7 8 | class base_class #(parameter base_p=1); function new(); endfunction virtual function void base_disp(); $display("base_p = %d",base_p); endfunction : base_disp endclass |
継承クラス
1 2 3 4 5 6 7 8 9 | class ext_class #(parameter ext_p=2) extends base_class #(.base_p(ext_p)); function new(); super.new(); endfunction virtual function void ext_disp(); $display("ext_p = %d",ext_p); endfunction : ext_disp endclass |
テストベンチトップ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | module tb_top; `include "base_class.sv" `include "ext_class.sv" base_class bc; ext_class ec; initial begin bc = new(); ec = new(); param_ec = new(); bc.base_disp(); ec.base_disp(); ec.ext_disp(); end endmodule |
実行結果
base_p = 1
base_p = 2
ext_p = 2
基本なのかな。。。基本だよね。。。