2020-06-06 15:11:23 +00:00
// DESCRIPTION: Verilator: Verilog Test module for SystemVerilog 'alias'
//
// Simple bi-directional alias test.
//
// 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-05-15 13:29:15 +00:00
`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);
2020-06-06 15:11:23 +00:00
module t ( /*AUTOARG*/ ) ;
initial begin
int tofind ;
int aliases [ $ ] ;
int found [ $ ] ;
int i ;
2022-05-15 13:53:48 +00:00
byte byteq [ $ ] = { 2 , - 1 , 127 } ;
2020-11-01 15:56:07 +00:00
2020-06-06 15:11:23 +00:00
aliases = ' { 1 , 4 , 6 , 8 } ;
tofind = 6 ;
2020-11-01 15:56:07 +00:00
found = aliases . find with ( item = = 1 ) ;
2022-05-15 13:29:15 +00:00
`checkh ( found . size , 1 ) ;
2020-11-01 15:56:07 +00:00
found = aliases . find ( j ) with ( j = = tofind ) ;
2022-05-15 13:29:15 +00:00
`checkh ( found . size , 1 ) ;
2020-06-06 15:11:23 +00:00
// And as function
2020-10-18 01:20:52 +00:00
aliases . find ( i ) with ( i = = tofind ) ;
2020-06-06 15:11:23 +00:00
// No parenthesis
2022-05-15 13:29:15 +00:00
tofind = 0 ;
found = aliases . find with ( item = = tofind ) ;
`checkh ( found . size , 0 ) ;
aliases . find with ( item = = tofind ) ;
2020-06-06 15:11:23 +00:00
2022-05-15 13:29:15 +00:00
// bug3387
i = aliases . sum ( ) ;
`checkh ( i , 'h13 ) ;
2022-05-15 13:53:48 +00:00
i = byteq . sum ( ) with ( int ' ( item ) ) ;
`checkh ( i , 128 ) ;
2020-11-26 16:50:50 +00:00
2020-06-06 15:11:23 +00:00
// Unique (array method)
2022-05-15 13:29:15 +00:00
tofind = 4 ;
found = aliases . find with ( tofind ) ; // "true" match
`checkh ( found . size , 4 ) ;
found = aliases . find ( ) with ( item = = tofind ) ;
`checkh ( found . size , 1 ) ;
found = aliases . find ( i ) with ( i = = tofind ) ;
`checkh ( found . size , 1 ) ;
2020-10-18 01:20:52 +00:00
i = aliases . or ( v ) with ( v ) ;
2022-05-15 13:29:15 +00:00
`checkh ( i , 'hf ) ;
2020-10-18 01:20:52 +00:00
i = aliases . and ( v ) with ( v ) ;
2022-05-15 13:29:15 +00:00
`checkh ( i , 0 ) ;
2020-10-18 01:20:52 +00:00
i = aliases . xor ( v ) with ( v ) ;
2022-05-15 13:29:15 +00:00
`checkh ( i , 'hb ) ;
2020-10-18 01:20:52 +00:00
$write ( " *-* All Finished *-* \n " ) ;
$finish ;
2020-06-06 15:11:23 +00:00
end
endmodule