@@ -29,9 +29,9 @@ Function: timeframe_identifier
29
29
\*******************************************************************/
30
30
31
31
std::string
32
- timeframe_identifier (std:: size_t timeframe, const irep_idt &identifier)
32
+ timeframe_identifier (const mp_integer & timeframe, const irep_idt &identifier)
33
33
{
34
- return id2string (identifier)+ " @" + std::to_string (timeframe);
34
+ return id2string (identifier) + " @" + integer2string (timeframe);
35
35
}
36
36
37
37
/* ******************************************************************\
@@ -46,7 +46,7 @@ Function: timeframe_symbol
46
46
47
47
\*******************************************************************/
48
48
49
- symbol_exprt timeframe_symbol (std:: size_t timeframe, symbol_exprt src)
49
+ symbol_exprt timeframe_symbol (const mp_integer & timeframe, symbol_exprt src)
50
50
{
51
51
auto result = std::move (src);
52
52
result.set_identifier (
@@ -69,40 +69,23 @@ symbol_exprt timeframe_symbol(std::size_t timeframe, symbol_exprt src)
69
69
class wl_instantiatet
70
70
{
71
71
public:
72
- wl_instantiatet (
73
- std::size_t _current,
74
- std::size_t _no_timeframes,
75
- const namespacet &_ns)
76
- : current(_current), no_timeframes(_no_timeframes), ns(_ns)
72
+ wl_instantiatet (const mp_integer &_no_timeframes, const namespacet &_ns)
73
+ : no_timeframes(_no_timeframes), ns(_ns)
77
74
{
78
75
}
79
76
80
- [[nodiscard]] exprt operator ()(exprt expr)
77
+ // / Instantiate the given expression for timeframe t
78
+ [[nodiscard]] exprt operator ()(exprt expr, const mp_integer &t) const
81
79
{
82
- return instantiate_rec (std::move (expr));
80
+ return instantiate_rec (std::move (expr), t );
83
81
}
84
82
85
83
protected:
86
- std:: size_t current, no_timeframes;
84
+ const mp_integer & no_timeframes;
87
85
const namespacet &ns;
88
86
89
- [[nodiscard]] exprt instantiate_rec (exprt);
90
- [[nodiscard]] typet instantiate_rec (typet);
91
-
92
- class save_currentt
93
- {
94
- public:
95
- inline explicit save_currentt (std::size_t &_c) : c(_c), saved(c)
96
- {
97
- }
98
-
99
- inline ~save_currentt ()
100
- {
101
- c=saved; // restore
102
- }
103
-
104
- std::size_t &c, saved;
105
- };
87
+ [[nodiscard]] exprt instantiate_rec (exprt, const mp_integer &t) const ;
88
+ [[nodiscard]] typet instantiate_rec (typet, const mp_integer &t) const ;
106
89
};
107
90
108
91
/* ******************************************************************\
@@ -117,26 +100,26 @@ Function: wl_instantiatet::instantiate_rec
117
100
118
101
\*******************************************************************/
119
102
120
- exprt wl_instantiatet::instantiate_rec (exprt expr)
103
+ exprt wl_instantiatet::instantiate_rec (exprt expr, const mp_integer &t) const
121
104
{
122
- expr.type () = instantiate_rec (expr.type ());
105
+ expr.type () = instantiate_rec (expr.type (), t );
123
106
124
107
if (expr.id () == ID_next_symbol)
125
108
{
126
109
expr.id (ID_symbol);
127
- return timeframe_symbol (current + 1 , to_symbol_expr (std::move (expr)));
110
+ return timeframe_symbol (t + 1 , to_symbol_expr (std::move (expr)));
128
111
}
129
112
else if (expr.id () == ID_symbol)
130
113
{
131
- return timeframe_symbol (current , to_symbol_expr (std::move (expr)));
114
+ return timeframe_symbol (t , to_symbol_expr (std::move (expr)));
132
115
}
133
116
else if (expr.id ()==ID_sva_overlapped_implication)
134
117
{
135
118
// same as regular implication
136
119
expr.id (ID_implies);
137
120
138
121
for (auto &op : expr.operands ())
139
- op = instantiate_rec (op);
122
+ op = instantiate_rec (op, t );
140
123
141
124
return expr;
142
125
}
@@ -147,18 +130,16 @@ exprt wl_instantiatet::instantiate_rec(exprt expr)
147
130
{
148
131
expr.id (ID_implies);
149
132
auto &implies_expr = to_implies_expr (expr);
150
- implies_expr.op0 () = instantiate_rec (implies_expr.op0 ());
133
+ implies_expr.op0 () = instantiate_rec (implies_expr.op0 (), t);
134
+
135
+ const auto next = t + 1 ;
151
136
152
- save_currentt save_current (current);
153
-
154
- current++;
155
-
156
137
// Do we exceed the bound? Make it 'true',
157
138
// works on NNF only
158
- if (current>= no_timeframes)
139
+ if (next >= no_timeframes)
159
140
implies_expr.op1 () = true_exprt ();
160
141
else
161
- implies_expr.op1 () = instantiate_rec (implies_expr.op1 ());
142
+ implies_expr.op1 () = instantiate_rec (implies_expr.op1 (), next );
162
143
163
144
return std::move (implies_expr);
164
145
}
@@ -171,22 +152,19 @@ exprt wl_instantiatet::instantiate_rec(exprt expr)
171
152
{
172
153
auto &ternary_expr = to_ternary_expr (expr);
173
154
174
- // save the current time frame, we'll change it
175
- save_currentt save_current (current);
176
-
177
155
if (ternary_expr.op1 ().is_nil ())
178
156
{
179
157
mp_integer offset;
180
158
if (to_integer_non_constant (ternary_expr.op0 (), offset))
181
159
throw " failed to convert sva_cycle_delay offset" ;
182
160
183
- current = save_current. saved + offset. to_ulong () ;
161
+ const auto u = t + offset;
184
162
185
163
// Do we exceed the bound? Make it 'true'
186
- if (current>= no_timeframes)
164
+ if (u >= no_timeframes)
187
165
return true_exprt ();
188
166
else
189
- return instantiate_rec (ternary_expr.op2 ());
167
+ return instantiate_rec (ternary_expr.op2 (), u );
190
168
}
191
169
else
192
170
{
@@ -208,14 +186,14 @@ exprt wl_instantiatet::instantiate_rec(exprt expr)
208
186
209
187
for (mp_integer offset=from; offset<to; ++offset)
210
188
{
211
- current = save_current. saved + offset. to_ulong () ;
189
+ auto u = t + offset;
212
190
213
- if (current>= no_timeframes)
191
+ if (u >= no_timeframes)
214
192
{
215
193
}
216
194
else
217
195
{
218
- disjuncts.push_back (instantiate_rec (ternary_expr.op2 ()));
196
+ disjuncts.push_back (instantiate_rec (ternary_expr.op2 (), u ));
219
197
}
220
198
}
221
199
@@ -231,22 +209,19 @@ exprt wl_instantiatet::instantiate_rec(exprt expr)
231
209
expr.id (ID_and);
232
210
233
211
for (auto &op : expr.operands ())
234
- op = instantiate_rec (op);
212
+ op = instantiate_rec (op, t );
235
213
236
214
return expr;
237
215
}
238
216
else if (expr.id ()==ID_sva_always)
239
217
{
240
218
auto &op = to_sva_always_expr (expr).op ();
241
219
242
- // save the current time frame, we'll change it
243
- save_currentt save_current (current);
244
-
245
220
exprt::operandst conjuncts;
246
221
247
- for (; current< no_timeframes; current++ )
222
+ for (auto u = t; u < no_timeframes; ++u )
248
223
{
249
- conjuncts.push_back (instantiate_rec (op));
224
+ conjuncts.push_back (instantiate_rec (op, u ));
250
225
}
251
226
252
227
return conjunction (conjuncts);
@@ -255,15 +230,12 @@ exprt wl_instantiatet::instantiate_rec(exprt expr)
255
230
expr.id ()==ID_sva_s_nexttime)
256
231
{
257
232
assert (expr.operands ().size ()==1 );
258
-
259
- // save the current time frame, we'll change it
260
- save_currentt save_current (current);
261
-
262
- current++;
263
-
264
- if (current<no_timeframes)
233
+
234
+ const auto next = t + 1 ;
235
+
236
+ if (next < no_timeframes)
265
237
{
266
- return instantiate_rec (to_unary_expr (expr).op ());
238
+ return instantiate_rec (to_unary_expr (expr).op (), next );
267
239
}
268
240
else
269
241
return true_exprt (); // works on NNF only
@@ -280,25 +252,22 @@ exprt wl_instantiatet::instantiate_rec(exprt expr)
280
252
// some earlier state k < i.
281
253
// (1) No state j with k<=k<=i on the lasso satisfies 'p'.
282
254
//
283
- // We look backwards instead of forwards so that 'current '
255
+ // We look backwards instead of forwards so that 't '
284
256
// is the last state of the counterexample trace.
285
257
//
286
- // Note that this is trivially true when current is zero,
258
+ // Note that this is trivially true when t is zero,
287
259
// as a single state cannot demonstrate the loop.
288
260
289
261
exprt::operandst conjuncts = {};
290
- const std:: size_t i = current ;
262
+ const auto i = t ;
291
263
292
- for (std:: size_t k = 0 ; k < i; k++ )
264
+ for (mp_integer k = 0 ; k < i; ++k )
293
265
{
294
266
exprt::operandst disjuncts = {not_exprt (lasso_symbol (k, i))};
295
267
296
- for (std:: size_t j = k; j <= i; j++ )
268
+ for (mp_integer j = k; j <= i; ++j )
297
269
{
298
- // save the current time frame, we'll change it
299
- save_currentt save_current (current);
300
- current = j;
301
- disjuncts.push_back (instantiate_rec (p));
270
+ disjuncts.push_back (instantiate_rec (p, j));
302
271
}
303
272
304
273
conjuncts.push_back (disjunction (disjuncts));
@@ -314,22 +283,19 @@ exprt wl_instantiatet::instantiate_rec(exprt expr)
314
283
assert (expr.operands ().size ()==2 );
315
284
316
285
// we need a lasso to refute these
317
-
318
- // save the current time frame, we'll change it
319
- save_currentt save_current (current);
320
-
286
+
321
287
// we expand: p U q <=> q || (p && X(p U q))
322
288
exprt tmp_q = to_binary_expr (expr).op1 ();
323
- tmp_q = instantiate_rec (tmp_q);
289
+ tmp_q = instantiate_rec (tmp_q, t );
324
290
325
291
exprt expansion = to_binary_expr (expr).op0 ();
326
- expansion = instantiate_rec (expansion);
292
+ expansion = instantiate_rec (expansion, t );
327
293
328
- current++ ;
329
-
330
- if (current< no_timeframes)
294
+ const auto next = t + 1 ;
295
+
296
+ if (next < no_timeframes)
331
297
{
332
- expansion = and_exprt (expansion, instantiate_rec (expr));
298
+ expansion = and_exprt (expansion, instantiate_rec (expr, next ));
333
299
}
334
300
335
301
return or_exprt (tmp_q, expansion);
@@ -350,12 +316,12 @@ exprt wl_instantiatet::instantiate_rec(exprt expr)
350
316
351
317
tmp.op1 () = sva_nexttime_exprt (tmp.op1 ());
352
318
353
- return instantiate_rec (tmp);
319
+ return instantiate_rec (tmp, t );
354
320
}
355
321
else
356
322
{
357
323
for (auto &op : expr.operands ())
358
- op = instantiate_rec (op);
324
+ op = instantiate_rec (op, t );
359
325
return expr;
360
326
}
361
327
}
@@ -372,7 +338,7 @@ Function: wl_instantiatet::instantiate_rec
372
338
373
339
\*******************************************************************/
374
340
375
- typet wl_instantiatet::instantiate_rec (typet type)
341
+ typet wl_instantiatet::instantiate_rec (typet type, const mp_integer &) const
376
342
{
377
343
return type;
378
344
}
@@ -391,10 +357,10 @@ Function: instantiate
391
357
392
358
exprt instantiate (
393
359
const exprt &expr,
394
- std:: size_t current ,
395
- std:: size_t no_timeframes,
360
+ const mp_integer &t ,
361
+ const mp_integer & no_timeframes,
396
362
const namespacet &ns)
397
363
{
398
- wl_instantiatet wl_instantiate (current, no_timeframes, ns);
399
- return wl_instantiate (expr);
364
+ wl_instantiatet wl_instantiate (no_timeframes, ns);
365
+ return wl_instantiate (expr, t );
400
366
}
0 commit comments