Skip to content

Commit fafc39c

Browse files
committed
SMT2: allow unary bitand, bitor, bitxor
This converts unary bitand, bitor, bitxor bit-vector expressions as the identity in the SMT2 backend.
1 parent 56d8598 commit fafc39c

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,46 +1301,40 @@ void smt2_convt::convert_expr(const exprt &expr)
13011301
{
13021302
convert_constant(to_constant_expr(expr));
13031303
}
1304-
else if(expr.id() == ID_concatenation && expr.operands().size() == 1)
1305-
{
1306-
DATA_INVARIANT_WITH_DIAGNOSTICS(
1307-
expr.type() == expr.operands().front().type(),
1308-
"concatenation over a single operand should have matching types",
1309-
expr.pretty());
1310-
1311-
convert_expr(expr.operands().front());
1312-
}
13131304
else if(
13141305
expr.id() == ID_concatenation || expr.id() == ID_bitand ||
13151306
expr.id() == ID_bitor || expr.id() == ID_bitxor)
13161307
{
13171308
DATA_INVARIANT_WITH_DIAGNOSTICS(
1318-
expr.operands().size() >= 2,
1319-
"given expression should have at least two operands",
1309+
!expr.operands().empty(),
1310+
"given expression should have at least one operand",
13201311
expr.id_string());
13211312

1322-
out << "(";
1323-
1324-
if(expr.id()==ID_concatenation)
1325-
out << "concat";
1326-
else if(expr.id()==ID_bitand)
1327-
out << "bvand";
1328-
else if(expr.id()==ID_bitor)
1329-
out << "bvor";
1330-
else if(expr.id()==ID_bitxor)
1331-
out << "bvxor";
1332-
else if(expr.id()==ID_bitnand)
1333-
out << "bvnand";
1334-
else if(expr.id()==ID_bitnor)
1335-
out << "bvnor";
1336-
1337-
for(const auto &op : expr.operands())
1313+
if(expr.operands().size() == 1)
13381314
{
1339-
out << " ";
1340-
flatten2bv(op);
1315+
flatten2bv(expr.operands().front());
13411316
}
1317+
else // >= 2
1318+
{
1319+
out << '(';
13421320

1343-
out << ")";
1321+
if(expr.id() == ID_concatenation)
1322+
out << "concat";
1323+
else if(expr.id() == ID_bitand)
1324+
out << "bvand";
1325+
else if(expr.id() == ID_bitor)
1326+
out << "bvor";
1327+
else if(expr.id() == ID_bitxor)
1328+
out << "bvxor";
1329+
1330+
for(const auto &op : expr.operands())
1331+
{
1332+
out << ' ';
1333+
flatten2bv(op);
1334+
}
1335+
1336+
out << ')';
1337+
}
13441338
}
13451339
else if(
13461340
expr.id() == ID_bitxnor || expr.id() == ID_bitnand ||

0 commit comments

Comments
 (0)