5 #include "corestructs.h"
13 /** This function creates a set containing the elements passed in the array. */
14 Set *createSet(VarType type, uint64_t *elements, uint num);
16 /** This function creates a set from lowrange to highrange (inclusive). */
18 Set *createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange);
20 /** This function creates a mutable set. */
22 MutableSet *createMutableSet(VarType type);
24 /** This function adds a new item to a set. */
26 void addItem(MutableSet *set, uint64_t element);
28 /** This function adds a new unique item to the set and returns it.
29 This function cannot be used in conjunction with manually adding
32 uint64_t createUniqueItem(MutableSet *set);
34 /** This function creates an element variable over a set. */
36 Element *getElementVar(Set *set);
38 /** This function creates an element constrant. */
39 Element *getElementConst(VarType type, uint64_t value);
41 Boolean *getBooleanTrue();
43 Boolean *getBooleanFalse();
45 /** This function creates a boolean variable. */
47 Boolean *getBooleanVar(VarType type);
49 /** This function creates a function operator. */
51 Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
52 OverFlowBehavior overflowbehavior);
54 /** This function creates a predicate operator. */
56 Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
58 Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
60 /** This function creates an empty instance table.*/
62 Table *createTable(Set **domains, uint numDomain, Set *range);
64 Table *createTableForPredicate(Set **domains, uint numDomain);
65 /** This function adds an input output relation to a table. */
67 void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
69 /** This function converts a completed table into a function. */
71 Function *completeTable(Table *, UndefinedBehavior behavior);
73 /** This function applies a function to the Elements in its input. */
75 Element *applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus);
77 /** This function applies a predicate to the Elements in its input. */
79 Boolean *applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus);
81 Boolean *applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
83 /** This function applies a logical operation to the Booleans in its input. */
85 Boolean *applyLogicalOperation(LogicOp op, Boolean **array, uint asize);
87 /** This function adds a boolean constraint to the set of constraints
90 void addConstraint(Boolean *constraint);
92 /** This function instantiates an order of type type over the set set. */
93 Order *createOrder(OrderType type, Set *set);
95 /** This function instantiates a boolean on two items in an order. */
96 Boolean *orderConstraint(Order *order, uint64_t first, uint64_t second);
98 /** When everything is done, the client calls this function and then csolver starts to encode*/
101 /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
102 uint64_t getElementValue(Element *element);
104 /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
105 bool getBooleanValue(Boolean *boolean);
107 HappenedBefore getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
109 void setUnSAT() { unsat = true; }
111 bool isUnSAT() { return unsat; }
113 Vector<Order *> *getOrders() { return &allOrders;}
115 Tuner *getTuner() { return tuner; }
117 SetIteratorBoolean *getConstraints() { return constraints.iterator(); }
119 SATEncoder *getSATEncoder() {return satEncoder;}
121 void replaceBooleanWithTrue(Boolean *bexpr);
122 void replaceBooleanWithFalse(Boolean *bexpr);
123 void replaceBooleanWithBoolean(Boolean *oldb, Boolean *newb);
125 void autoTune(uint budget);
127 void setTuner(Tuner * _tuner) { tuner = _tuner; }
128 long long getElapsedTime() { return elapsedTime; }
129 long long getEncodeTime();
130 long long getSolveTime();
135 void handleXORFalse(BooleanLogic *bexpr, Boolean *child);
136 void handleIMPLIESTrue(BooleanLogic *bexpr, Boolean *child);
137 void handleIMPLIESFalse(BooleanLogic *bexpr, Boolean *child);
138 void handleANDTrue(BooleanLogic *bexpr, Boolean *child);
139 void handleORFalse(BooleanLogic *bexpr, Boolean *child);
141 /** This is a vector of constraints that must be satisfied. */
142 HashsetBoolean constraints;
144 /** This is a vector of all boolean structs that we have allocated. */
145 Vector<Boolean *> allBooleans;
147 /** This is a vector of all set structs that we have allocated. */
148 Vector<Set *> allSets;
150 /** This is a vector of all element structs that we have allocated. */
151 Vector<Element *> allElements;
153 /** This is a vector of all predicate structs that we have allocated. */
154 Vector<Predicate *> allPredicates;
156 /** This is a vector of all table structs that we have allocated. */
157 Vector<Table *> allTables;
159 /** This is a vector of all order structs that we have allocated. */
160 Vector<Order *> allOrders;
162 /** This is a vector of all function structs that we have allocated. */
163 Vector<Function *> allFunctions;
168 /** These two tables are used for deduplicating entries. */
169 BooleanMatchMap boolMap;
170 ElementMatchMap elemMap;
172 SATEncoder *satEncoder;
176 long long elapsedTime;