5 #include "corestructs.h"
7 #include "solver_interface.h"
15 /** This function creates a set containing the elements passed in the array. */
16 Set *createSet(VarType type, uint64_t *elements, uint num);
18 /** This function creates a set from lowrange to highrange (inclusive). */
20 Set *createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange);
22 bool itemExistInSet(Set *set, uint64_t item);
24 VarType getSetVarType(Set *set);
26 Element *createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange);
28 /** This function creates a mutable set.
29 * Note: You should use addItem for adding new item to Mutable sets, and
30 * at the end, you should call finalizeMutableSet!
33 MutableSet *createMutableSet(VarType type);
35 /** This function adds a new item to a set. */
37 //Deprecating this unless we need it...
38 void addItem(MutableSet *set, uint64_t element);
40 /** This function adds a new unique item to the set and returns it.
41 This function cannot be used in conjunction with manually adding
44 uint64_t createUniqueItem(MutableSet *set);
47 * Freeze and finalize the mutableSet ...
49 void finalizeMutableSet(MutableSet *set);
51 /** This function creates an element variable over a set. */
53 Element *getElementVar(Set *set);
55 /** This function creates an element constrant. */
56 Element *getElementConst(VarType type, uint64_t value);
58 Set *getElementRange (Element *element);
60 void mustHaveValue(Element *element);
62 BooleanEdge getBooleanTrue();
64 BooleanEdge getBooleanFalse();
66 /** This function creates a boolean variable. */
68 BooleanEdge getBooleanVar(VarType type);
70 /** This function creates a function operator. */
72 Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
73 OverFlowBehavior overflowbehavior);
75 /** This function creates a predicate operator. */
77 Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
79 Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
81 /** This function creates an empty instance table.*/
83 Table *createTable(Set **domains, uint numDomain, Set *range);
85 Table *createTableForPredicate(Set **domains, uint numDomain);
86 /** This function adds an input output relation to a table. */
88 void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
90 /** This function converts a completed table into a function. */
92 Function *completeTable(Table *, UndefinedBehavior behavior);
94 /** This function applies a function to the Elements in its input. */
96 Element *applyFunction(Function *function, Element **array, uint numArrays, BooleanEdge overflowstatus);
98 /** This function applies a predicate to the Elements in its input. */
100 BooleanEdge applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, BooleanEdge undefinedStatus);
102 BooleanEdge applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
104 /** This function applies a logical operation to the Booleans in its input. */
106 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
108 /** This function applies a logical operation to the Booleans in its input. */
110 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg1, BooleanEdge arg2);
112 /** This function applies a logical operation to the Booleans in its input. */
114 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg);
116 /** This function adds a boolean constraint to the set of constraints
119 void addConstraint(BooleanEdge constraint);
121 /** This function instantiates an order of type type over the set set. */
122 Order *createOrder(OrderType type, Set *set);
124 /** This function instantiates a boolean on two items in an order. */
125 BooleanEdge orderConstraint(Order *order, uint64_t first, uint64_t second);
127 /** When everything is done, the client calls this function and then csolver starts to encode*/
130 /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
131 uint64_t getElementValue(Element *element);
133 /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
134 bool getBooleanValue(BooleanEdge boolean);
136 bool getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
138 bool isTrue(BooleanEdge b);
139 bool isFalse(BooleanEdge b);
141 void setUnSAT() { model_print("Setting UNSAT %%%%%%\n"); unsat = true; }
142 bool isUnSAT() { return unsat; }
144 void printConstraint(BooleanEdge boolean);
145 void printConstraints();
147 Vector<Order *> *getOrders() { return &allOrders;}
148 HashsetOrder *getActiveOrders() { return &activeOrders;}
150 Tuner *getTuner() { return tuner; }
152 SetIteratorBooleanEdge *getConstraints() { return constraints.iterator(); }
154 SATEncoder *getSATEncoder() {return satEncoder;}
156 void replaceBooleanWithTrue(BooleanEdge bexpr);
157 void replaceBooleanWithTrueNoRemove(BooleanEdge bexpr);
158 void replaceBooleanWithFalseNoRemove(BooleanEdge bexpr);
159 void replaceBooleanWithFalse(BooleanEdge bexpr);
160 void replaceBooleanWithBoolean(BooleanEdge oldb, BooleanEdge newb);
162 // Set* addItemsToRange(Element* element, uint num, ...);
164 static CSolver *deserialize(const char *file);
165 void autoTune(uint budget);
166 void inferFixedOrders();
167 void inferFixedOrder(Order *order);
170 void setTuner(Tuner *_tuner) { tuner = _tuner; }
171 long long getElapsedTime() { return elapsedTime; }
172 long long getEncodeTime();
173 long long getSolveTime();
178 void handleIFFTrue(BooleanLogic *bexpr, BooleanEdge child);
179 void handleANDTrue(BooleanLogic *bexpr, BooleanEdge child);
181 //These two functions are helpers if the client has a pointer to a
182 //Boolean object that we have since replaced
183 BooleanEdge rewriteLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
184 BooleanEdge doRewrite(BooleanEdge b);
185 /** This is a vector of constraints that must be satisfied. */
186 HashsetBooleanEdge constraints;
188 /** This is a vector of all boolean structs that we have allocated. */
189 Vector<Boolean *> allBooleans;
191 /** This is a vector of all set structs that we have allocated. */
192 Vector<Set *> allSets;
194 /** This is a vector of all element structs that we have allocated. */
195 Vector<Element *> allElements;
197 /** This is a vector of all predicate structs that we have allocated. */
198 Vector<Predicate *> allPredicates;
200 /** This is a vector of all table structs that we have allocated. */
201 Vector<Table *> allTables;
203 /** This is a vector of all order structs that we have allocated. */
204 Vector<Order *> allOrders;
206 HashsetOrder activeOrders;
208 /** This is a vector of all function structs that we have allocated. */
209 Vector<Function *> allFunctions;
211 BooleanEdge boolTrue;
212 BooleanEdge boolFalse;
214 /** These two tables are used for deduplicating entries. */
215 BooleanMatchMap boolMap;
216 ElementMatchMap elemMap;
218 SATEncoder *satEncoder;
221 long long elapsedTime;