Skip to content

Commit 283d3bd

Browse files
committed
Refactor conversion of shift operators
In preparation for adding conversion of shifts with operands of mismatched sizes.
1 parent afda322 commit 283d3bd

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -652,34 +652,35 @@ static smt_termt convert_expr_to_smt(const index_exprt &index)
652652
"Generation of SMT formula for index expression: " + index.pretty());
653653
}
654654

655-
static smt_termt convert_expr_to_smt(const shift_exprt &shift)
655+
template <typename factoryt, typename shiftt>
656+
static smt_termt
657+
convert_to_smt_shift(const factoryt &factory, const shiftt &shift)
656658
{
657-
// TODO: Dispatch into different types of shifting
658-
const auto &first_operand = shift.op0();
659-
const auto &second_operand = shift.op1();
659+
const smt_termt first_operand = convert_expr_to_smt(shift.op0());
660+
const smt_termt second_operand = convert_expr_to_smt(shift.op1());
661+
return factory(first_operand, second_operand);
662+
}
660663

664+
static smt_termt convert_expr_to_smt(const shift_exprt &shift)
665+
{
666+
// TODO: Dispatch for rotation expressions. A `shift_exprt` can be a rotation.
661667
if(const auto left_shift = expr_try_dynamic_cast<shl_exprt>(shift))
662668
{
663-
return smt_bit_vector_theoryt::shift_left(
664-
convert_expr_to_smt(first_operand), convert_expr_to_smt(second_operand));
669+
return convert_to_smt_shift(
670+
smt_bit_vector_theoryt::shift_left, *left_shift);
665671
}
666-
else if(
667-
const auto right_logical_shift = expr_try_dynamic_cast<lshr_exprt>(shift))
672+
if(const auto right_logical_shift = expr_try_dynamic_cast<lshr_exprt>(shift))
668673
{
669-
return smt_bit_vector_theoryt::logical_shift_right(
670-
convert_expr_to_smt(first_operand), convert_expr_to_smt(second_operand));
674+
return convert_to_smt_shift(
675+
smt_bit_vector_theoryt::logical_shift_right, *right_logical_shift);
671676
}
672-
else if(
673-
const auto right_arith_shift = expr_try_dynamic_cast<ashr_exprt>(shift))
677+
if(const auto right_arith_shift = expr_try_dynamic_cast<ashr_exprt>(shift))
674678
{
675-
return smt_bit_vector_theoryt::arithmetic_shift_right(
676-
convert_expr_to_smt(first_operand), convert_expr_to_smt(second_operand));
677-
}
678-
else
679-
{
680-
UNIMPLEMENTED_FEATURE(
681-
"Generation of SMT formula for shift expression: " + shift.pretty());
679+
return convert_to_smt_shift(
680+
smt_bit_vector_theoryt::arithmetic_shift_right, *right_arith_shift);
682681
}
682+
UNIMPLEMENTED_FEATURE(
683+
"Generation of SMT formula for shift expression: " + shift.pretty());
683684
}
684685

685686
static smt_termt convert_expr_to_smt(const with_exprt &with)

0 commit comments

Comments
 (0)