verilator/test_regress/t/t_dynarray_cast_write.v

40 lines
779 B
Systemverilog
Raw Normal View History

2024-10-24 15:40:54 +02:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain
// SPDX-FileCopyrightText: 2024 Antmicro
2024-10-24 15:40:54 +02:00
// SPDX-License-Identifier: CC0-1.0
class Foo;
2026-03-08 23:26:40 +01:00
int x = 1;
2024-10-24 15:40:54 +02:00
endclass
class Bar extends Foo;
2026-03-08 23:26:40 +01:00
function new;
x = 2;
endfunction
2024-10-24 15:40:54 +02:00
endclass
module t;
2026-03-08 23:26:40 +01:00
initial begin
automatic int sel_bit = 3;
automatic Bar bar = new;
automatic Foo foo = bar;
automatic Bar bars[] = new[4];
$cast(bars[0], foo);
if (bars[0].x != 2) $stop;
$cast(bars[sel_bit[0]], foo);
if (bars[1].x != 2) $stop;
$cast(bars[bars[0].x], foo);
if (bars[2].x != 2) $stop;
$cast(bars[sel_bit[1:0]], foo);
if (bars[3].x != 2) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
2024-10-24 15:40:54 +02:00
endmodule