@@ -154,9 +154,19 @@ static smt_termt convert_expr_to_smt(const bitnot_exprt &bitwise_not)
154
154
155
155
static smt_termt convert_expr_to_smt (const unary_minus_exprt &unary_minus)
156
156
{
157
- UNIMPLEMENTED_FEATURE (
158
- " Generation of SMT formula for unary minus expression: " +
159
- unary_minus.pretty ());
157
+ const bool operand_is_bitvector =
158
+ can_cast_type<integer_bitvector_typet>(unary_minus.op ().type ());
159
+ if (operand_is_bitvector)
160
+ {
161
+ return smt_bit_vector_theoryt::negate (
162
+ convert_expr_to_smt (unary_minus.op ()));
163
+ }
164
+ else
165
+ {
166
+ UNIMPLEMENTED_FEATURE (
167
+ " Generation of SMT formula for unary minus expression: " +
168
+ unary_minus.pretty ());
169
+ }
160
170
}
161
171
162
172
static smt_termt convert_expr_to_smt (const unary_plus_exprt &unary_plus)
@@ -326,20 +336,67 @@ static optionalt<smt_termt> try_relational_conversion(const exprt &expr)
326
336
327
337
static smt_termt convert_expr_to_smt (const plus_exprt &plus)
328
338
{
329
- UNIMPLEMENTED_FEATURE (
330
- " Generation of SMT formula for plus expression: " + plus.pretty ());
339
+ if (std::all_of (
340
+ plus.operands ().cbegin (), plus.operands ().cend (), [](exprt operand) {
341
+ return can_cast_type<integer_bitvector_typet>(operand.type ());
342
+ }))
343
+ {
344
+ return convert_multiary_operator_to_terms (
345
+ plus, smt_bit_vector_theoryt::add);
346
+ }
347
+ else
348
+ {
349
+ UNIMPLEMENTED_FEATURE (
350
+ " Generation of SMT formula for plus expression: " + plus.pretty ());
351
+ }
331
352
}
332
353
333
354
static smt_termt convert_expr_to_smt (const minus_exprt &minus)
334
355
{
335
- UNIMPLEMENTED_FEATURE (
336
- " Generation of SMT formula for minus expression: " + minus.pretty ());
356
+ const bool both_operands_bitvector =
357
+ can_cast_type<integer_bitvector_typet>(minus.lhs ().type ()) &&
358
+ can_cast_type<integer_bitvector_typet>(minus.rhs ().type ());
359
+
360
+ if (both_operands_bitvector)
361
+ {
362
+ return smt_bit_vector_theoryt::subtract (
363
+ convert_expr_to_smt (minus.lhs ()), convert_expr_to_smt (minus.rhs ()));
364
+ }
365
+ else
366
+ {
367
+ UNIMPLEMENTED_FEATURE (
368
+ " Generation of SMT formula for minus expression: " + minus.pretty ());
369
+ }
337
370
}
338
371
339
372
static smt_termt convert_expr_to_smt (const div_exprt ÷)
340
373
{
341
- UNIMPLEMENTED_FEATURE (
342
- " Generation of SMT formula for divide expression: " + divide.pretty ());
374
+ const bool both_operands_bitvector =
375
+ can_cast_type<integer_bitvector_typet>(divide.lhs ().type ()) &&
376
+ can_cast_type<integer_bitvector_typet>(divide.rhs ().type ());
377
+
378
+ const bool both_operands_unsigned =
379
+ can_cast_type<unsignedbv_typet>(divide.lhs ().type ()) &&
380
+ can_cast_type<unsignedbv_typet>(divide.rhs ().type ());
381
+
382
+ if (both_operands_bitvector)
383
+ {
384
+ if (both_operands_unsigned)
385
+ {
386
+ return smt_bit_vector_theoryt::unsigned_divide (
387
+ convert_expr_to_smt (divide.lhs ()), convert_expr_to_smt (divide.rhs ()));
388
+ }
389
+ else
390
+ {
391
+ return smt_bit_vector_theoryt::signed_divide (
392
+ convert_expr_to_smt (divide.lhs ()), convert_expr_to_smt (divide.rhs ()));
393
+ }
394
+ }
395
+ else
396
+ {
397
+ UNIMPLEMENTED_FEATURE (
398
+ " Generation of SMT formula for divide expression: " + divide.pretty ());
399
+ }
343
400
}
344
401
345
402
static smt_termt convert_expr_to_smt (const ieee_float_op_exprt &float_operation)
@@ -353,9 +410,35 @@ static smt_termt convert_expr_to_smt(const ieee_float_op_exprt &float_operation)
353
410
354
411
static smt_termt convert_expr_to_smt (const mod_exprt &truncation_modulo)
355
412
{
356
- UNIMPLEMENTED_FEATURE (
357
- " Generation of SMT formula for truncation modulo expression: " +
358
- truncation_modulo.pretty ());
413
+ const bool both_operands_bitvector =
414
+ can_cast_type<integer_bitvector_typet>(truncation_modulo.lhs ().type ()) &&
415
+ can_cast_type<integer_bitvector_typet>(truncation_modulo.rhs ().type ());
416
+
417
+ const bool both_operands_unsigned =
418
+ can_cast_type<unsignedbv_typet>(truncation_modulo.lhs ().type ()) &&
419
+ can_cast_type<unsignedbv_typet>(truncation_modulo.rhs ().type ());
420
+
421
+ if (both_operands_bitvector)
422
+ {
423
+ if (both_operands_unsigned)
424
+ {
425
+ return smt_bit_vector_theoryt::unsigned_remainder (
426
+ convert_expr_to_smt (truncation_modulo.lhs ()),
427
+ convert_expr_to_smt (truncation_modulo.rhs ()));
428
+ }
429
+ else
430
+ {
431
+ return smt_bit_vector_theoryt::signed_remainder (
432
+ convert_expr_to_smt (truncation_modulo.lhs ()),
433
+ convert_expr_to_smt (truncation_modulo.rhs ()));
434
+ }
435
+ }
436
+ else
437
+ {
438
+ UNIMPLEMENTED_FEATURE (
439
+ " Generation of SMT formula for remainder (modulus) expression: " +
440
+ truncation_modulo.pretty ());
441
+ }
359
442
}
360
443
361
444
static smt_termt
@@ -368,8 +451,22 @@ convert_expr_to_smt(const euclidean_mod_exprt &euclidean_modulo)
368
451
369
452
static smt_termt convert_expr_to_smt (const mult_exprt &multiply)
370
453
{
371
- UNIMPLEMENTED_FEATURE (
372
- " Generation of SMT formula for multiply expression: " + multiply.pretty ());
454
+ if (std::all_of (
455
+ multiply.operands ().cbegin (),
456
+ multiply.operands ().cend (),
457
+ [](exprt operand) {
458
+ return can_cast_type<integer_bitvector_typet>(operand.type ());
459
+ }))
460
+ {
461
+ return convert_multiary_operator_to_terms (
462
+ multiply, smt_bit_vector_theoryt::multiply);
463
+ }
464
+ else
465
+ {
466
+ UNIMPLEMENTED_FEATURE (
467
+ " Generation of SMT formula for multiply expression: " +
468
+ multiply.pretty ());
469
+ }
373
470
}
374
471
375
472
static smt_termt convert_expr_to_smt (const address_of_exprt &address_of)
0 commit comments