SystemVerilog class の super

SystemVerilog classにて、super というものがあります。

  • サンプルコード
class base;
  virtual function void show(int a, int b);
    $display("- a = %3d, b = %3d", a, b);
  endfunction
endclass

class hoge extends base;
  function void show(int a, int b=0);
    if (b != 0) super.show(a,b);
    else        $display("- a = %3d", a);
  endfunction
endclass

module testbench;

  int i,j;
  hoge cl_hoge = new;

  initial begin
    i = 10; j = 4;
    cl_hoge.show(i);
    cl_hoge.show(i,j);
    $finish;
  end

endmodule
  • 実行結果
# --- a =  10
# --- a =  10, b =   4

解説

継承したクラス(ここでは、hoge)にて、オーバーライドされた show関数の 引数 bが 0以外であった場合に baseクラスの show関数を呼んでいます。 その際に、super を使うことで実現することができます。 ただし、一つ上(baseクラス)しか記述できません。