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; }
116 Transformer* getTransformer() {return transformer;}
118 SetIteratorBoolean *getConstraints() { return constraints.iterator(); }
120 SATEncoder *getSATEncoder() {return satEncoder;}
122 void replaceBooleanWithTrue(Boolean *bexpr);
123 void replaceBooleanWithFalse(Boolean *bexpr);
124 void replaceBooleanWithBoolean(Boolean *oldb, Boolean *newb);
126 void autoTune(uint budget);
128 void setTransformer(Transformer * _transformer) { transformer = _transformer; }
129 void setTuner(Tuner * _tuner) { tuner = _tuner; }
130 long long getElapsedTime() { return elapsedTime; }
131 long long getEncodeTime();
132 long long getSolveTime();
137 void handleXORFalse(BooleanLogic *bexpr, Boolean *child);
138 void handleIMPLIESTrue(BooleanLogic *bexpr, Boolean *child);
139 void handleIMPLIESFalse(BooleanLogic *bexpr, Boolean *child);
140 void handleANDTrue(BooleanLogic *bexpr, Boolean *child);
141 void handleORFalse(BooleanLogic *bexpr, Boolean *child);
143 /** This is a vector of constraints that must be satisfied. */
144 HashsetBoolean constraints;
146 /** This is a vector of all boolean structs that we have allocated. */
147 Vector<Boolean *> allBooleans;
149 /** This is a vector of all set structs that we have allocated. */
150 Vector<Set *> allSets;
152 /** This is a vector of all element structs that we have allocated. */
153 Vector<Element *> allElements;
155 /** This is a vector of all predicate structs that we have allocated. */
156 Vector<Predicate *> allPredicates;
158 /** This is a vector of all table structs that we have allocated. */
159 Vector<Table *> allTables;
161 /** This is a vector of all order structs that we have allocated. */
162 Vector<Order *> allOrders;
164 /** This is a vector of all function structs that we have allocated. */
165 Vector<Function *> allFunctions;
170 /** These two tables are used for deduplicating entries. */
171 BooleanMatchMap boolMap;
172 ElementMatchMap elemMap;
174 SATEncoder *satEncoder;
177 Transformer* transformer;
178 long long elapsedTime;