verilator/test_regress/t/t_array_query.v

63 lines
1.2 KiB
Systemverilog
Raw Normal View History

// DESCRIPTION: Verilator: System Verilog test of array querying functions.
//
// This code instantiates a module that calls the various array querying
// functions.
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2012 Jeremy Bennett, Embecosm
// SPDX-License-Identifier: CC0-1.0
2026-03-03 13:21:24 +01:00
module t (
input clk
);
2026-03-03 13:21:24 +01:00
wire a = clk;
wire b = 1'b0;
reg c;
2017-09-12 01:18:58 +02:00
2026-03-03 13:21:24 +01:00
array_test array_test_i ( /*AUTOINST*/
// Inputs
.clk(clk)
);
endmodule
// Check the array sizing functions work correctly.
2026-03-03 13:21:24 +01:00
module array_test #(
parameter LEFT = 5,
RIGHT = 55
) ( /*AUTOARG*/
// Inputs
clk
);
2026-03-03 13:21:24 +01:00
input clk;
2026-03-03 13:21:24 +01:00
// verilator lint_off ASCRANGE
reg [7:0] a[LEFT:RIGHT];
// verilator lint_on ASCRANGE
2026-03-03 13:21:24 +01:00
typedef reg [7:0] r_t;
2026-03-03 13:21:24 +01:00
integer l;
integer r;
integer s;
2026-03-03 13:21:24 +01:00
always @(posedge clk) begin
l = $left(a);
r = $right(a);
s = $size(a);
2017-09-12 01:18:58 +02:00
`ifdef TEST_VERBOSE
2026-03-03 13:21:24 +01:00
$write("$left (a) = %d, $right (a) = %d, $size (a) = %d\n", l, r, s);
`endif
2026-03-03 13:21:24 +01:00
if ((l != LEFT) || (r != RIGHT) || (s != (RIGHT - LEFT + 1))) $stop;
if ($left(r_t) != 7 || $right(r_t) != 0 || $size(r_t) != 8 || $bits(r_t) != 8) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
endmodule