Skip to content

SMT2: bvnor, bvnand are binary only; add bvxnor #8508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 57 additions & 6 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,12 +1220,9 @@

convert_expr(expr.operands().front());
}
else if(expr.id()==ID_concatenation ||
expr.id()==ID_bitand ||
expr.id()==ID_bitor ||
expr.id()==ID_bitxor ||
expr.id()==ID_bitnand ||
expr.id()==ID_bitnor)
else if(
expr.id() == ID_concatenation || expr.id() == ID_bitand ||
expr.id() == ID_bitor || expr.id() == ID_bitxor)
{
DATA_INVARIANT_WITH_DIAGNOSTICS(
expr.operands().size() >= 2,
Expand Down Expand Up @@ -1255,6 +1252,60 @@

out << ")";
}
else if(
expr.id() == ID_bitxnor || expr.id() == ID_bitnand ||
expr.id() == ID_bitnor)
{

Check warning on line 1258 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1258

Added line #L1258 was not covered by tests
// SMT-LIB only has these as a binary expression,
// owing to their ambiguity.

Check warning on line 1260 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1260

Added line #L1260 was not covered by tests
if(expr.operands().size() == 2)
{

Check warning on line 1262 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1262

Added line #L1262 was not covered by tests
const auto &binary_expr = to_binary_expr(expr);

Check warning on line 1264 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1264

Added line #L1264 was not covered by tests
out << '(';
if(binary_expr.id() == ID_bitxnor)
out << "bvxnor";

Check warning on line 1267 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1267

Added line #L1267 was not covered by tests
else if(binary_expr.id() == ID_bitnand)
out << "bvnand";
else if(binary_expr.id() == ID_bitnor)
out << "bvnor";

Check warning on line 1271 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1270-L1271

Added lines #L1270 - L1271 were not covered by tests
out << ' ';
flatten2bv(binary_expr.op0());
out << ' ';
flatten2bv(binary_expr.op1());
out << ')';
}
else if(expr.operands().size() == 1)
{
out << "(bvnot ";
flatten2bv(to_unary_expr(expr).op());
out << ')';

Check warning on line 1282 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1278-L1282

Added lines #L1278 - L1282 were not covered by tests
}
else if(expr.operands().size() >= 3)
{
out << "(bvnot (";

Check warning on line 1286 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1284-L1286

Added lines #L1284 - L1286 were not covered by tests
if(expr.id() == ID_bitxnor)
out << "bvxor";
else if(expr.id() == ID_bitnand)
out << "bvand";
else if(expr.id() == ID_bitnor)
out << "bvor";

Check warning on line 1293 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1288-L1293

Added lines #L1288 - L1293 were not covered by tests
for(const auto &op : expr.operands())
{
out << ' ';
flatten2bv(op);

Check warning on line 1297 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1295-L1297

Added lines #L1295 - L1297 were not covered by tests
}

out << "))"; // bvX, bvnot

Check warning on line 1300 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1300

Added line #L1300 was not covered by tests
}
else
{
DATA_INVARIANT(
expr.operands().size() >= 1,

Check warning on line 1305 in src/solvers/smt2/smt2_conv.cpp

View check run for this annotation

Codecov / codecov/patch

src/solvers/smt2/smt2_conv.cpp#L1303-L1305

Added lines #L1303 - L1305 were not covered by tests
expr.id_string() + " should have at least one operand");
}
}
else if(expr.id()==ID_bitnot)
{
const bitnot_exprt &bitnot_expr = to_bitnot_expr(expr);
Expand Down
4 changes: 3 additions & 1 deletion src/util/bitvector_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class bitxnor_exprt : public multi_ary_exprt
{
public:
bitxnor_exprt(exprt _op0, exprt _op1)
: multi_ary_exprt(std::move(_op0), ID_bitxnor, std::move(_op1))
: multi_ary_exprt(_op0, ID_bitxnor, _op1, _op0.type())
{
}

Expand All @@ -278,13 +278,15 @@ inline bool can_cast_expr<bitxnor_exprt>(const exprt &base)
inline const bitxnor_exprt &to_bitxnor_expr(const exprt &expr)
{
PRECONDITION(expr.id() == ID_bitxnor);
bitxnor_exprt::check(expr, validation_modet::INVARIANT);
return static_cast<const bitxnor_exprt &>(expr);
}

/// \copydoc to_bitxnor_expr(const exprt &)
inline bitxnor_exprt &to_bitxnor_expr(exprt &expr)
{
PRECONDITION(expr.id() == ID_bitxnor);
bitxnor_exprt::check(expr, validation_modet::INVARIANT);
return static_cast<bitxnor_exprt &>(expr);
}

Expand Down
Loading