|
23 | 23 |
|
24 | 24 | #include <libsolutil/Common.h> |
25 | 25 | #include <libsolutil/Numeric.h> |
| 26 | +#include <libsolutil/CommonData.h> |
26 | 27 |
|
| 28 | +#include <range/v3/algorithm/all_of.hpp> |
27 | 29 | #include <range/v3/view.hpp> |
28 | 30 |
|
29 | 31 | #include <cstdio> |
@@ -305,6 +307,64 @@ class Expression |
305 | 307 | ); |
306 | 308 | } |
307 | 309 |
|
| 310 | + static bool sameSort(std::vector<Expression> const& _args) |
| 311 | + { |
| 312 | + if (_args.empty()) |
| 313 | + return true; |
| 314 | + |
| 315 | + auto sort = _args.front().sort; |
| 316 | + return ranges::all_of( |
| 317 | + _args, |
| 318 | + [&](auto const& _expr){ return _expr.sort->kind == sort->kind; } |
| 319 | + ); |
| 320 | + } |
| 321 | + |
| 322 | + static Expression mkAnd(std::vector<Expression> _args) |
| 323 | + { |
| 324 | + smtAssert(!_args.empty(), ""); |
| 325 | + smtAssert(sameSort(_args), ""); |
| 326 | + |
| 327 | + auto sort = _args.front().sort; |
| 328 | + if (sort->kind == Kind::BitVector) |
| 329 | + return Expression("bvand", std::move(_args), sort); |
| 330 | + |
| 331 | + smtAssert(sort->kind == Kind::Bool, ""); |
| 332 | + return Expression("and", std::move(_args), Kind::Bool); |
| 333 | + } |
| 334 | + |
| 335 | + static Expression mkOr(std::vector<Expression> _args) |
| 336 | + { |
| 337 | + smtAssert(!_args.empty(), ""); |
| 338 | + smtAssert(sameSort(_args), ""); |
| 339 | + |
| 340 | + auto sort = _args.front().sort; |
| 341 | + if (sort->kind == Kind::BitVector) |
| 342 | + return Expression("bvor", std::move(_args), sort); |
| 343 | + |
| 344 | + smtAssert(sort->kind == Kind::Bool, ""); |
| 345 | + return Expression("or", std::move(_args), Kind::Bool); |
| 346 | + } |
| 347 | + |
| 348 | + static Expression mkPlus(std::vector<Expression> _args) |
| 349 | + { |
| 350 | + smtAssert(!_args.empty(), ""); |
| 351 | + smtAssert(sameSort(_args), ""); |
| 352 | + |
| 353 | + auto sort = _args.front().sort; |
| 354 | + smtAssert(sort->kind == Kind::BitVector || sort->kind == Kind::Int, ""); |
| 355 | + return Expression("+", std::move(_args), sort); |
| 356 | + } |
| 357 | + |
| 358 | + static Expression mkMul(std::vector<Expression> _args) |
| 359 | + { |
| 360 | + smtAssert(!_args.empty(), ""); |
| 361 | + smtAssert(sameSort(_args), ""); |
| 362 | + |
| 363 | + auto sort = _args.front().sort; |
| 364 | + smtAssert(sort->kind == Kind::BitVector || sort->kind == Kind::Int, ""); |
| 365 | + return Expression("*", std::move(_args), sort); |
| 366 | + } |
| 367 | + |
308 | 368 | friend Expression operator!(Expression _a) |
309 | 369 | { |
310 | 370 | if (_a.sort->kind == Kind::BitVector) |
|
0 commit comments