X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=blobdiff_plain;f=src%2Fcsolver.c;h=5f330fd6112c70074522c17ac116739bf35746d6;hp=c9b06336d548e333e4655902266edab175be987d;hb=487b405f45bfc928a981a2b3613c08f26cf4a9e5;hpb=b373ca39ded747fb61eda999a28dc178a6bb5eaa diff --git a/src/csolver.c b/src/csolver.c index c9b0633..5f330fd 100644 --- a/src/csolver.c +++ b/src/csolver.c @@ -5,6 +5,8 @@ #include "boolean.h" #include "predicate.h" #include "order.h" +#include "table.h" +#include "function.h" CSolver * allocCSolver() { CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver)); @@ -12,52 +14,77 @@ CSolver * allocCSolver() { tmp->allBooleans=allocDefVectorBoolean(); tmp->allSets=allocDefVectorSet(); tmp->allElements=allocDefVectorElement(); + tmp->allPredicates = allocDefVectorPredicate(); + tmp->allTables = allocDefVectorTable(); + tmp->allOrders = allocDefVectorOrder(); + tmp->allFunctions = allocDefVectorFunction(); return tmp; } /** This function tears down the solver and the entire AST */ -void deleteSolver(CSolver *this) { - deleteVectorBoolean(this->constraints); +void deleteSolver(CSolver *This) { + deleteVectorBoolean(This->constraints); - uint size=getSizeVectorBoolean(this->allBooleans); + uint size=getSizeVectorBoolean(This->allBooleans); for(uint i=0;iallBooleans, i)); + deleteBoolean(getVectorBoolean(This->allBooleans, i)); } - - deleteVectorBoolean(this->allBooleans); + deleteVectorBoolean(This->allBooleans); - size=getSizeVectorSet(this->allSets); + size=getSizeVectorSet(This->allSets); for(uint i=0;iallSets, i)); + deleteSet(getVectorSet(This->allSets, i)); } + deleteVectorSet(This->allSets); - deleteVectorSet(this->allSets); + size=getSizeVectorElement(This->allElements); + for(uint i=0;iallElements, i)); + } + deleteVectorElement(This->allElements); + + size=getSizeVectorTable(This->allTables); + for(uint i=0;iallTables, i)); + } + deleteVectorTable(This->allTables); + + size=getSizeVectorPredicate(This->allPredicates); + for(uint i=0;iallPredicates, i)); + } + deleteVectorPredicate(This->allPredicates); - size=getSizeVectorElement(this->allElements); + size=getSizeVectorOrder(This->allOrders); for(uint i=0;iallElements, i)); + deleteOrder(getVectorOrder(This->allOrders, i)); } + deleteVectorOrder(This->allOrders); - deleteVectorElement(this->allElements); - ourfree(this); + size=getSizeVectorFunction(This->allFunctions); + for(uint i=0;iallFunctions, i)); + } + deleteVectorFunction(This->allFunctions); + ourfree(This); } -Set * createSet(CSolver * this, VarType type, uint64_t * elements, uint numelements) { +Set * createSet(CSolver * This, VarType type, uint64_t * elements, uint numelements) { Set * set=allocSet(type, elements, numelements); - pushVectorSet(this->allSets, set); + pushVectorSet(This->allSets, set); return set; } -Set * createRangeSet(CSolver * this, VarType type, uint64_t lowrange, uint64_t highrange) { +Set * createRangeSet(CSolver * This, VarType type, uint64_t lowrange, uint64_t highrange) { Set * set=allocSetRange(type, lowrange, highrange); - pushVectorSet(this->allSets, set); + pushVectorSet(This->allSets, set); return set; } -MutableSet * createMutableSet(CSolver * this, VarType type) { +MutableSet * createMutableSet(CSolver * This, VarType type) { MutableSet * set=allocMutableSet(type); - pushVectorSet(this->allSets, set); + pushVectorSet(This->allSets, set); return set; } @@ -71,64 +98,74 @@ uint64_t createUniqueItem(CSolver *solver, MutableSet * set) { return element; } -Element * getElementVar(CSolver *this, Set * set) { - Element * element=allocElement(set); - pushVectorElement(this->allElements, element); +Element * getElementVar(CSolver *This, Set * set) { + Element * element=allocElementSet(set); + pushVectorElement(This->allElements, element); return element; } Boolean * getBooleanVar(CSolver *solver, VarType type) { - Boolean* boolean= allocBoolean(type); - pushVectorBoolean(solver->allBooleans, boolean); - return boolean; + Boolean* boolean= allocBoolean(type); + pushVectorBoolean(solver->allBooleans, boolean); + return boolean; } -Function * createFunctionOperator(CSolver *solver, enum ArithOp op, Set ** domain, uint numDomain, Set * range, - enum OverFlowBehavior overflowbehavior, Boolean * overflowstatus) { - return NULL; +Function * createFunctionOperator(CSolver *solver, ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior) { + Function* function = allocFunctionOperator(op, domain, numDomain, range, overflowbehavior); + pushVectorFunction(solver->allFunctions, function); + return function; } -//Function * createFunctionOperatorPure(CSolver *solver, enum ArithOp op) { -// return NULL; -//} - -Predicate * createPredicateOperator(CSolver *solver, enum CompOp op, Set ** domain, uint numDomain) { - return allocPredicate(op, domain,numDomain); +Predicate * createPredicateOperator(CSolver *solver, CompOp op, Set ** domain, uint numDomain) { + Predicate* predicate= allocPredicate(op, domain,numDomain); + pushVectorPredicate(solver->allPredicates, predicate); + return predicate; } Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range) { - return NULL; + Table* table= allocTable(domains,numDomain,range); + pushVectorTable(solver->allTables, table); + return table; } -void addTableEntry(CSolver *solver, uint64_t* inputs, uint inputSize, uint64_t result) { +void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result) { + addNewTableEntry(table,inputs, inputSize,result); } Function * completeTable(CSolver *solver, Table * table) { - return NULL; + Function* function = allocFunctionTable(table); + pushVectorFunction(solver->allFunctions,function); + return function; } -Element * applyFunction(CSolver *solver, Function * function, Element ** array) { - return NULL; +Element * applyFunction(CSolver *solver, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus) { + Element* element= allocElementFunction(function,array,numArrays,overflowstatus); + pushVectorElement(solver->allElements, element); + return element; } -Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs) { - return NULL; +Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs, uint numInputs) { + Boolean* boolean= allocBooleanPredicate(predicate, inputs, numInputs); + pushVectorBoolean(solver->allBooleans, boolean); + return boolean; } -Boolean * applyLogicalOperation(CSolver *solver, enum LogicOp op, Boolean ** array) { - return NULL; +Boolean * applyLogicalOperation(CSolver *solver, LogicOp op, Boolean ** array, uint asize) { + return allocBooleanLogicArray(solver, op, array, asize); } -void addBoolean(CSolver *this, Boolean * constraint) { - pushVectorBoolean(this->constraints, constraint); +void addBoolean(CSolver *This, Boolean * constraint) { + pushVectorBoolean(This->constraints, constraint); } -Order * createOrder(CSolver *solver, enum OrderType type, Set * set) { - return allocOrder(type, set); +Order * createOrder(CSolver *solver, OrderType type, Set * set) { + Order* order = allocOrder(type, set); + pushVectorOrder(solver->allOrders, order); + return order; } Boolean * orderConstraint(CSolver *solver, Order * order, uint64_t first, uint64_t second) { - Boolean* constraint = allocBooleanOrder(order, first, second); - pushVectorBoolean(solver->allBooleans,constraint); - return constraint; + Boolean* constraint = allocBooleanOrder(order, first, second); + pushVectorBoolean(solver->allBooleans,constraint); + return constraint; }