2021-12-13 00:49:06 +00:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
2022-01-01 18:48:53 +00:00
`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);
2021-12-13 00:49:06 +00:00
// See also t_class_param.v
module t ( /*AUTOARG*/ ) ;
2022-01-01 18:48:53 +00:00
class Cls # ( parameter PBASE = 12 ) ;
bit [ PBASE - 1 : 0 ] member ;
function bit [ PBASE - 1 : 0 ] get_member ;
2021-12-13 00:49:06 +00:00
return member ;
endfunction
2022-01-01 18:48:53 +00:00
static function int get_p ;
return PBASE ;
2021-12-13 00:49:06 +00:00
endfunction
2022-01-01 18:48:53 +00:00
typedef enum { E_PBASE = PBASE } enum_t ;
2021-12-13 00:49:06 +00:00
endclass
2022-01-01 18:48:53 +00:00
class Wrap # ( parameter P = 13 ) ;
2021-12-13 00:49:06 +00:00
function int get_p ;
return c1 . get_p ( ) ;
endfunction
2022-01-01 18:48:53 +00:00
function new ;
c1 = new ;
endfunction
Cls # ( PMINUS1 + 1 ) c1 ;
localparam PMINUS1 = P - 1 ; // Checking works when last
2021-12-13 00:49:06 +00:00
endclass
2022-01-01 18:48:53 +00:00
typedef Cls # ( 8 ) Cls8_t ;
2021-12-13 00:49:06 +00:00
Cls c12 ;
2022-01-01 18:48:53 +00:00
Cls # ( . PBASE ( 4 ) ) c4 ;
Cls8_t c8 ;
Wrap # ( . P ( 16 ) ) w16 ;
2021-12-13 00:49:06 +00:00
initial begin
c12 = new ;
c4 = new ;
2022-01-01 18:48:53 +00:00
c8 = new ;
2021-12-13 00:49:06 +00:00
w16 = new ;
2022-01-01 18:48:53 +00:00
if ( Cls # ( ) : : PBASE ! = 12 ) $stop ;
if ( Cls # ( 4 ) : : PBASE ! = 4 ) $stop ;
if ( Cls8_t : : PBASE ! = 8 ) $stop ;
if ( Cls # ( ) : : E_PBASE ! = 12 ) $stop ;
if ( Cls # ( 4 ) : : E_PBASE ! = 4 ) $stop ;
if ( Cls8_t : : E_PBASE ! = 8 ) $stop ;
if ( c12 . PBASE ! = 12 ) $stop ;
if ( c4 . PBASE ! = 4 ) $stop ;
if ( c8 . PBASE ! = 8 ) $stop ;
if ( Cls # ( ) : : get_p ( ) ! = 12 ) $stop ;
if ( Cls # ( 4 ) : : get_p ( ) ! = 4 ) $stop ;
if ( Cls8_t : : get_p ( ) ! = 8 ) $stop ;
2021-12-13 00:49:06 +00:00
if ( c12 . get_p ( ) ! = 12 ) $stop ;
if ( c4 . get_p ( ) ! = 4 ) $stop ;
2022-01-01 18:48:53 +00:00
if ( c8 . get_p ( ) ! = 8 ) $stop ;
2021-12-13 00:49:06 +00:00
if ( w16 . get_p ( ) ! = 16 ) $stop ;
2022-01-01 18:48:53 +00:00
2021-12-13 00:49:06 +00:00
// verilator lint_off WIDTH
c12 . member = 32 'haaaaaaaa ;
c4 . member = 32 'haaaaaaaa ;
2022-01-01 18:48:53 +00:00
c8 . member = 32 'haaaaaaaa ;
2021-12-13 00:49:06 +00:00
// verilator lint_on WIDTH
if ( c12 . member ! = 12 'haaa ) $stop ;
if ( c4 . member ! = 4 'ha ) $stop ;
if ( c12 . get_member ( ) ! = 12 'haaa ) $stop ;
if ( c4 . get_member ( ) ! = 4 'ha ) $stop ;
2022-01-01 18:48:53 +00:00
`checks ( $sformatf ( " %p " , c12 ) , " '{member:'haaa} " ) ;
`checks ( $sformatf ( " %p " , c4 ) , " '{member:'ha} " ) ;
2021-12-13 00:49:06 +00:00
$write ( " *-* All Finished *-* \n " ) ;
$finish ;
end
endmodule