forked from martinjonas/Q3B
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExprToBDDTransformer.h
126 lines (100 loc) · 3.39 KB
/
ExprToBDDTransformer.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef ExprToBDDTransformer_h
#define ExprToBDDTransformer_h
#include <string>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <bdd.h>
#include <bvec.h>
#include <fdd.h>
#include <z3++.h>
#include "ExprSimplifier.h"
#include "VariableOrderer.h"
typedef std::pair<std::string, int> var;
enum BoundType { EXISTENTIAL, UNIVERSAL };
enum ApproximationType { ZERO_EXTEND, SIGN_EXTEND };
enum ReorderType { NO_REORDER, WIN2, WIN2_ITE, WIN3, WIN3_ITE, SIFT, SIFT_ITE };
enum InitialOrder { INTERLEAVE_ALL, HEURISTIC, SEQUENTIAL };
typedef std::pair<std::string, BoundType> boundVar;
class ExprToBDDTransformer
{
private:
std::map<std::string, bvec> vars;
std::map<std::string, bdd> varSets;
std::map<std::string, std::vector<int>> varIndices;
std::set<var> constSet;
std::set<var> boundVarSet;
std::map<const Z3_ast, std::pair<bdd, std::vector<boundVar>>> bddExprCache;
std::map<const Z3_ast, std::pair<bvec, std::vector<boundVar>>> bvecExprCache;
std::set<Z3_ast> processedVarsCache;
bdd m_bdd;
z3::context* context;
//std::map<std::string, int> varToBddIndex;
z3::expr expression;
int bv_size = 16;
void getVars(const z3::expr &e);
void loadVars();
void loadBDDsFromExpr(z3::expr);
bdd getBDDFromExpr(const z3::expr&, std::vector<boundVar>, bool onlyExistentials = false);
bvec getBvecFromExpr(const z3::expr&, std::vector<boundVar>);
unsigned int getNumeralValue(const z3::expr&);
unsigned int getNumeralOnes(const z3::expr&);
bvec getNumeralBvec(const z3::expr&);
bdd getConjunctionBdd(const std::vector<z3::expr>&, const std::vector<boundVar>&);
bdd getDisjunctionBdd(const std::vector<z3::expr>&, const std::vector<boundVar>&);
int exisentialBitWidth;
int universalBitWidth;
ApproximationType approximationType;
ReorderType reorderType = NO_REORDER;
InitialOrder initialOrder = HEURISTIC;
bool m_negateMul;
int cacheHits = 0;
public:
ExprToBDDTransformer(z3::context& context, z3::expr e) : ExprToBDDTransformer(context, e, HEURISTIC) {}
ExprToBDDTransformer(z3::context& context, z3::expr e, InitialOrder initialOrder);
bdd Proccess();
bdd ProcessUnderapproximation(int);
bdd ProcessOverapproximation(int);
std::map<std::string, bdd> GetVarSets() { return varSets; }
void setApproximationType(ApproximationType at)
{
approximationType = at;
}
void SetNegateMul(bool negateMul)
{
m_negateMul = negateMul;
}
void setReorderType(ReorderType rt)
{
reorderType = rt;
if (reorderType != NO_REORDER)
{
bdd_varblockall();
switch (reorderType)
{
case WIN2:
bdd_autoreorder(BDD_REORDER_WIN2);
break;
case WIN2_ITE:
bdd_autoreorder(BDD_REORDER_WIN2ITE);
break;
case WIN3:
bdd_autoreorder(BDD_REORDER_WIN3);
break;
case WIN3_ITE:
bdd_autoreorder(BDD_REORDER_WIN3ITE);
break;
case SIFT:
bdd_autoreorder(BDD_REORDER_SIFT);
break;
case SIFT_ITE:
bdd_autoreorder(BDD_REORDER_SIFTITE);
break;
default:
break;
}
}
}
};
#endif