3 #include "mutableset.h"
11 CSolver * allocCSolver() {
12 CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver));
13 tmp->constraints=allocDefVectorBoolean();
14 tmp->allBooleans=allocDefVectorBoolean();
15 tmp->allSets=allocDefVectorSet();
16 tmp->allElements=allocDefVectorElement();
17 tmp->allPredicates = allocDefVectorPredicate();
18 tmp->allTables = allocDefVectorTable();
19 tmp->allOrders = allocDefVectorOrder();
20 tmp->allFunctions = allocDefVectorFunction();
24 /** This function tears down the solver and the entire AST */
26 void deleteSolver(CSolver *This) {
27 deleteVectorBoolean(This->constraints);
29 uint size=getSizeVectorBoolean(This->allBooleans);
30 for(uint i=0;i<size;i++) {
31 deleteBoolean(getVectorBoolean(This->allBooleans, i));
34 deleteVectorBoolean(This->allBooleans);
36 size=getSizeVectorSet(This->allSets);
37 for(uint i=0;i<size;i++) {
38 deleteSet(getVectorSet(This->allSets, i));
41 deleteVectorSet(This->allSets);
43 size=getSizeVectorElement(This->allElements);
44 for(uint i=0;i<size;i++) {
45 deleteElement(getVectorElement(This->allElements, i));
47 size=getSizeVectorTable(This->allTables);
48 for(uint i=0;i<size;i++) {
49 deleteTable(getVectorTable(This->allTables, i));
51 size=getSizeVectorPredicate(This->allPredicates);
52 for(uint i=0;i<size;i++) {
53 deletePredicate(getVectorPredicate(This->allPredicates, i));
55 size=getSizeVectorOrder(This->allOrders);
56 for(uint i=0;i<size;i++) {
57 deleteOrder(getVectorOrder(This->allOrders, i));
59 deleteVectorOrder(This->allOrders);
60 size=getSizeVectorFunction(This->allFunctions);
61 for(uint i=0;i<size;i++) {
62 deleteFunction(getVectorFunction(This->allFunctions, i));
64 deleteVectorOrder(This->allFunctions);
68 Set * createSet(CSolver * This, VarType type, uint64_t * elements, uint numelements) {
69 Set * set=allocSet(type, elements, numelements);
70 pushVectorSet(This->allSets, set);
74 Set * createRangeSet(CSolver * This, VarType type, uint64_t lowrange, uint64_t highrange) {
75 Set * set=allocSetRange(type, lowrange, highrange);
76 pushVectorSet(This->allSets, set);
80 MutableSet * createMutableSet(CSolver * This, VarType type) {
81 MutableSet * set=allocMutableSet(type);
82 pushVectorSet(This->allSets, set);
86 void addItem(CSolver *solver, MutableSet * set, uint64_t element) {
87 addElementMSet(set, element);
90 uint64_t createUniqueItem(CSolver *solver, MutableSet * set) {
91 uint64_t element=set->low++;
92 addElementMSet(set, element);
96 Element * getElementVar(CSolver *This, Set * set) {
97 Element * element=allocElement(set);
98 pushVectorElement(This->allElements, element);
102 Boolean * getBooleanVar(CSolver *solver, VarType type) {
103 Boolean* boolean= allocBoolean(type);
104 pushVectorBoolean(solver->allBooleans, boolean);
108 Function * createFunctionOperator(CSolver *solver, ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior) {
109 Function* function = allocFunctionOperator(op, domain, numDomain, range, overflowbehavior);
110 pushVectorFunction(solver->allFunctions, function);
114 Predicate * createPredicateOperator(CSolver *solver, CompOp op, Set ** domain, uint numDomain) {
115 Predicate* predicate= allocPredicate(op, domain,numDomain);
116 pushVectorPredicate(solver->allPredicates, predicate);
120 Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range) {
121 Table* table= allocTable(domains,numDomain,range);
122 pushVectorTable(solver->allTables, table);
126 void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result) {
127 addNewTableEntry(table,inputs, inputSize,result);
130 Function * completeTable(CSolver *solver, Table * table) {
131 Function* function = allocFunctionTable(table);
132 pushVectorFunction(solver->allFunctions,function);
136 Element * applyFunction(CSolver *solver, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus) {
140 Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs, uint numInputs) {
144 Boolean * applyLogicalOperation(CSolver *solver, LogicOp op, Boolean ** array) {
148 void addBoolean(CSolver *This, Boolean * constraint) {
149 pushVectorBoolean(This->constraints, constraint);
152 Order * createOrder(CSolver *solver, OrderType type, Set * set) {
153 Order* order = allocOrder(type, set);
154 pushVectorOrder(solver->allOrders, order);
158 Boolean * orderConstraint(CSolver *solver, Order * order, uint64_t first, uint64_t second) {
159 Boolean* constraint = allocBooleanOrder(order, first, second);
160 pushVectorBoolean(solver->allBooleans,constraint);