5 #include "corestructs.h"
7 #include "solver_interface.h"
14 /** This function creates a set containing the elements passed in the array. */
15 Set *createSet(VarType type, uint64_t *elements, uint num);
17 /** This function creates a set from lowrange to highrange (inclusive). */
19 Set *createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange);
21 Element *createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange);
23 /** This function creates a mutable set. */
25 MutableSet *createMutableSet(VarType type);
27 /** This function adds a new item to a set. */
29 void addItem(MutableSet *set, uint64_t element);
31 /** This function adds a new unique item to the set and returns it.
32 This function cannot be used in conjunction with manually adding
35 uint64_t createUniqueItem(MutableSet *set);
37 /** This function creates an element variable over a set. */
39 Element *getElementVar(Set *set);
41 /** This function creates an element constrant. */
42 Element *getElementConst(VarType type, uint64_t value);
44 Boolean *getBooleanTrue();
46 Boolean *getBooleanFalse();
48 /** This function creates a boolean variable. */
50 Boolean *getBooleanVar(VarType type);
52 /** This function creates a function operator. */
54 Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
55 OverFlowBehavior overflowbehavior);
57 /** This function creates a predicate operator. */
59 Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
61 Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
63 /** This function creates an empty instance table.*/
65 Table *createTable(Set **domains, uint numDomain, Set *range);
67 Table *createTableForPredicate(Set **domains, uint numDomain);
68 /** This function adds an input output relation to a table. */
70 void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
72 /** This function converts a completed table into a function. */
74 Function *completeTable(Table *, UndefinedBehavior behavior);
76 /** This function applies a function to the Elements in its input. */
78 Element *applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus);
80 /** This function applies a predicate to the Elements in its input. */
82 Boolean *applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus);
84 Boolean *applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
86 /** This function applies a logical operation to the Booleans in its input. */
88 Boolean *applyLogicalOperation(LogicOp op, Boolean **array, uint asize);
90 /** This function applies a logical operation to the Booleans in its input. */
92 Boolean *applyLogicalOperation(LogicOp op, Boolean * arg1, Boolean * arg2);
94 /** This function applies a logical operation to the Booleans in its input. */
96 Boolean *applyLogicalOperation(LogicOp op, Boolean *arg);
98 /** This function adds a boolean constraint to the set of constraints
101 void addConstraint(Boolean *constraint);
103 /** This function instantiates an order of type type over the set set. */
104 Order *createOrder(OrderType type, Set *set);
106 /** This function instantiates a boolean on two items in an order. */
107 Boolean *orderConstraint(Order *order, uint64_t first, uint64_t second);
109 /** When everything is done, the client calls this function and then csolver starts to encode*/
112 /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
113 uint64_t getElementValue(Element *element);
115 /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
116 bool getBooleanValue(Boolean *boolean);
118 HappenedBefore getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
120 bool isTrue(Boolean *b);
121 bool isFalse(Boolean *b);
123 void setUnSAT() { unsat = true; }
125 bool isUnSAT() { return unsat; }
127 Vector<Order *> *getOrders() { return &allOrders;}
129 Tuner *getTuner() { return tuner; }
130 Transformer* getTransformer() {return transformer;}
132 SetIteratorBoolean *getConstraints() { return constraints.iterator(); }
134 SATEncoder *getSATEncoder() {return satEncoder;}
136 void replaceBooleanWithTrue(Boolean *bexpr);
137 void replaceBooleanWithFalse(Boolean *bexpr);
138 void replaceBooleanWithBoolean(Boolean *oldb, Boolean *newb);
140 void autoTune(uint budget);
142 void setTransformer(Transformer * _transformer) { transformer = _transformer; }
143 void setTuner(Tuner * _tuner) { tuner = _tuner; }
144 long long getElapsedTime() { return elapsedTime; }
145 long long getEncodeTime();
146 long long getSolveTime();
151 void handleXORFalse(BooleanLogic *bexpr, Boolean *child);
152 void handleIMPLIESTrue(BooleanLogic *bexpr, Boolean *child);
153 void handleIMPLIESFalse(BooleanLogic *bexpr, Boolean *child);
154 void handleANDTrue(BooleanLogic *bexpr, Boolean *child);
155 void handleORFalse(BooleanLogic *bexpr, Boolean *child);
157 /** This is a vector of constraints that must be satisfied. */
158 HashsetBoolean constraints;
160 /** This is a vector of all boolean structs that we have allocated. */
161 Vector<Boolean *> allBooleans;
163 /** This is a vector of all set structs that we have allocated. */
164 Vector<Set *> allSets;
166 /** This is a vector of all element structs that we have allocated. */
167 Vector<Element *> allElements;
169 /** This is a vector of all predicate structs that we have allocated. */
170 Vector<Predicate *> allPredicates;
172 /** This is a vector of all table structs that we have allocated. */
173 Vector<Table *> allTables;
175 /** This is a vector of all order structs that we have allocated. */
176 Vector<Order *> allOrders;
178 /** This is a vector of all function structs that we have allocated. */
179 Vector<Function *> allFunctions;
184 /** These two tables are used for deduplicating entries. */
185 BooleanMatchMap boolMap;
186 ElementMatchMap elemMap;
188 SATEncoder *satEncoder;
191 Transformer* transformer;
192 long long elapsedTime;