1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
// DESCRIPTION: Verilator: Verilog Test module
// 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
`define CONCAT(a,b) a``b
`define SHOW_LINED `CONCAT(show, `__LINE__)
bit fails;
module t (/*AUTOARG*/
// Inputs
clk, reset_l
);
input clk;
input reset_l;
generate
begin : direct_ignored
show #(`__LINE__) show1();
if (1) begin check #(`__LINE__, 1) show2(); end
end
begin : empty_DISAGREE
// DISAGREEMENT: if empty unnamed begin/end counts
begin end
if (1) begin check #(`__LINE__, 0) show2(); end
end
begin : empty_named_DISAGREE
// DISAGREEMENT: if empty named begin/end counts
begin : empty_inside_named end
if (1) begin check #(`__LINE__, 0) show2(); end
end
begin : unnamed_counts
// DISAGREEMENT: if unnamed begin/end counts
begin
show #(`__LINE__) show1();
end
if (1) begin check #(`__LINE__, 0) show2(); end
end
begin : named_counts
// DISAGREEMENT: if named begin/end counts
begin : named
show #(`__LINE__) show1();
end
if (1) begin check #(`__LINE__, 0) show2(); end
end
begin : if_direct_counts
if (0) ;
else if (0) ;
else if (1) show #(`__LINE__) show1();
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : if_begin_counts
if (0) begin end
else if (0) begin show #(`__LINE__) show1_NOT(); end
else if (1) begin show #(`__LINE__) show1(); end
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : if_named_counts
if (1) begin : named
show #(`__LINE__) show1();
if (1) begin : subnamed
show #(`__LINE__) show1s();
end
end
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : begin_if_counts
begin
if (0) begin end
else if (0) begin show #(`__LINE__) show1_NOT(); end
else if (1) begin show #(`__LINE__) show1(); end
end
// DISAGREEMENT: this could be genblk01
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : for_empty_counts
// DISAGREEMENT: if empty genfor counts
for (genvar g = 0; g < 1; ++g) ;
if (1) begin check #(`__LINE__, 0) show2(); end
end
begin : for_direct_counts
for (genvar g = 0; g < 1; ++g)
show #(`__LINE__) show1();
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : for_named_counts
for (genvar g = 0; g < 1; ++g) begin : fornamed
show #(`__LINE__) show1();
end
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : for_begin_counts
for (genvar g = 0; g < 1; ++g) begin
show #(`__LINE__) show1();
end
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : if_if
if (0) ;
else if (0) begin : namedb
end
else begin
if (0) begin end
else if (1) begin
show #(`__LINE__) show1();
end
end
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : case_direct
case (1)
0 : show #(`__LINE__) show1a_NOT();
1 : show #(`__LINE__) show1();
2 : show #(`__LINE__) show1c_NOT();
endcase
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : case_begin_counts
case (1)
0 : begin show #(`__LINE__) show1a_NOT(); end
1 : begin show #(`__LINE__) show1(); end
2 : begin show #(`__LINE__) show1c_NOT(); end
endcase
if (1) begin check #(`__LINE__, 2) show2(); end
end
begin : case_named_counts
case (1)
0 : begin : subnamed show #(`__LINE__) show1a_NOT(); end
1 : begin : subnamed show #(`__LINE__) show1(); end
2 : begin : subnamed show #(`__LINE__) show1c_NOT(); end
endcase
if (1) begin check #(`__LINE__, 2) show2(); end
end
endgenerate
int cyc;
always @ (posedge clk) begin
cyc <= cyc + 1;
if (cyc == 999) begin
if (fails) $stop;
else $write("*-* All Finished *-*\n");
$finish;
end
end
endmodule
module show #(parameter LINE=0) ();
// Each instance compares on unique cycle based on line number
// so we get deterministic ordering (versus using an initial)
always @ (posedge t.clk) begin
if (t.cyc == LINE) begin
$display("%03d: got=%m", LINE);
end
end
endmodule
module check #(parameter LINE=0, parameter EXP=0) ();
string mod;
int gennum;
int pos;
always @ (posedge t.clk) begin
if (t.cyc == LINE) begin
mod = $sformatf("%m");
gennum = 0;
for (int pos = 0; pos < mod.len(); ++pos) begin
if (mod.substr(pos, pos+5) == "genblk") begin
pos += 6;
// verilator lint_off WIDTH
gennum = mod[pos] - "0";
// verilator lint_on WIDTH
break;
end
end
$write("%03d: got=%s exp=%0d gennum=%0d ", LINE, mod, EXP, gennum);
if (EXP == 0) $display(" <ignored>");
else if (gennum != EXP) begin
$display (" %%Error");
fails = 1;
end
else $display;
$display;
end
end
endmodule
|