blob: d7f5d6fde4985644c799cceb40f93ab357f8e29c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include "theory/bv/bvintropow2.h"
#include "theory/rewriter.h"
#include "theory/bv/theory_bv_rewrite_rules_simplification.h"
namespace CVC4 {
namespace theory {
namespace bv {
void BVIntroducePow2::pow2Rewrite(std::vector<Node>& assertionsToPreprocess){
NodeMap cache;
for(size_t i = 0, N= assertionsToPreprocess.size(); i < N; ++i){
Node curr = assertionsToPreprocess[i];
Node next = pow2Rewrite(curr, cache);
if(next != curr){
Node tmp = Rewriter::rewrite(next);
next = tmp;
}
assertionsToPreprocess[i] = next;
}
}
Node BVIntroducePow2::pow2Rewrite(Node node, NodeMap& cache){
NodeMap::const_iterator ci = cache.find(node);
if(ci != cache.end()){
Node incache = (*ci).second;
return incache.isNull() ? node : incache;
}
Node res = Node::null();
switch(node.getKind()){
case kind::AND:
{
bool changed = false;
std::vector<Node> children;
for(unsigned i = 0, N = node.getNumChildren(); i < N; ++i){
Node child = node[i];
Node found = pow2Rewrite(child, cache);
changed = changed || (child != found);
children.push_back(found);
}
if(changed){
res = NodeManager::currentNM()->mkNode(kind::AND, children);
}
}
break;
case kind::EQUAL:
if(node[0].getType().isBitVector()){
if (RewriteRule<IsPowerOfTwo>::applies(node)) {
res = RewriteRule<IsPowerOfTwo>::run<false>(node);
}
}
break;
default:
break;
}
cache.insert(std::make_pair(node, res));
return res.isNull() ? node : res;
}
}/* CVC4::theory::bv namespace */
}/* CVC4::theory namespace */
}/* CVC4 namespace */
|