1
1
#include <stdint.h>
2
- #include <cassert >
2
+ #include <assert.h >
3
3
4
4
//Some helper functions.
5
5
6
- //nondet_bool, nondet_int, nondet_sizet are available in CBMC.
6
+ //nndt_bool, nndt_int, nndt_sizet are available in CBMC.
7
7
8
- int nondet_int (){
8
+ int nndt_int (){
9
9
int i ;
10
10
return (i );
11
11
}
12
12
13
- int nondet_bool (){
14
- bool b ;
15
- return (b );
13
+ int nndt_bool (){
14
+ int i ;
15
+ return (i % 2 );
16
16
}
17
17
18
- int nondet_under (int bound ){
18
+
19
+ int nndt_under (int bound ){
19
20
int nd ;
20
21
// Mod is an expensive operation. We need to get rid of this.
21
22
//return(nd%bound);
22
- __CPROVER_ASSUME (nd < bound );
23
+ __CPROVER_assume (nd < bound );
23
24
return (nd );
24
25
}
25
26
26
- int nondet_between (int l , int u ){
27
+ int nndt_between (int l , int u ){
27
28
int diff = u - l ;
28
- int nd = nondet_under (diff );
29
+ int nd = nndt_under (diff );
29
30
if (nd == 0 ) return (l + 1 );
30
31
else return (nd + l );
31
32
}
32
33
33
- int nondet_above (int bound ){
34
- int nd = nondet_int ();
34
+ int nndt_above (int bound ){
35
+ int nd = nndt_int ();
35
36
if (nd > bound ) return (nd );
36
37
else return (bound + 1 + nd );
37
38
}
@@ -59,20 +60,20 @@ int concretize_1(int abs_ind, int a1){
59
60
if (abs_ind < 1 ) {
60
61
if (a1 == 0 )
61
62
{
62
- assert (false );
63
+ assert (0 != 0 );
63
64
return (-1 );
64
65
}
65
- else return (nondet_under (a1 ));
66
+ else return (nndt_under (a1 ));
66
67
}
67
68
else if (abs_ind == 1 ) return (a1 );
68
- else return (nondet_above (a1 ));
69
+ else return (nndt_above (a1 ));
69
70
}
70
71
71
72
// Add a number to an abs_ind
72
73
int add_abs_to_conc_1 (int abs_ind , int num , int a1 ){
73
74
if (num == 1 ){
74
75
if (abs_ind == 0 ) {
75
- if (nondet_bool () ) return (abs_ind );
76
+ if (nndt_bool () > 0 ) return (abs_ind );
76
77
else return (abs_ind + 1 );
77
78
}
78
79
//abs_ind = 1 or 2
@@ -91,7 +92,7 @@ int add_abs_to_conc_1(int abs_ind, int num, int a1){
91
92
int sub_conc_from_abs_1 (int abs_ind , int num , int a1 , int a2 ){
92
93
if (num == 1 ){
93
94
if (abs_ind == 2 ) {
94
- if (nondet_bool () ) return (abs_ind );
95
+ if (nndt_bool () > 0 ) return (abs_ind );
95
96
else return (abs_ind - 1 );
96
97
}
97
98
//abs_ind = 1 0r 0
@@ -133,37 +134,39 @@ int concretize_2(int abs_ind, int a1, int a2) {
133
134
if (a1 == 0 )
134
135
{
135
136
//throw an exception here?
136
- assert (false );
137
+ assert (0 != 0 );
137
138
return (-1 );
138
139
}
139
- else return (nondet_under (a1 ));
140
+ else return (nndt_under (a1 ));
140
141
}
141
142
else if (abs_ind == 1 ) return (a1 );
142
143
else if (abs_ind == 2 ){
143
144
if (a1 + 1 == a2 ) {
144
145
//throw an exception here?
145
- assert (false );
146
+ assert (0 != 0 );
146
147
return (-1 );
147
148
}
148
- else return (nondet_between (a1 , a2 ));
149
+ else return (nndt_between (a1 , a2 ));
149
150
}
150
151
else if (abs_ind == 3 ) return (a2 );
151
- else return (nondet_above (a2 ));
152
+ else return (nndt_above (a2 ));
152
153
}
153
154
154
- bool is_precise_2 (int abs_ind ){
155
- return (abs_ind == 1 || abs_ind == 3 );
155
+ int is_precise_2 (int abs_ind ){
156
+ if (abs_ind == 1 || abs_ind == 3 ) return (1 );
157
+ else return (0 );
156
158
}
157
159
158
- bool is_abstract_2 (int abs_ind ){
159
- return (!is_precise_2 (abs_ind ));
160
+ int is_abstract_2 (int abs_ind ){
161
+ int pre = is_precise_2 (abs_ind );
162
+ return (1 - pre );
160
163
}
161
164
162
165
// Add a number to an abs_ind
163
166
int add_abs_to_conc_2 (int abs_ind , int num , int a1 , int a2 ){
164
167
if (num == 1 ){
165
168
if (abs_ind == 0 || abs_ind == 2 ) {
166
- if (nondet_bool () ) return (abs_ind );
169
+ if (nndt_bool () > 0 ) return (abs_ind );
167
170
else return (abs_ind + 1 );
168
171
}
169
172
else if (abs_ind == 1 ) {
@@ -187,7 +190,7 @@ int add_abs_to_conc_2(int abs_ind, int num, int a1, int a2){
187
190
int sub_conc_from_abs_2 (int abs_ind , int num , int a1 , int a2 ){
188
191
if (num == 1 ){
189
192
if (abs_ind == 4 || abs_ind == 2 ) {
190
- if (nondet_bool () ) return (abs_ind );
193
+ if (nndt_bool () > 0 ) return (abs_ind );
191
194
else return (abs_ind - 1 );
192
195
}
193
196
else if (abs_ind == 3 ) {
@@ -248,39 +251,41 @@ int concretize_4(int abs_ind, int a1, int a2, int a3, int a4) {
248
251
if (a1 == 0 )
249
252
{
250
253
//throw an exception here?
251
- assert (false );
254
+ assert (0 != 0 );
252
255
return (-1 );
253
256
}
254
- else return (nondet_under (a1 ));
257
+ else return (nndt_under (a1 ));
255
258
}
256
259
else if (abs_ind == 1 ) return (a1 );
257
260
else if (abs_ind == 2 ) return (a2 );
258
261
else if (abs_ind == 3 ){
259
262
if (a2 + 1 == a3 ) {
260
263
//throw an exception here?
261
- assert (false );
264
+ assert (0 != 0 );
262
265
return (-1 );
263
266
}
264
- else return (nondet_between (a2 , a3 ));
267
+ else return (nndt_between (a2 , a3 ));
265
268
}
266
269
else if (abs_ind == 4 ) return (a3 );
267
270
else if (abs_ind == 5 ) return (a4 );
268
- else return (nondet_above (a4 ));
271
+ else return (nndt_above (a4 ));
269
272
}
270
273
271
- bool is_precise_4 (int abs_ind ){
272
- return (abs_ind == 1 || abs_ind == 2 || abs_ind == 4 || abs_ind == 5 );
274
+ int is_precise_4 (int abs_ind ){
275
+ if (abs_ind == 1 || abs_ind == 2 || abs_ind == 4 || abs_ind == 5 ) return (1 );
276
+ else return (0 );
273
277
}
274
278
275
- bool is_abstract_4 (int abs_ind ){
276
- return (!is_precise_4 (abs_ind ));
279
+ int is_abstract_4 (int abs_ind ){
280
+ if (!is_precise_4 (abs_ind )) return (1 );
281
+ else return (0 );
277
282
}
278
283
279
284
// Add a number to an abs_ind
280
285
int add_abs_to_conc_4 (int abs_ind , int num , int a1 , int a2 , int a3 , int a4 ){
281
286
if (num == 1 ){
282
287
if (abs_ind == 0 || abs_ind == 3 ) {
283
- if (nondet_bool () ) return (abs_ind );
288
+ if (nndt_bool () > 0 ) return (abs_ind );
284
289
else return (abs_ind + 1 );
285
290
}
286
291
else if (abs_ind == 1 ) return (2 );
@@ -306,7 +311,7 @@ int add_abs_to_conc_4(int abs_ind, int num, int a1, int a2, int a3, int a4){
306
311
int sub_conc_from_abs_4 (int abs_ind , int num , int a1 , int a2 , int a3 , int a4 ){
307
312
if (num == 1 ){
308
313
if (abs_ind == 6 || abs_ind == 3 ) {
309
- if (nondet_bool () ) return (abs_ind );
314
+ if (nndt_bool () > 0 ) return (abs_ind );
310
315
else return (abs_ind - 1 );
311
316
}
312
317
else if (abs_ind == 5 || abs_ind == 2 || abs_ind == 1 ) return (abs_ind - 1 );
0 commit comments