commit after resolving conflict
[satune.git] / src / csolver.c
1 #include "csolver.h"
2 #include "set.h"
3 #include "mutableset.h"
4 #include "element.h"
5 #include "boolean.h"
6 #include "predicate.h"
7 #include "order.h"
8 #include "table.h"
9 #include "function.h"
10
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();
21         return tmp;
22 }
23
24 /** This function tears down the solver and the entire AST */
25
26 void deleteSolver(CSolver *This) {
27         deleteVectorBoolean(This->constraints);
28
29         uint size=getSizeVectorBoolean(This->allBooleans);
30         for(uint i=0;i<size;i++) {
31                 deleteBoolean(getVectorBoolean(This->allBooleans, i));
32         }
33
34         deleteVectorBoolean(This->allBooleans);
35
36         size=getSizeVectorSet(This->allSets);
37         for(uint i=0;i<size;i++) {
38                 deleteSet(getVectorSet(This->allSets, i));
39         }
40
41         deleteVectorSet(This->allSets);
42
43         size=getSizeVectorElement(This->allElements);
44         for(uint i=0;i<size;i++) {
45                 deleteElement(getVectorElement(This->allElements, i));
46         }
47         size=getSizeVectorTable(This->allTables);
48         for(uint i=0;i<size;i++) {
49                 deleteTable(getVectorTable(This->allTables, i));
50         }
51         size=getSizeVectorPredicate(This->allPredicates);
52         for(uint i=0;i<size;i++) {
53                 deletePredicate(getVectorPredicate(This->allPredicates, i));
54         }
55         size=getSizeVectorOrder(This->allOrders);
56         for(uint i=0;i<size;i++) {
57                 deleteOrder(getVectorOrder(This->allOrders, i));
58         }
59         deleteVectorOrder(This->allOrders);
60         size=getSizeVectorFunction(This->allFunctions);
61         for(uint i=0;i<size;i++) {
62                 deleteFunction(getVectorFunction(This->allFunctions, i));
63         }
64         deleteVectorOrder(This->allFunctions);
65         ourfree(This);
66 }
67
68 Set * createSet(CSolver * This, VarType type, uint64_t * elements, uint numelements) {
69         Set * set=allocSet(type, elements, numelements);
70         pushVectorSet(This->allSets, set);
71         return set;
72 }
73
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);
77         return set;
78 }
79
80 MutableSet * createMutableSet(CSolver * This, VarType type) {
81         MutableSet * set=allocMutableSet(type);
82         pushVectorSet(This->allSets, set);
83         return set;
84 }
85
86 void addItem(CSolver *solver, MutableSet * set, uint64_t element) {
87         addElementMSet(set, element);
88 }
89
90 uint64_t createUniqueItem(CSolver *solver, MutableSet * set) {
91         uint64_t element=set->low++;
92         addElementMSet(set, element);
93         return element;
94 }
95
96 Element * getElementVar(CSolver *This, Set * set) {
97         Element * element=allocElement(set);
98         pushVectorElement(This->allElements, element);
99         return element;
100 }
101
102 Boolean * getBooleanVar(CSolver *solver, VarType type) {
103         Boolean* boolean= allocBoolean(type);
104         pushVectorBoolean(solver->allBooleans, boolean);
105         return boolean;
106 }
107
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);
111     return function;
112 }
113
114 Predicate * createPredicateOperator(CSolver *solver, CompOp op, Set ** domain, uint numDomain) {
115         Predicate* predicate= allocPredicate(op, domain,numDomain);
116         pushVectorPredicate(solver->allPredicates, predicate);
117         return predicate;
118 }
119
120 Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range) {
121         Table* table= allocTable(domains,numDomain,range);
122         pushVectorTable(solver->allTables, table);
123         return table;
124 }
125
126 void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result) {
127     addNewTableEntry(table,inputs, inputSize,result);
128 }
129
130 Function * completeTable(CSolver *solver, Table * table) {
131     Function* function = allocFunctionTable(table);
132     pushVectorFunction(solver->allFunctions,function);
133     return function;
134 }
135
136 Element * applyFunction(CSolver *solver, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus) {
137         return NULL;
138 }
139
140 Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs, uint numInputs) {
141         return NULL;
142 }
143
144 Boolean * applyLogicalOperation(CSolver *solver, LogicOp op, Boolean ** array) {
145         return NULL;
146 }
147
148 void addBoolean(CSolver *This, Boolean * constraint) {
149         pushVectorBoolean(This->constraints, constraint);
150 }
151
152 Order * createOrder(CSolver *solver, OrderType type, Set * set) {
153         Order* order = allocOrder(type, set);
154         pushVectorOrder(solver->allOrders, order);
155         return order;
156 }
157
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);
161         return constraint;
162 }