@@ -35,6 +35,12 @@ static bool have_to_remove_vector(const exprt &expr)
35
35
}
36
36
else if (expr.id ()==ID_unary_minus || expr.id ()==ID_bitnot)
37
37
return true ;
38
+ else if (
39
+ expr.id () == ID_equal || expr.id () == ID_notequal || expr.id () == ID_lt ||
40
+ expr.id () == ID_le || expr.id () == ID_gt || expr.id () == ID_ge)
41
+ {
42
+ return true ;
43
+ }
38
44
else if (expr.id ()==ID_vector)
39
45
return true ;
40
46
}
@@ -103,6 +109,7 @@ static void remove_vector(exprt &expr)
103
109
// x+y -> vector(x[0]+y[0],x[1]+y[1],...)
104
110
array_exprt array_expr ({}, array_type);
105
111
array_expr.operands ().resize (numeric_cast_v<std::size_t >(dimension));
112
+ array_expr.add_source_location () = expr.source_location ();
106
113
107
114
for (std::size_t i=0 ; i<array_expr.operands ().size (); i++)
108
115
{
@@ -130,6 +137,7 @@ static void remove_vector(exprt &expr)
130
137
// -x -> vector(-x[0],-x[1],...)
131
138
array_exprt array_expr ({}, array_type);
132
139
array_expr.operands ().resize (numeric_cast_v<std::size_t >(dimension));
140
+ array_expr.add_source_location () = expr.source_location ();
133
141
134
142
for (std::size_t i=0 ; i<array_expr.operands ().size (); i++)
135
143
{
@@ -141,6 +149,41 @@ static void remove_vector(exprt &expr)
141
149
142
150
expr=array_expr;
143
151
}
152
+ else if (
153
+ expr.id () == ID_equal || expr.id () == ID_notequal || expr.id () == ID_lt ||
154
+ expr.id () == ID_le || expr.id () == ID_gt || expr.id () == ID_ge)
155
+ {
156
+ // component-wise and generate 0 (false) or -1 (true)
157
+ // x ~ y -> vector(x[0] ~ y[0] ? -1 : 0, x[1] ~ y[1] ? -1 : 0, ...)
158
+
159
+ auto const &binary_expr = to_binary_expr (expr);
160
+ const vector_typet &vector_type = to_vector_type (expr.type ());
161
+ const auto dimension = numeric_cast_v<std::size_t >(vector_type.size ());
162
+
163
+ const typet &subtype = vector_type.subtype ();
164
+ exprt minus_one = from_integer (-1 , subtype);
165
+ exprt zero = from_integer (0 , subtype);
166
+
167
+ exprt::operandst operands;
168
+ operands.reserve (dimension);
169
+
170
+ for (std::size_t i = 0 ; i < dimension; ++i)
171
+ {
172
+ exprt index = from_integer (i, vector_type.size ().type ());
173
+
174
+ operands.push_back (
175
+ if_exprt{binary_relation_exprt{index_exprt{binary_expr.lhs (), index },
176
+ binary_expr.id (),
177
+ index_exprt{binary_expr.rhs (), index }},
178
+ minus_one,
179
+ zero});
180
+ }
181
+
182
+ source_location source_location = expr.source_location ();
183
+ expr = array_exprt{std::move (operands),
184
+ array_typet{subtype, vector_type.size ()}};
185
+ expr.add_source_location () = std::move (source_location);
186
+ }
144
187
else if (expr.id ()==ID_vector)
145
188
{
146
189
expr.id (ID_array);
@@ -158,7 +201,9 @@ static void remove_vector(exprt &expr)
158
201
numeric_cast_v<std::size_t >(to_constant_expr (array_type.size ()));
159
202
exprt casted_op =
160
203
typecast_exprt::conditional_cast (op, array_type.subtype ());
204
+ source_location source_location = expr.source_location ();
161
205
expr = array_exprt (exprt::operandst (dimension, casted_op), array_type);
206
+ expr.add_source_location () = std::move (source_location);
162
207
}
163
208
}
164
209
}
0 commit comments