verilator/test_regress/t/t_with.v

62 lines
1.7 KiB
Systemverilog
Raw Normal View History

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;
byte byteq[$] = {2, -1, 127};
2020-06-06 15:11:23 +00:00
aliases = '{ 1, 4, 6, 8};
tofind = 6;
found = aliases.find with (item == 1);
2022-05-15 13:29:15 +00:00
`checkh(found.size, 1);
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
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);
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);
i = aliases.or(v) with (v);
2022-05-15 13:29:15 +00:00
`checkh(i, 'hf);
i = aliases.and(v) with (v);
2022-05-15 13:29:15 +00:00
`checkh(i, 0);
i = aliases.xor(v) with (v);
2022-05-15 13:29:15 +00:00
`checkh(i, 'hb);
$write("*-* All Finished *-*\n");
$finish;
2020-06-06 15:11:23 +00:00
end
endmodule