99#include " sequence.h"
1010
1111#include < util/arith_tools.h>
12- #include < util/ebmc_util.h>
1312
1413#include < temporal-logic/temporal_logic.h>
1514#include < verilog/sva_expr.h>
2019
2120sequence_matchest instantiate_sequence (
2221 exprt expr,
22+ sva_sequence_semanticst semantics,
2323 const mp_integer &t,
2424 const mp_integer &no_timeframes)
2525{
@@ -32,17 +32,21 @@ sequence_matchest instantiate_sequence(
3232 {
3333 const auto u = t + from;
3434
35- // Do we exceed the bound? Make it 'true'
35+ // Do we exceed the bound? Make it 'false'/'true', depending
36+ // on semantics.
3637 if (u >= no_timeframes)
3738 {
3839 DATA_INVARIANT (no_timeframes != 0 , " must have timeframe" );
39- return {{no_timeframes - 1 , true_exprt ()}};
40+ if (semantics == sva_sequence_semanticst::WEAK)
41+ return {{no_timeframes - 1 , true_exprt{}}};
42+ else // STRONG
43+ return {}; // no match
4044 }
4145 else
4246 return instantiate_sequence (
43- sva_cycle_delay_expr.op (), u, no_timeframes);
47+ sva_cycle_delay_expr.op (), semantics, u, no_timeframes);
4448 }
45- else
49+ else // ##[from:to] something
4650 {
4751 mp_integer to;
4852
@@ -51,25 +55,34 @@ sequence_matchest instantiate_sequence(
5155 DATA_INVARIANT (no_timeframes != 0 , " must have timeframe" );
5256 to = no_timeframes - 1 ;
5357 }
54- else if (to_integer_non_constant ( sva_cycle_delay_expr.to (), to ))
58+ else if (! sva_cycle_delay_expr.to (). is_constant ( ))
5559 throw " failed to convert sva_cycle_delay offsets" ;
60+ else
61+ to = numeric_cast_v<mp_integer>(
62+ to_constant_expr (sva_cycle_delay_expr.to ()));
5663
5764 auto lower = t + from;
5865 auto upper = t + to;
5966
60- // Do we exceed the bound? Make it 'true'
67+ // Do we exceed the bound? Make it 'true' if we are doing
68+ // weak semantics.
6169 if (upper >= no_timeframes)
6270 {
63- DATA_INVARIANT (no_timeframes != 0 , " must have timeframe" );
64- return {{no_timeframes - 1 , true_exprt ()}};
71+ if (semantics == sva_sequence_semanticst::WEAK)
72+ {
73+ DATA_INVARIANT (no_timeframes != 0 , " must have timeframe" );
74+ return {{no_timeframes - 1 , true_exprt ()}};
75+ }
76+ else
77+ upper = no_timeframes - 1 ;
6578 }
6679
6780 sequence_matchest matches;
6881
6982 for (mp_integer u = lower; u <= upper; ++u)
7083 {
71- auto sub_result =
72- instantiate_sequence ( sva_cycle_delay_expr.op (), u, no_timeframes);
84+ auto sub_result = instantiate_sequence (
85+ sva_cycle_delay_expr.op (), semantics , u, no_timeframes);
7386 for (auto &match : sub_result)
7487 matches.push_back (match);
7588 }
@@ -84,21 +97,25 @@ sequence_matchest instantiate_sequence(
8497
8598 // This is the product of the match points on the LHS and RHS
8699 const auto lhs_matches =
87- instantiate_sequence (implication.lhs (), t, no_timeframes);
100+ instantiate_sequence (implication.lhs (), semantics, t, no_timeframes);
88101
89102 for (auto &lhs_match : lhs_matches)
90103 {
91104 auto t_rhs = lhs_match.end_time ;
92105
93- // Do we exceed the bound? Make it 'true'
106+ // Do we exceed the bound? Make it 'false'/'true', depending
107+ // on semantics.
94108 if (t_rhs >= no_timeframes)
95109 {
96110 DATA_INVARIANT (no_timeframes != 0 , " must have timeframe" );
97- return {{no_timeframes - 1 , true_exprt ()}};
111+ if (semantics == sva_sequence_semanticst::WEAK)
112+ return {{no_timeframes - 1 , true_exprt{}}};
113+ else // STRONG
114+ return {}; // no match
98115 }
99116
100- const auto rhs_matches =
101- instantiate_sequence ( implication.rhs (), t_rhs, no_timeframes);
117+ const auto rhs_matches = instantiate_sequence (
118+ implication.rhs (), semantics , t_rhs, no_timeframes);
102119
103120 for (auto &rhs_match : rhs_matches)
104121 {
@@ -119,9 +136,9 @@ sequence_matchest instantiate_sequence(
119136 auto &intersect = to_sva_sequence_intersect_expr (expr);
120137
121138 const auto lhs_matches =
122- instantiate_sequence (intersect.lhs (), t, no_timeframes);
139+ instantiate_sequence (intersect.lhs (), semantics, t, no_timeframes);
123140 const auto rhs_matches =
124- instantiate_sequence (intersect.rhs (), t, no_timeframes);
141+ instantiate_sequence (intersect.rhs (), semantics, t, no_timeframes);
125142
126143 sequence_matchest result;
127144
@@ -146,7 +163,7 @@ sequence_matchest instantiate_sequence(
146163 auto &first_match = to_sva_sequence_first_match_expr (expr);
147164
148165 const auto lhs_matches =
149- instantiate_sequence (first_match.lhs (), t, no_timeframes);
166+ instantiate_sequence (first_match.lhs (), semantics, t, no_timeframes);
150167
151168 // the match of seq with the earliest ending clock tick is a
152169 // match of first_match (seq)
@@ -183,7 +200,7 @@ sequence_matchest instantiate_sequence(
183200 auto &throughout = to_sva_sequence_throughout_expr (expr);
184201
185202 const auto rhs_matches =
186- instantiate_sequence (throughout.rhs (), t, no_timeframes);
203+ instantiate_sequence (throughout.rhs (), semantics, t, no_timeframes);
187204
188205 sequence_matchest result;
189206
@@ -210,16 +227,16 @@ sequence_matchest instantiate_sequence(
210227
211228 auto &within_expr = to_sva_sequence_within_expr (expr);
212229 const auto matches_rhs =
213- instantiate_sequence (within_expr.rhs (), t, no_timeframes);
230+ instantiate_sequence (within_expr.rhs (), semantics, t, no_timeframes);
214231
215232 sequence_matchest result;
216233
217234 for (auto &match_rhs : matches_rhs)
218235 {
219236 for (auto start_lhs = t; start_lhs <= match_rhs.end_time ; ++start_lhs)
220237 {
221- auto matches_lhs =
222- instantiate_sequence ( within_expr.lhs (), start_lhs, no_timeframes);
238+ auto matches_lhs = instantiate_sequence (
239+ within_expr.lhs (), semantics , start_lhs, no_timeframes);
223240
224241 for (auto &match_lhs : matches_lhs)
225242 {
@@ -245,8 +262,10 @@ sequence_matchest instantiate_sequence(
245262 // 3. The end time of the composite sequence is
246263 // the end time of the operand sequence that completes last.
247264 auto &and_expr = to_sva_and_expr (expr);
248- auto matches_lhs = instantiate_sequence (and_expr.lhs (), t, no_timeframes);
249- auto matches_rhs = instantiate_sequence (and_expr.rhs (), t, no_timeframes);
265+ auto matches_lhs =
266+ instantiate_sequence (and_expr.lhs (), semantics, t, no_timeframes);
267+ auto matches_rhs =
268+ instantiate_sequence (and_expr.rhs (), semantics, t, no_timeframes);
250269
251270 sequence_matchest result;
252271
@@ -268,7 +287,7 @@ sequence_matchest instantiate_sequence(
268287 sequence_matchest result;
269288
270289 for (auto &op : expr.operands ())
271- for (auto &match : instantiate_sequence (op, t, no_timeframes))
290+ for (auto &match : instantiate_sequence (op, semantics, t, no_timeframes))
272291 result.push_back (match);
273292
274293 return result;
@@ -277,7 +296,8 @@ sequence_matchest instantiate_sequence(
277296 {
278297 // x[*n] is syntactic sugar for x ##1 ... ##1 x, with n repetitions
279298 auto &repetition = to_sva_sequence_consecutive_repetition_expr (expr);
280- return instantiate_sequence (repetition.lower (), t, no_timeframes);
299+ return instantiate_sequence (
300+ repetition.lower (), semantics, t, no_timeframes);
281301 }
282302 else if (
283303 expr.id () == ID_sva_sequence_repetition_plus ||
0 commit comments