10
10
11
11
#include < util/arith_tools.h>
12
12
#include < util/ebmc_util.h>
13
+ #include < util/std_expr.h>
13
14
14
15
#include < temporal-logic/temporal_logic.h>
15
16
#include < verilog/sva_expr.h>
18
19
#include " obligations.h"
19
20
#include " property.h"
20
21
22
+ exprt sequence_count_condition (
23
+ const sva_sequence_repetition_exprt &expr,
24
+ const exprt &counter)
25
+ {
26
+ if (expr.is_range ())
27
+ {
28
+ // number of repetitions inside a range
29
+ auto lower = numeric_cast_v<mp_integer>(
30
+ expr.lower ());
31
+
32
+ if (expr.is_unbounded ())
33
+ {
34
+ return binary_relation_exprt{counter, ID_ge, from_integer (lower, counter.type ())};
35
+ }
36
+ else
37
+ {
38
+ auto upper = numeric_cast_v<mp_integer>(
39
+ to_constant_expr (expr.upper ()));
40
+
41
+ return and_exprt{binary_relation_exprt{counter, ID_ge, from_integer (lower, counter.type ())},
42
+ binary_relation_exprt{counter, ID_le, from_integer (upper, counter.type ())}};
43
+ }
44
+ }
45
+ else
46
+ {
47
+ // fixed number of repetitions
48
+ auto repetitions_int = numeric_cast_v<mp_integer>(
49
+ expr.repetitions ());
50
+
51
+ return equal_exprt{counter, from_integer (repetitions_int, counter.type ())};
52
+ }
53
+ }
54
+
21
55
sequence_matchest instantiate_sequence (
22
56
exprt expr,
23
57
const mp_integer &t,
@@ -311,11 +345,8 @@ sequence_matchest instantiate_sequence(
311
345
}
312
346
else if (expr.id () == ID_sva_sequence_goto_repetition)
313
347
{
314
- // The 'op' is a Boolean condition, not a sequence.
315
- auto &op = to_sva_sequence_goto_repetition_expr (expr).op ();
316
- auto repetitions_int = numeric_cast_v<mp_integer>(
317
- to_sva_sequence_goto_repetition_expr (expr).repetitions ());
318
- PRECONDITION (repetitions_int >= 1 );
348
+ auto &repetition = to_sva_sequence_goto_repetition_expr (expr);
349
+ auto &condition = repetition.condition ();
319
350
320
351
sequence_matchest result;
321
352
@@ -324,32 +355,28 @@ sequence_matchest instantiate_sequence(
324
355
const auto bits = address_bits (no_timeframes);
325
356
const auto zero = from_integer (0 , unsignedbv_typet{bits});
326
357
const auto one = from_integer (1 , unsignedbv_typet{bits});
327
- const auto repetitions = from_integer (repetitions_int, zero.type ());
328
358
exprt matches = zero;
329
359
330
360
for (mp_integer u = t; u < no_timeframes; ++u)
331
361
{
332
362
// match of op in timeframe u?
333
- auto rec_op = instantiate (op , u, no_timeframes);
363
+ auto rec_op = instantiate (condition , u, no_timeframes);
334
364
335
365
// add up
336
366
matches = plus_exprt{matches, if_exprt{rec_op, one, zero}};
337
367
338
368
// We have a match for op[->n] if there is a match in timeframe
339
369
// u and matches is n.
340
370
result.emplace_back (
341
- u, and_exprt{rec_op, equal_exprt{ matches, repetitions}} );
371
+ u, sequence_count_condition (repetition, matches) );
342
372
}
343
373
344
374
return result;
345
375
}
346
376
else if (expr.id () == ID_sva_sequence_non_consecutive_repetition)
347
377
{
348
- // The 'op' is a Boolean condition, not a sequence.
349
- auto &op = to_sva_sequence_non_consecutive_repetition_expr (expr).op ();
350
- auto repetitions_int = numeric_cast_v<mp_integer>(
351
- to_sva_sequence_non_consecutive_repetition_expr (expr).repetitions ());
352
- PRECONDITION (repetitions_int >= 1 );
378
+ auto &repetition = to_sva_sequence_non_consecutive_repetition_expr (expr);
379
+ auto &condition = repetition.condition ();
353
380
354
381
sequence_matchest result;
355
382
@@ -358,19 +385,18 @@ sequence_matchest instantiate_sequence(
358
385
const auto bits = address_bits (no_timeframes);
359
386
const auto zero = from_integer (0 , unsignedbv_typet{bits});
360
387
const auto one = from_integer (1 , zero.type ());
361
- const auto repetitions = from_integer (repetitions_int, zero.type ());
362
388
exprt matches = zero;
363
389
364
390
for (mp_integer u = t; u < no_timeframes; ++u)
365
391
{
366
392
// match of op in timeframe u?
367
- auto rec_op = instantiate (op , u, no_timeframes);
393
+ auto rec_op = instantiate (condition , u, no_timeframes);
368
394
369
395
// add up
370
396
matches = plus_exprt{matches, if_exprt{rec_op, one, zero}};
371
397
372
398
// We have a match for op[=n] if matches is n.
373
- result.emplace_back (u, equal_exprt{matches, repetitions} );
399
+ result.emplace_back (u, sequence_count_condition (repetition, matches) );
374
400
}
375
401
376
402
return result;
0 commit comments