@@ -65,96 +65,104 @@ SCENARIO("byte_extract_lowering", "[core][solvers][lowering][byte_extract]")
65
65
GIVEN (" A collection of types" )
66
66
{
67
67
unsignedbv_typet u8 (8 );
68
+ signedbv_typet s8 (8 );
69
+ unsignedbv_typet u16 (16 );
70
+ signedbv_typet s16 (16 );
68
71
unsignedbv_typet u32 (32 );
72
+ signedbv_typet s32 (32 );
69
73
unsignedbv_typet u64 (64 );
74
+ signedbv_typet s64 (64 );
70
75
71
76
constant_exprt size = from_integer (8 , size_type ());
72
77
73
78
std::vector<typet> types = {
74
- struct_typet ({{" comp1" , u32}, {" comp2" , u64}}),
79
+ // struct_typet({{"comp1", u16}, {"comp2", u16}}),
80
+ // struct_typet({{"comp1", u32}, {"comp2", u64}}),
75
81
#if 0
76
82
// not currently handled: components not byte aligned
77
83
struct_typet({{"comp1", u32},
78
84
{"compX", c_bit_field_typet(u8, 4)},
79
85
{"pad", c_bit_field_typet(u8, 4)},
80
86
{"comp2", u8}}),
81
87
#endif
82
- union_typet ({{" compA" , u32}, {" compB" , u64}}),
83
- c_enum_typet (unsignedbv_typet (16 )),
84
- array_typet (u8, size),
85
- array_typet (u64, size),
88
+ // union_typet({{"compA", u32}, {"compB", u64}}),
89
+ // c_enum_typet(u16),
90
+ // c_enum_typet(unsignedbv_typet(128)),
91
+ // array_typet(u8, size),
92
+ // array_typet(s32, size),
93
+ // array_typet(u64, size),
86
94
unsignedbv_typet (24 ),
95
+ unsignedbv_typet (128 ),
96
+ signedbv_typet (24 ),
87
97
signedbv_typet (128 ),
88
- ieee_float_spect::single_precision ().to_type (),
89
- pointer_typet (u64, 64 ),
90
- vector_typet (u8, size),
91
- vector_typet (u64, size),
92
- complex_typet (u32)
98
+ // ieee_float_spect::single_precision().to_type(),
99
+ // pointer_typet(u64, 64),
100
+ // vector_typet(u8, size),
101
+ // vector_typet(u64, size),
102
+ // complex_typet(s16),
103
+ // complex_typet(u64)
93
104
};
94
105
95
106
simplify_exprt simp (ns);
96
107
97
108
THEN (" byte_extract lowering yields the expected value" )
98
109
{
99
- for (const auto &t1 : types)
110
+ for (const auto endianness :
111
+ {ID_byte_extract_little_endian, ID_byte_extract_big_endian})
100
112
{
101
- std::ostringstream oss;
102
- for (int i = 0 ; i < 64 ; ++i)
103
- oss << integer2binary (i, 8 );
104
-
105
- const auto type_bits = pointer_offset_bits (t1, ns);
106
- REQUIRE (type_bits);
107
- const auto type_bits_int = numeric_cast_v<std::size_t >(*type_bits);
108
- REQUIRE (type_bits_int <= oss.str ().size ());
109
- const exprt s =
110
- simp.bits2expr (oss.str ().substr (0 , type_bits_int), t1, true );
111
- REQUIRE (s.is_not_nil ());
112
-
113
- for (const auto &t2 : types)
113
+ for (const auto &t1 : types)
114
114
{
115
- oss. str ( " " ) ;
116
- for (int i = 2 ; i < 66 ; ++i)
115
+ std::ostringstream oss;
116
+ for (int i = 0 ; i < 64 ; ++i)
117
117
oss << integer2binary (i, 8 );
118
118
119
- const auto type_bits_2 = pointer_offset_bits (t2, ns);
120
- REQUIRE (type_bits_2);
121
- const auto type_bits_2_int =
122
- numeric_cast_v<std::size_t >(*type_bits_2);
123
- REQUIRE (type_bits_2_int <= oss.str ().size ());
124
- const exprt r =
125
- simp.bits2expr (oss.str ().substr (0 , type_bits_2_int), t2, true );
126
- REQUIRE (r.is_not_nil ());
127
-
128
- const byte_extract_exprt be1 (
129
- ID_byte_extract_little_endian,
130
- s,
131
- from_integer (2 , index_type ()),
132
- t2);
133
-
134
- const exprt lower_be1 = lower_byte_extract (be1, ns);
135
- const exprt lower_be1_s = simplify_expr (lower_be1, ns);
136
-
137
- // TODO: does not currently hold
138
- // REQUIRE(!has_subexpr(lower_be1, ID_byte_extract_little_endian));
139
- REQUIRE (lower_be1.type () == be1.type ());
140
- // TODO: does not currently hold
141
- // REQUIRE(lower_be1 == r);
142
- // TODO: does not currently hold
143
- // REQUIRE(lower_be1_s == r);
144
-
145
- const byte_extract_exprt be2 (
146
- ID_byte_extract_big_endian, s, from_integer (2 , index_type ()), t2);
147
-
148
- const exprt lower_be2 = lower_byte_extract (be2, ns);
149
- const exprt lower_be2_s = simplify_expr (lower_be2, ns);
150
-
151
- // TODO: does not currently hold
152
- REQUIRE (!has_subexpr (lower_be2, ID_byte_extract_big_endian));
153
- REQUIRE (lower_be2.type () == be2.type ());
154
- // TODO: does not currently hold
155
- // REQUIRE(lower_be2 == r);
156
- // TODO: does not currently hold
157
- // REQUIRE(lower_be2_s == r);
119
+ const auto type_bits = pointer_offset_bits (t1, ns);
120
+ REQUIRE (type_bits);
121
+ const auto type_bits_int = numeric_cast_v<std::size_t >(*type_bits);
122
+ REQUIRE (type_bits_int <= oss.str ().size ());
123
+ const exprt s = simp.bits2expr (
124
+ oss.str ().substr (0 , type_bits_int),
125
+ t1,
126
+ endianness == ID_byte_extract_little_endian);
127
+ REQUIRE (s.is_not_nil ());
128
+
129
+ for (const auto &t2 : types)
130
+ {
131
+ oss.str (" " );
132
+ for (int i = 2 ; i < 64 ; ++i)
133
+ oss << integer2binary (i, 8 );
134
+
135
+ const auto type_bits_2 = pointer_offset_bits (t2, ns);
136
+ REQUIRE (type_bits_2);
137
+
138
+ // for now only extract within bounds
139
+ if (*type_bits_2 + 16 > *type_bits)
140
+ continue ;
141
+
142
+ const auto type_bits_2_int =
143
+ numeric_cast_v<std::size_t >(*type_bits_2);
144
+ REQUIRE (type_bits_2_int <= oss.str ().size ());
145
+ const exprt r = simp.bits2expr (
146
+ oss.str ().substr (0 , type_bits_2_int),
147
+ t2,
148
+ endianness == ID_byte_extract_little_endian);
149
+ REQUIRE (r.is_not_nil ());
150
+
151
+ const byte_extract_exprt be (
152
+ endianness, s, from_integer (2 , index_type ()), t2);
153
+
154
+ const exprt lower_be = lower_byte_extract (be, ns);
155
+ const exprt lower_be_s = simplify_expr (lower_be, ns);
156
+
157
+ // TODO: does not currently hold
158
+ // REQUIRE(!has_subexpr(lower_be, ID_byte_extract_little_endian));
159
+ // REQUIRE(!has_subexpr(lower_be, ID_byte_extract_big_endian));
160
+ REQUIRE (lower_be.type () == be.type ());
161
+ // TODO: does not currently hold
162
+ // REQUIRE(lower_be == r);
163
+ // TODO: does not currently hold
164
+ // REQUIRE(lower_be_s == r);
165
+ }
158
166
}
159
167
}
160
168
}
@@ -208,13 +216,19 @@ SCENARIO("byte_update_lowering", "[core][solvers][lowering][byte_update]")
208
216
GIVEN (" A collection of types" )
209
217
{
210
218
unsignedbv_typet u8 (8 );
219
+ signedbv_typet s8 (8 );
220
+ unsignedbv_typet u16 (16 );
221
+ signedbv_typet s16 (16 );
211
222
unsignedbv_typet u32 (32 );
223
+ signedbv_typet s32 (32 );
212
224
unsignedbv_typet u64 (64 );
225
+ signedbv_typet s64 (64 );
213
226
214
227
constant_exprt size = from_integer (8 , size_type ());
215
228
216
229
std::vector<typet> types = {
217
230
// TODO: only arrays and scalars
231
+ // struct_typet({{"comp1", u16}, {"comp2", u16}}),
218
232
// struct_typet({{"comp1", u32}, {"comp2", u64}}),
219
233
#if 0
220
234
// not currently handled: components not byte aligned
@@ -225,83 +239,88 @@ SCENARIO("byte_update_lowering", "[core][solvers][lowering][byte_update]")
225
239
#endif
226
240
// TODO: only arrays and scalars
227
241
// union_typet({{"compA", u32}, {"compB", u64}}),
228
- // c_enum_typet(unsignedbv_typet(16)),
229
- array_typet (u8, size),
230
- array_typet (u64, size),
242
+ // c_enum_typet(u16),
243
+ // c_enum_typet(unsignedbv_typet(128)),
244
+ // array_typet(u8, size),
245
+ // array_typet(s32, size),
246
+ // array_typet(u64, size),
231
247
unsignedbv_typet (24 ),
248
+ unsignedbv_typet (128 ),
249
+ signedbv_typet (24 ),
232
250
signedbv_typet (128 ),
233
- ieee_float_spect::single_precision ().to_type (),
234
- pointer_typet (u64, 64 ),
251
+ // ieee_float_spect::single_precision().to_type(),
252
+ // pointer_typet(u64, 64),
235
253
// TODO: only arrays and scalars
236
254
// vector_typet(u8, size),
237
255
// vector_typet(u64, size),
238
- // complex_typet(u32)
256
+ // complex_typet(s16),
257
+ // complex_typet(u64)
239
258
};
240
259
241
260
simplify_exprt simp (ns);
242
261
243
262
THEN (" byte_update lowering yields the expected value" )
244
263
{
245
- for (const auto &t1 : types)
264
+ for (const auto endianness :
265
+ {ID_byte_update_little_endian, ID_byte_update_big_endian})
246
266
{
247
- std::ostringstream oss;
248
- for (int i = 0 ; i < 64 ; ++i)
249
- oss << integer2binary (i, 8 );
250
-
251
- const auto type_bits = pointer_offset_bits (t1, ns);
252
- REQUIRE (type_bits);
253
- const auto type_bits_int = numeric_cast_v<std::size_t >(*type_bits);
254
- REQUIRE (type_bits_int <= oss.str ().size ());
255
- const exprt s =
256
- simp.bits2expr (oss.str ().substr (0 , type_bits_int), t1, true );
257
- REQUIRE (s.is_not_nil ());
258
-
259
- for (const auto &t2 : types)
267
+ for (const auto &t1 : types)
260
268
{
261
- oss. str ( " " ) ;
262
- for (int i = 64 ; i < 128 ; ++i)
269
+ std::ostringstream oss;
270
+ for (int i = 0 ; i < 64 ; ++i)
263
271
oss << integer2binary (i, 8 );
264
272
265
- const auto type_bits_2 = pointer_offset_bits (t2, ns);
266
- REQUIRE (type_bits_2);
267
- const auto type_bits_2_int =
268
- numeric_cast_v<std::size_t >(*type_bits_2);
269
- REQUIRE (type_bits_2_int <= oss.str ().size ());
270
- const exprt u =
271
- simp.bits2expr (oss.str ().substr (0 , type_bits_2_int), t2, true );
272
- REQUIRE (u.is_not_nil ());
273
-
274
- // TODO: currently required
275
- if (type_bits < type_bits_2)
276
- continue ;
277
-
278
- const byte_update_exprt bu1 (
279
- ID_byte_update_little_endian, s, from_integer (2 , index_type ()), u);
280
-
281
- const exprt lower_bu1 = lower_byte_operators (bu1, ns);
282
- const exprt lower_bu1_s = simplify_expr (lower_bu1, ns);
283
-
284
- REQUIRE (!has_subexpr (lower_bu1, ID_byte_update_little_endian));
285
- REQUIRE (!has_subexpr (lower_bu1, ID_byte_extract_little_endian));
286
- REQUIRE (lower_bu1.type () == bu1.type ());
287
- // TODO: does not currently hold
288
- // REQUIRE(lower_bu1 == u);
289
- // TODO: does not currently hold
290
- // REQUIRE(lower_bu1_s == u);
291
-
292
- const byte_update_exprt bu2 (
293
- ID_byte_update_big_endian, s, from_integer (2 , index_type ()), u);
294
-
295
- const exprt lower_bu2 = lower_byte_operators (bu2, ns);
296
- const exprt lower_bu2_s = simplify_expr (lower_bu2, ns);
297
-
298
- REQUIRE (!has_subexpr (lower_bu2, ID_byte_update_big_endian));
299
- REQUIRE (!has_subexpr (lower_bu2, ID_byte_extract_big_endian));
300
- REQUIRE (lower_bu2.type () == bu2.type ());
301
- // TODO: does not currently hold
302
- // REQUIRE(lower_bu2 == u);
303
- // TODO: does not currently hold
304
- // REQUIRE(lower_bu2_s == u);
273
+ const auto type_bits = pointer_offset_bits (t1, ns);
274
+ REQUIRE (type_bits);
275
+ const auto type_bits_int = numeric_cast_v<std::size_t >(*type_bits);
276
+ REQUIRE (type_bits_int <= oss.str ().size ());
277
+ std::string s_string = oss.str ().substr (0 , type_bits_int);
278
+ const exprt s = simp.bits2expr (
279
+ s_string, t1, endianness == ID_byte_update_little_endian);
280
+ REQUIRE (s.is_not_nil ());
281
+
282
+ for (const auto &t2 : types)
283
+ {
284
+ oss.str (" " );
285
+ for (int i = 64 ; i < 128 ; ++i)
286
+ oss << integer2binary (i, 8 );
287
+
288
+ const auto type_bits_2 = pointer_offset_bits (t2, ns);
289
+ REQUIRE (type_bits_2);
290
+
291
+ // for now only update within bounds
292
+ if (*type_bits_2 + 16 > *type_bits)
293
+ continue ;
294
+
295
+ const auto type_bits_2_int =
296
+ numeric_cast_v<std::size_t >(*type_bits_2);
297
+ REQUIRE (type_bits_2_int <= oss.str ().size ());
298
+ std::string u_string = oss.str ().substr (0 , type_bits_2_int);
299
+ const exprt u = simp.bits2expr (
300
+ u_string, t2, endianness == ID_byte_update_little_endian);
301
+ REQUIRE (u.is_not_nil ());
302
+
303
+ const exprt r = simp.bits2expr (
304
+ s_string.replace (16 , u_string.size (), u_string),
305
+ t1,
306
+ endianness == ID_byte_update_little_endian);
307
+ REQUIRE (r.is_not_nil ());
308
+
309
+ const byte_update_exprt bu (
310
+ endianness, s, from_integer (2 , index_type ()), u);
311
+
312
+ const exprt lower_bu = lower_byte_operators (bu, ns);
313
+ const exprt lower_bu_s = simplify_expr (lower_bu, ns);
314
+
315
+ REQUIRE (!has_subexpr (lower_bu, endianness));
316
+ REQUIRE (!has_subexpr (lower_bu, ID_byte_extract_big_endian));
317
+ REQUIRE (!has_subexpr (lower_bu, ID_byte_extract_little_endian));
318
+ REQUIRE (lower_bu.type () == bu.type ());
319
+ // TODO: does not currently hold
320
+ // REQUIRE(lower_bu == r);
321
+ // TODO: does not currently hold
322
+ // REQUIRE(lower_bu_s == r);
323
+ }
305
324
}
306
325
}
307
326
}
0 commit comments