@@ -6,9 +6,10 @@ Author: Daniel Kroening, kroening@kroening.com
6
6
7
7
\*******************************************************************/
8
8
9
- #include " verilog_typecheck.h "
9
+ #include < util/arith_tools.h >
10
10
11
11
#include " verilog_expr.h"
12
+ #include " verilog_typecheck.h"
12
13
13
14
/* ******************************************************************\
14
15
@@ -268,7 +269,34 @@ void verilog_typecheckt::elaborate_generate_for(
268
269
269
270
elaborate_generate_item (copy_of_body, dest);
270
271
271
- // Now increase the loop counter.
272
- elaborate_generate_assign (for_statement.increment (), dest);
272
+ // Now increase/decrease the loop counter.
273
+ {
274
+ auto statement = for_statement.iteration ().id ();
275
+ if (statement == ID_generate_assign)
276
+ {
277
+ elaborate_generate_assign (
278
+ to_verilog_generate_assign (for_statement.iteration ()), dest);
279
+ }
280
+ else if (statement == ID_preincrement || statement == ID_predecrement)
281
+ {
282
+ // turn ++x and x++ into x = x + 1
283
+ // turn --x and x-- into x = x - 1
284
+ // The expressions are parse trees, prior to typechecking
285
+ auto &op = to_unary_expr (for_statement.iteration ()).op ();
286
+ auto one = constant_exprt{ID_1, typet{}};
287
+ auto new_value = binary_exprt{
288
+ op, statement == ID_preincrement ? ID_plus : ID_minus, one, typet{}};
289
+ auto assignment = verilog_generate_assignt{op, new_value};
290
+
291
+ elaborate_generate_assign (assignment, dest);
292
+ }
293
+ else
294
+ {
295
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
296
+ false ,
297
+ " unexpected genvar_iteration item" ,
298
+ for_statement.iteration ().pretty ());
299
+ }
300
+ }
273
301
}
274
302
}
0 commit comments