1// DESCRIPTION: Verilator: Verilog Test module 2// 3// This file ONLY is placed under the Creative Commons Public Domain, for 4// any use, without warranty, 2021 by Noam Gallmann. 5// SPDX-License-Identifier: CC0-1.0 6 7`define stop $stop 8`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) 9 10module t(/*AUTOARG*/); 11 localparam int SIZES [3:0] = '{1,2,3,4}; 12 typedef int calc_sums_t [3:0]; 13 14 localparam int SUMS_ARRAY [3:0] = calc_sums_array(SIZES, 4); 15 function calc_sums_t calc_sums_array(int s[3:0], int n); 16 int sum = 0; 17 for (int ii = 0; ii < n; ++ii) begin 18 sum = sum + s[ii]; 19 calc_sums_array[ii] = sum; 20 end 21 endfunction 22 23`ifndef VERILATOR 24 localparam int SUMS_DYN [3:0] = calc_sums_dyn(SIZES, 4); 25`endif 26 function calc_sums_t calc_sums_dyn(int s[], int n); 27 int sum = 0; 28 for (int ii = 0; ii < n; ++ii) begin 29 sum = sum + s[ii]; 30 calc_sums_dyn[ii] = sum; 31 end 32 endfunction 33 34 initial begin 35 `checkh(SIZES[0], 4); 36 `checkh(SIZES[1], 3); 37 `checkh(SIZES[2], 2); 38 `checkh(SIZES[3], 1); 39 40 `checkh(SUMS_ARRAY[0], 4); 41 `checkh(SUMS_ARRAY[1], 7); 42 `checkh(SUMS_ARRAY[2], 9); 43 `checkh(SUMS_ARRAY[3], 10); 44 45`ifndef VERILATOR 46 `checkh(SUMS_DYN[0], 1); 47 `checkh(SUMS_DYN[1], 3); 48 `checkh(SUMS_DYN[2], 6); 49 `checkh(SUMS_DYN[3], 10); 50`endif 51 $write("*-* All Finished *-*\n"); 52 $finish; 53 end 54endmodule 55