9
9
#include " sequence.h"
10
10
11
11
#include < util/arith_tools.h>
12
+ // #include <util/ebmc_util.h>
13
+ // #include <util/std_expr.h>
12
14
13
15
#include < ebmc/ebmc_error.h>
14
16
#include < temporal-logic/temporal_logic.h>
18
20
#include " obligations.h"
19
21
#include " property.h"
20
22
23
+ exprt sequence_count_condition (
24
+ const sva_sequence_repetition_exprt &expr,
25
+ const exprt &counter)
26
+ {
27
+ if (expr.is_range ())
28
+ {
29
+ // number of repetitions inside a range
30
+ auto from = numeric_cast_v<mp_integer>(expr.from ());
31
+
32
+ if (expr.is_unbounded ())
33
+ {
34
+ return binary_relation_exprt{
35
+ counter, ID_ge, from_integer (from, counter.type ())};
36
+ }
37
+ else
38
+ {
39
+ auto to = numeric_cast_v<mp_integer>(expr.to ());
40
+
41
+ return and_exprt{
42
+ binary_relation_exprt{
43
+ counter, ID_ge, from_integer (from, counter.type ())},
44
+ binary_relation_exprt{
45
+ counter, ID_le, from_integer (to, counter.type ())}};
46
+ }
47
+ }
48
+ else
49
+ {
50
+ // fixed number of repetitions
51
+ auto repetitions_int = numeric_cast_v<mp_integer>(expr.repetitions ());
52
+
53
+ return equal_exprt{counter, from_integer (repetitions_int, counter.type ())};
54
+ }
55
+ }
56
+
21
57
sequence_matchest instantiate_sequence (
22
58
exprt expr,
23
59
sva_sequence_semanticst semantics,
@@ -346,11 +382,8 @@ sequence_matchest instantiate_sequence(
346
382
}
347
383
else if (expr.id () == ID_sva_sequence_goto_repetition)
348
384
{
349
- // The 'op' is a Boolean condition, not a sequence.
350
- auto &op = to_sva_sequence_goto_repetition_expr (expr).op ();
351
- auto repetitions_int = numeric_cast_v<mp_integer>(
352
- to_sva_sequence_goto_repetition_expr (expr).repetitions ());
353
- PRECONDITION (repetitions_int >= 1 );
385
+ auto &repetition = to_sva_sequence_goto_repetition_expr (expr);
386
+ auto &condition = repetition.op ();
354
387
355
388
sequence_matchest result;
356
389
@@ -359,54 +392,47 @@ sequence_matchest instantiate_sequence(
359
392
const auto bits = address_bits (no_timeframes);
360
393
const auto zero = from_integer (0 , unsignedbv_typet{bits});
361
394
const auto one = from_integer (1 , unsignedbv_typet{bits});
362
- const auto repetitions = from_integer (repetitions_int, zero.type ());
363
395
exprt matches = zero;
364
396
365
397
for (mp_integer u = t; u < no_timeframes; ++u)
366
398
{
367
399
// match of op in timeframe u?
368
- auto rec_op = instantiate (op , u, no_timeframes);
400
+ auto rec_op = instantiate (condition , u, no_timeframes);
369
401
370
402
// add up
371
403
matches = plus_exprt{matches, if_exprt{rec_op, one, zero}};
372
404
373
405
// We have a match for op[->n] if there is a match in timeframe
374
406
// u and matches is n.
375
- result.emplace_back (
376
- u, and_exprt{rec_op, equal_exprt{matches, repetitions}});
407
+ result.emplace_back (u, sequence_count_condition (repetition, matches));
377
408
}
378
409
379
410
return result;
380
411
}
381
412
else if (expr.id () == ID_sva_sequence_non_consecutive_repetition)
382
413
{
383
- // The 'op' is a Boolean condition, not a sequence.
384
- auto &op = to_sva_sequence_non_consecutive_repetition_expr (expr).op ();
385
- auto repetitions_int = numeric_cast_v<mp_integer>(
386
- to_sva_sequence_non_consecutive_repetition_expr (expr).repetitions ());
387
- PRECONDITION (repetitions_int >= 1 );
414
+ auto &repetition = to_sva_sequence_non_consecutive_repetition_expr (expr);
415
+ auto &condition = repetition.op ();
388
416
389
417
sequence_matchest result;
390
418
391
419
// We add up the number of matches of 'op' starting from
392
420
// timeframe u, until the end of our unwinding.
393
- const auto bits =
394
- address_bits (std::max (no_timeframes, repetitions_int + 1 ));
421
+ const auto bits = address_bits (no_timeframes);
395
422
const auto zero = from_integer (0 , unsignedbv_typet{bits});
396
423
const auto one = from_integer (1 , zero.type ());
397
- const auto repetitions = from_integer (repetitions_int, zero.type ());
398
424
exprt matches = zero;
399
425
400
426
for (mp_integer u = t; u < no_timeframes; ++u)
401
427
{
402
428
// match of op in timeframe u?
403
- auto rec_op = instantiate (op , u, no_timeframes);
429
+ auto rec_op = instantiate (condition , u, no_timeframes);
404
430
405
431
// add up
406
432
matches = plus_exprt{matches, if_exprt{rec_op, one, zero}};
407
433
408
434
// We have a match for op[=n] if matches is n.
409
- result.emplace_back (u, equal_exprt{matches, repetitions} );
435
+ result.emplace_back (u, sequence_count_condition (repetition, matches) );
410
436
}
411
437
412
438
return result;
0 commit comments