verilator/test_regress/t/t_class_virtual.v

109 lines
2.1 KiB
Systemverilog
Raw Normal View History

// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2019 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
2020-08-23 17:50:42 +02:00
virtual class VBase;
virtual function int hello;
return 1;
endfunction
virtual class VNested;
virtual function int hello;
return 10;
endfunction
endclass
endclass
2020-08-23 17:50:42 +02:00
2020-08-24 02:27:25 +02:00
class VA extends VBase;
2020-08-23 17:50:42 +02:00
virtual function int hello;
return 2;
endfunction
class VNested extends VBase::VNested;
virtual function int hello;
return 20;
endfunction
endclass
2020-08-23 17:50:42 +02:00
endclass
2020-08-24 02:27:25 +02:00
class VB extends VBase;
2020-08-23 17:50:42 +02:00
virtual function int hello;
return 3;
endfunction
class VNested extends VBase::VNested;
virtual function int hello;
return 30;
endfunction
endclass
2020-08-23 17:50:42 +02:00
endclass
2023-10-24 15:51:46 +02:00
virtual class uvm_phase;
virtual function int exec_func;
return 0;
endfunction
endclass
class uvm_topdown_phase extends uvm_phase;
function int get1;
return exec_func();
endfunction
endclass
class uvm_build_phase extends uvm_topdown_phase;
virtual function int exec_func;
return 1;
endfunction
endclass
virtual class Cls;
uvm_phase ph;
endclass
class ExtendsCls extends Cls;
function new;
uvm_build_phase bp = new;
ph = bp;
endfunction
function int get1;
return super.ph.exec_func();
endfunction
endclass
2020-08-23 17:50:42 +02:00
module t;
initial begin
VA va = new;
VB vb = new;
VA::VNested vna = new;
VB::VNested vnb = new;
2020-08-23 17:50:42 +02:00
VBase b;
VBase::VNested bn;
2020-08-24 02:27:25 +02:00
2023-10-24 15:51:46 +02:00
uvm_build_phase ph;
ExtendsCls ec;
2020-08-24 02:27:25 +02:00
if (va.hello() != 2) $stop;
if (vb.hello() != 3) $stop;
if (vna.hello() != 20) $stop;
if (vnb.hello() != 30) $stop;
2020-08-24 02:27:25 +02:00
2020-08-23 17:50:42 +02:00
b = va;
bn = vna;
2020-08-23 17:50:42 +02:00
if (b.hello() != 2) $stop;
if (bn.hello() != 20) $stop;
2020-08-23 17:50:42 +02:00
b = vb;
bn = vnb;
2020-08-23 17:50:42 +02:00
if (b.hello() != 3) $stop;
if (bn.hello() != 30) $stop;
2023-10-24 15:51:46 +02:00
ph = new;
if (ph.get1() != 1) $stop;
ec = new;
if (ec.get1() != 1) $stop;
2020-08-23 17:50:42 +02:00
$write("*-* All Finished *-*\n");
$finish;
end
endmodule