4
4
#include <stdlib.h>
5
5
6
6
C3BitBlast * bb ;
7
+
7
8
C3BitBlast * c3_bitblast_new () {
8
9
C3BitBlast * bitblast ;
9
10
bitblast = (C3BitBlast * ) malloc (sizeof (C3BitBlast ));
@@ -52,8 +53,10 @@ ASTVec c3_bitblast_neg(ASTVec vec) {
52
53
return result ;
53
54
}
54
55
55
- static ASTNode * c3_bitblast_cmp_internal (ASTVec left , ASTVec right , bool sign , bool bvlt ) {
56
- /* TODO: */
56
+ static ASTNode * c3_bitblast_bvle (ASTVec left , ASTVec right , bool sign , bool bvlt ) {
57
+ C3ListIter * lit , * rit ;
58
+ lit = left -> tail ;
59
+ rit = right -> tail ;
57
60
return NULL ;
58
61
}
59
62
@@ -66,40 +69,42 @@ ASTNode *c3_bitblast_cmp(ASTNode *form) {
66
69
switch (k ) {
67
70
case BVLE :
68
71
{
69
- result = c3_bitblast_cmp_internal (left , right , false, false);
72
+ result = c3_bitblast_bvle (left , right , false, false);
70
73
break ;
71
74
}
72
75
case BVGE :
73
76
{
74
- result = c3_bitblast_cmp_internal ( left , right , false, false);
77
+ result = c3_bitblast_bvle ( right , left , false, false);
75
78
break ;
76
79
}
77
80
case BVGT :
78
81
{
79
- result = c3_bitblast_cmp_internal (right , left , false, true);
82
+ result = c3_bitblast_bvle (right , left , false, true);
80
83
break ;
81
84
}
82
85
case BVLT :
83
86
{
84
- result = c3_bitblast_cmp_internal (left , right , true , true);
87
+ result = c3_bitblast_bvle (left , right , false , true);
85
88
break ;
86
89
}
87
90
case BVSLE :
88
91
{
89
- result = c3_bitblast_cmp_internal ( right , left , true, true );
92
+ result = c3_bitblast_bvle ( left , right , true, false );
90
93
break ;
91
94
}
92
95
case BVSGE :
93
96
{
94
- result = c3_bitblast_cmp_internal ( left , right , false , false);
97
+ result = c3_bitblast_bvle ( right , left , true , false);
95
98
break ;
96
99
}
97
100
case BVSGT :
98
101
{
102
+ //result = c3_bitblast_bvle (right, left, true, true);
99
103
break ;
100
104
}
101
105
case BVSLT :
102
106
{
107
+ //result = c3_bitblast_bvle (left, right, true, true);
103
108
break ;
104
109
}
105
110
default :
@@ -111,23 +116,39 @@ ASTNode *c3_bitblast_cmp(ASTNode *form) {
111
116
ASTVec c3_bitblast_term (ASTNode * term ) {
112
117
const ASTKind k = term -> kind ;
113
118
ASTVec children = term -> children , result ;
119
+ unsigned int numbits = term -> value_width ;
120
+
114
121
switch (k ) {
115
122
case BVNOT :
116
123
{
117
124
const ASTVec kids = c3_bitblast_term ((ASTNode * )children -> head -> data );
118
125
result = c3_bitblast_neg (kids );
119
126
break ;
120
127
}
128
+ case BVCONST :
129
+ {
130
+ ASTVec cnts = ast_vec_new ();
131
+ ASTBVConst * bvconst = term -> bvconst ;
132
+ unsigned int i ;
133
+ for (i = 0 ; i < numbits ; i ++ ) {
134
+ ast_vec_add (cnts , ast_bvc_bit_test (bvconst , i ) ? bb -> ASTTrue : bb -> ASTFalse );
135
+ }
136
+ result = cnts ;
137
+ break ;
138
+ }
121
139
default :
122
140
break ;
123
141
}
124
142
return result ;
125
143
}
126
144
127
145
ASTNode * c3_bitblast_form (ASTNode * form ) {
128
- ASTNode * result ;
146
+ ASTNode * result , * child ;
129
147
ASTVec children = form -> children ;
148
+ ASTVec echildren = ast_vec_new ();
149
+ C3ListIter * iter ;
130
150
const ASTKind k = form -> kind ;
151
+
131
152
switch (k ) {
132
153
case TRUE:
133
154
result = bb -> ASTTrue ;
@@ -136,10 +157,13 @@ ASTNode *c3_bitblast_form(ASTNode *form) {
136
157
result = bb -> ASTFalse ;
137
158
break ;
138
159
case NOT :
139
- result = ast_create_node1 (NOT , ( ASTNode * )children -> head -> data );
160
+ result = ast_create_node1 (NOT , c3_bitblast_form (( ASTNode * )children -> head -> data ) );
140
161
break ;
141
162
case ITE :
142
- result = ast_create_node3 (ITE , (ASTNode * )children -> head -> data , (ASTNode * )children -> head -> n -> data , (ASTNode * )children -> head -> n -> n -> data );
163
+ result = ast_create_node3 (ITE ,
164
+ c3_bitblast_form ((ASTNode * )children -> head -> data ),
165
+ c3_bitblast_form ((ASTNode * )children -> head -> n -> data ),
166
+ c3_bitblast_form ((ASTNode * )children -> head -> n -> n -> data ));
143
167
break ;
144
168
case AND :
145
169
case OR :
@@ -148,7 +172,10 @@ ASTNode *c3_bitblast_form(ASTNode *form) {
148
172
case IFF :
149
173
case XOR :
150
174
case IMPLIES :
151
- result = ast_create_node (k , children );
175
+ c3_list_foreach (children , iter , child ) {
176
+ c3_list_append (echildren , c3_bitblast_form (child ));
177
+ }
178
+ result = ast_create_node (k , echildren );
152
179
break ;
153
180
case EQ :
154
181
{
@@ -177,6 +204,6 @@ ASTNode *c3_bitblast_form(ASTNode *form) {
177
204
178
205
void c3_bitblast (C3 * c3 , ASTNode * assertq ) {
179
206
bb = c3_bitblast_new ();
180
- c3_bitblast_form (assertq );
207
+ assertq = c3_bitblast_form (assertq );
181
208
c3_bitblast_free (bb );
182
209
}
0 commit comments