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 Element *createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange);
22 /** This function creates a mutable set. */
24 MutableSet *createMutableSet(VarType type);
26 /** This function adds a new item to a set. */
28 void addItem(MutableSet *set, uint64_t element);
30 /** This function adds a new unique item to the set and returns it.
31 This function cannot be used in conjunction with manually adding
34 uint64_t createUniqueItem(MutableSet *set);
36 /** This function creates an element variable over a set. */
38 Element *getElementVar(Set *set);
40 /** This function creates an element constrant. */
41 Element *getElementConst(VarType type, uint64_t value);
43 Boolean *getBooleanTrue();
45 Boolean *getBooleanFalse();
47 /** This function creates a boolean variable. */
49 Boolean *getBooleanVar(VarType type);
51 /** This function creates a function operator. */
53 Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
54 OverFlowBehavior overflowbehavior);
56 /** This function creates a predicate operator. */
58 Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
60 Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
62 /** This function creates an empty instance table.*/
64 Table *createTable(Set **domains, uint numDomain, Set *range);
66 Table *createTableForPredicate(Set **domains, uint numDomain);
67 /** This function adds an input output relation to a table. */
69 void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
71 /** This function converts a completed table into a function. */
73 Function *completeTable(Table *, UndefinedBehavior behavior);
75 /** This function applies a function to the Elements in its input. */
77 Element *applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus);
79 /** This function applies a predicate to the Elements in its input. */
81 Boolean *applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus);
83 Boolean *applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
85 /** This function applies a logical operation to the Booleans in its input. */
87 Boolean *applyLogicalOperation(LogicOp op, Boolean **array, uint asize);
89 /** This function applies a logical operation to the Booleans in its input. */
91 Boolean *applyLogicalOperation(LogicOp op, Boolean * arg1, Boolean * arg2);
93 /** This function applies a logical operation to the Booleans in its input. */
95 Boolean *applyLogicalOperation(LogicOp op, Boolean *arg);
97 /** This function adds a boolean constraint to the set of constraints
100 void addConstraint(Boolean *constraint);
102 /** This function instantiates an order of type type over the set set. */
103 Order *createOrder(OrderType type, Set *set);
105 /** This function instantiates a boolean on two items in an order. */
106 Boolean *orderConstraint(Order *order, uint64_t first, uint64_t second);
108 /** When everything is done, the client calls this function and then csolver starts to encode*/
111 /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
112 uint64_t getElementValue(Element *element);
114 /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
115 bool getBooleanValue(Boolean *boolean);
117 HappenedBefore getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
119 bool isTrue(Boolean *b);
120 bool isFalse(Boolean *b);
122 void setUnSAT() { unsat = true; }
124 bool isUnSAT() { return unsat; }
126 Vector<Order *> *getOrders() { return &allOrders;}
128 Tuner *getTuner() { return tuner; }
129 Transformer* getTransformer() {return transformer;}
131 SetIteratorBoolean *getConstraints() { return constraints.iterator(); }
133 SATEncoder *getSATEncoder() {return satEncoder;}
135 void replaceBooleanWithTrue(Boolean *bexpr);
136 void replaceBooleanWithFalse(Boolean *bexpr);
137 void replaceBooleanWithBoolean(Boolean *oldb, Boolean *newb);
139 void autoTune(uint budget);
141 void setTransformer(Transformer * _transformer) { transformer = _transformer; }
142 void setTuner(Tuner * _tuner) { tuner = _tuner; }
143 long long getElapsedTime() { return elapsedTime; }
144 long long getEncodeTime();
145 long long getSolveTime();
150 void handleXORFalse(BooleanLogic *bexpr, Boolean *child);
151 void handleIMPLIESTrue(BooleanLogic *bexpr, Boolean *child);
152 void handleIMPLIESFalse(BooleanLogic *bexpr, Boolean *child);
153 void handleANDTrue(BooleanLogic *bexpr, Boolean *child);
154 void handleORFalse(BooleanLogic *bexpr, Boolean *child);
156 /** This is a vector of constraints that must be satisfied. */
157 HashsetBoolean constraints;
159 /** This is a vector of all boolean structs that we have allocated. */
160 Vector<Boolean *> allBooleans;
162 /** This is a vector of all set structs that we have allocated. */
163 Vector<Set *> allSets;
165 /** This is a vector of all element structs that we have allocated. */
166 Vector<Element *> allElements;
168 /** This is a vector of all predicate structs that we have allocated. */
169 Vector<Predicate *> allPredicates;
171 /** This is a vector of all table structs that we have allocated. */
172 Vector<Table *> allTables;
174 /** This is a vector of all order structs that we have allocated. */
175 Vector<Order *> allOrders;
177 /** This is a vector of all function structs that we have allocated. */
178 Vector<Function *> allFunctions;
183 /** These two tables are used for deduplicating entries. */
184 BooleanMatchMap boolMap;
185 ElementMatchMap elemMap;
187 SATEncoder *satEncoder;
190 Transformer* transformer;
191 long long elapsedTime;