2025-07-11 19:10:36 +02:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2025 by Petr Nohavica
// SPDX-License-Identifier: CC0-1.0
`define stop $stop
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
`define checks(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d: got='%s' exp='%s'\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
interface class IBottomMid ;
2025-10-08 03:06:11 +02:00
pure virtual function void moo ( int i ) ;
2025-07-11 19:10:36 +02:00
endclass
interface class IBottom ;
2025-10-08 03:06:11 +02:00
pure virtual function bit foo ( ) ;
2025-07-11 19:10:36 +02:00
endclass
interface class IMid extends IBottomMid ;
2025-10-08 03:06:11 +02:00
pure virtual function string bar ( ) ;
2025-07-11 19:10:36 +02:00
endclass
class bottom_class implements IBottom ;
2025-10-08 03:06:11 +02:00
string name ;
2025-07-11 19:10:36 +02:00
2025-10-08 03:06:11 +02:00
function new ( string name ) ;
this . name = name ;
endfunction
2025-07-11 19:10:36 +02:00
2025-10-08 03:06:11 +02:00
virtual function bit foo ( ) ;
$display ( " %s " , name ) ;
return 1 'b0 ;
endfunction
2025-07-11 19:10:36 +02:00
endclass
class middle_class extends bottom_class implements IMid , IBottom ;
2025-10-08 03:06:11 +02:00
function new ( string name ) ;
super . new ( $sformatf ( " middle %0s " , name ) ) ;
endfunction
virtual function bit foo ( ) ;
$display ( " %s " , name ) ;
return 0 ;
endfunction
virtual function void moo ( int i ) ;
$display ( " moo: %d " , i ) ;
endfunction
virtual function string bar ( ) ;
return name ;
endfunction
2025-07-11 19:10:36 +02:00
endclass
class top_class extends middle_class ;
2025-10-08 03:06:11 +02:00
int i ;
function new ( string name , int i ) ;
super . new ( $sformatf ( " %0s %0d " , name , i ) ) ;
this . i = i ;
endfunction
2025-07-11 19:10:36 +02:00
endclass
class sky_class extends top_class ;
2025-10-08 03:06:11 +02:00
function new ( string name ) ;
super . new ( name , 42 ) ;
endfunction
2025-07-11 19:10:36 +02:00
endclass
module t ;
2025-10-08 03:06:11 +02:00
initial begin
sky_class s = new ( " ahoj " ) ;
bottom_class b = s ;
top_class t = s ;
IMid im ;
`checks ( b . name , " middle ahoj 42 " ) ;
`checks ( s . name , " middle ahoj 42 " ) ;
`checks ( t . name , " middle ahoj 42 " ) ;
`checkh ( t . i , 42 ) ;
`checks ( s . bar ( ) , " middle ahoj 42 " ) ;
im = s ;
im . moo ( 42 ) ;
$finish ;
end
2025-07-11 19:10:36 +02:00
endmodule