verilator/test_regress/t/t_castdyn_enum.v

71 lines
1.4 KiB
Systemverilog
Raw Normal View History

2020-11-29 22:58:34 +01:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2020 Wilson Snyder
2020-11-29 22:58:34 +01:00
// SPDX-License-Identifier: CC0-1.0
2026-03-03 13:21:24 +01:00
typedef enum {
TEN = 10,
ELEVEN = 11,
SIXTEEN = 16
} enum_t;
2020-11-29 22:58:34 +01:00
2026-03-03 13:21:24 +01:00
module t ( /*AUTOARG*/
// Inputs
clk
);
input clk;
2020-11-29 22:58:34 +01:00
2026-03-03 13:21:24 +01:00
int i;
int i_const;
int cyc;
enum_t en;
2020-11-29 22:58:34 +01:00
2026-03-03 13:21:24 +01:00
// Constant propagation tests
initial begin
en = SIXTEEN;
i_const = $cast(en, 1);
if (i_const != 0) $stop;
if (en != SIXTEEN) $stop;
2026-03-03 13:21:24 +01:00
en = SIXTEEN;
i_const = $cast(en, 10);
if (i_const != 1) $stop;
if (en != TEN) $stop;
end
2026-03-03 13:21:24 +01:00
// Test loop
always @(posedge clk) begin
i = $cast(en, cyc);
2020-11-29 22:58:34 +01:00
`ifdef TEST_VERBOSE
2026-03-03 13:21:24 +01:00
$write("[%0t] cyc==%0d i=%0d en=%0d\n", $time, cyc, i, en);
2020-11-29 22:58:34 +01:00
`endif
2026-03-03 13:21:24 +01:00
cyc <= cyc + 1;
if (cyc == 10) begin
if (i != 1) $stop;
if (en != TEN) $stop;
end
else if (cyc == 11) begin
if (i != 1) $stop;
if (en != ELEVEN) $stop;
end
else if (cyc == 12) begin
if (i != 0) $stop;
if (en != ELEVEN) $stop;
end
else if (cyc == 16) begin
if (i != 1) $stop;
if (en != SIXTEEN) $stop;
end
else if (cyc == 17) begin
if (i != 0) $stop;
if (en != SIXTEEN) $stop;
end
else if (cyc == 99) begin
$write("*-* All Finished *-*\n");
$finish;
end
end
2020-11-29 22:58:34 +01:00
endmodule