Skip to content

Commit e884c43

Browse files
committed
Split convert_overflow into binary and unary variations
Because the code used for one operand vs two operands is slightly different and because this facilitates a more type-specific implementation.
1 parent 4996426 commit e884c43

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/solvers/flattening/boolbv.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,16 @@ literalt boolbvt::convert_rest(const exprt &expr)
417417
else if(expr.id()==ID_onehot || expr.id()==ID_onehot0)
418418
return convert_onehot(to_unary_expr(expr));
419419
else if(
420-
can_cast_expr<binary_overflow_exprt>(expr) ||
421-
can_cast_expr<unary_minus_overflow_exprt>(expr))
420+
const auto binary_overflow =
421+
expr_try_dynamic_cast<binary_overflow_exprt>(expr))
422422
{
423-
return convert_overflow(expr);
423+
return convert_binary_overflow(*binary_overflow);
424+
}
425+
else if(
426+
const auto unary_overflow =
427+
expr_try_dynamic_cast<unary_overflow_exprt>(expr))
428+
{
429+
return convert_unary_overflow(*unary_overflow);
424430
}
425431
else if(expr.id()==ID_isnan)
426432
{

src/solvers/flattening/boolbv.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Author: Daniel Kroening, kroening@kroening.com
2727
#include "arrays.h"
2828

2929
class array_comprehension_exprt;
30+
class binary_overflow_exprt;
3031
class bitreverse_exprt;
3132
class bswap_exprt;
3233
class byte_extract_exprt;
@@ -38,6 +39,7 @@ class floatbv_typecast_exprt;
3839
class ieee_float_op_exprt;
3940
class member_exprt;
4041
class replication_exprt;
42+
class unary_overflow_exprt;
4143
class union_typet;
4244

4345
class boolbvt:public arrayst
@@ -140,7 +142,8 @@ class boolbvt:public arrayst
140142
virtual literalt convert_reduction(const unary_exprt &expr);
141143
virtual literalt convert_onehot(const unary_exprt &expr);
142144
virtual literalt convert_extractbit(const extractbit_exprt &expr);
143-
virtual literalt convert_overflow(const exprt &expr);
145+
virtual literalt convert_binary_overflow(const binary_overflow_exprt &expr);
146+
virtual literalt convert_unary_overflow(const unary_overflow_exprt &expr);
144147
virtual literalt convert_equality(const equal_exprt &expr);
145148
virtual literalt convert_verilog_case_equality(
146149
const binary_relation_exprt &expr);

src/solvers/flattening/boolbv_overflow.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Author: Daniel Kroening, kroening@kroening.com
1111

1212
#include "boolbv.h"
1313

14-
literalt boolbvt::convert_overflow(const exprt &expr)
14+
literalt boolbvt::convert_binary_overflow(const binary_overflow_exprt &expr)
1515
{
1616
const auto plus_or_minus_conversion =
1717
[&](
@@ -161,7 +161,13 @@ literalt boolbvt::convert_overflow(const exprt &expr)
161161
return
162162
prop.land(!neg_shift, prop.lselect(undef, prop.lor(bv0), overflow));
163163
}
164-
else if(
164+
165+
return SUB::convert_rest(expr);
166+
}
167+
168+
literalt boolbvt::convert_unary_overflow(const unary_overflow_exprt &expr)
169+
{
170+
if(
165171
const auto unary_minus_overflow =
166172
expr_try_dynamic_cast<unary_minus_overflow_exprt>(expr))
167173
{

0 commit comments

Comments
 (0)