GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bv/bv_eager_solver.cpp Lines: 39 46 84.8 %
Date: 2021-05-24 Branches: 52 200 26.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Mathias Preiner, Liana Hadarean, Tim King
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 *
13
 * Eager bit-blasting solver.
14
 */
15
16
#include "theory/bv/bv_eager_solver.h"
17
18
#include "options/bv_options.h"
19
#include "options/smt_options.h"
20
#include "theory/bv/bitblast/aig_bitblaster.h"
21
#include "theory/bv/bitblast/eager_bitblaster.h"
22
23
using namespace std;
24
25
namespace cvc5 {
26
namespace theory {
27
namespace bv {
28
29
39
EagerBitblastSolver::EagerBitblastSolver(context::Context* c, BVSolverLazy* bv)
30
    : d_assertionSet(c),
31
      d_assumptionSet(c),
32
      d_context(c),
33
      d_bitblaster(),
34
      d_aigBitblaster(),
35
39
      d_useAig(options::bitvectorAig()),
36
78
      d_bv(bv)
37
{
38
39
}
39
40
39
EagerBitblastSolver::~EagerBitblastSolver() {}
41
42
void EagerBitblastSolver::turnOffAig() {
43
  Assert(d_aigBitblaster == nullptr && d_bitblaster == nullptr);
44
  d_useAig = false;
45
}
46
47
29
void EagerBitblastSolver::initialize() {
48
29
  Assert(!isInitialized());
49
29
  if (d_useAig) {
50
#ifdef CVC5_USE_ABC
51
    d_aigBitblaster.reset(new AigBitblaster());
52
#else
53
    Unreachable();
54
#endif
55
  } else {
56
29
    d_bitblaster.reset(new EagerBitblaster(d_bv, d_context));
57
  }
58
29
}
59
60
2952
bool EagerBitblastSolver::isInitialized() {
61
2952
  const bool init = d_aigBitblaster != nullptr || d_bitblaster != nullptr;
62
2952
  Assert(!init || !d_useAig || d_aigBitblaster);
63
2952
  Assert(!init || d_useAig || d_bitblaster);
64
2952
  return init;
65
}
66
67
620
void EagerBitblastSolver::assertFormula(TNode formula) {
68
620
  d_bv->spendResource(Resource::BvEagerAssertStep);
69
620
  Assert(isInitialized());
70
1240
  Debug("bitvector-eager") << "EagerBitblastSolver::assertFormula " << formula
71
620
                           << "\n";
72
620
  if (options::incrementalSolving() && d_context->getLevel() > 1)
73
  {
74
48
    d_assumptionSet.insert(formula);
75
  }
76
620
  d_assertionSet.insert(formula);
77
  // ensures all atoms are bit-blasted and converted to AIG
78
620
  if (d_useAig) {
79
#ifdef CVC5_USE_ABC
80
    d_aigBitblaster->bbFormula(formula);
81
#else
82
    Unreachable();
83
#endif
84
  }
85
  else
86
  {
87
620
    d_bitblaster->bbFormula(formula);
88
  }
89
620
}
90
91
53
bool EagerBitblastSolver::checkSat() {
92
53
  Assert(isInitialized());
93
53
  if (d_assertionSet.empty()) {
94
2
    return true;
95
  }
96
97
51
  if (d_useAig) {
98
#ifdef CVC5_USE_ABC
99
    const std::vector<Node> assertions = {d_assertionSet.key_begin(),
100
                                          d_assertionSet.key_end()};
101
    Assert(!assertions.empty());
102
103
    Node query = utils::mkAnd(assertions);
104
    return d_aigBitblaster->solve(query);
105
#else
106
    Unreachable();
107
#endif
108
  }
109
110
51
  if (options::incrementalSolving())
111
  {
112
    const std::vector<Node> assumptions = {d_assumptionSet.key_begin(),
113
68
                                           d_assumptionSet.key_end()};
114
34
    return d_bitblaster->solve(assumptions);
115
  }
116
17
  return d_bitblaster->solve();
117
}
118
119
9
bool EagerBitblastSolver::collectModelInfo(TheoryModel* m, bool fullModel)
120
{
121
9
  AlwaysAssert(!d_useAig && d_bitblaster);
122
9
  return d_bitblaster->collectModelInfo(m, fullModel);
123
}
124
125
}  // namespace bv
126
}  // namespace theory
127
28191
}  // namespace cvc5