SystemVerilog class の this

SystemVerilog「this」 を使ってみましょう。というお話です。

  • サンプルコード
class base;
  int a;

  virtual function void set_a(int in);
    a = in;
  endfunction

endclass

class hoge extends base ;

  int a;

  function void set_a(int in);
    this.a = in;
    $display("--- this.a = %3d, super.a = %3d", this.a, super.a);
  endfunction

endclass

module testbench;

  hoge cl_hoge = new;

  initial begin
    cl_hoge.set_a(10);
    $finish;
  end

endmodule
  • 実行結果
# --- this.a =  10, super.a =   0

解説

base そしてそれを継承した hogeに対してそれぞれ変数 aというものが存在します。
その際にthisを使うことにより、自身の変数 aに代入していることがわかります。