From: Hamed Date: Tue, 20 Jun 2017 01:22:29 +0000 (-0700) Subject: commit after resolving conflict X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=commitdiff_plain;h=5249fbe7415e60c2e0411c64031d8a60aa7cd09f;hp=ba9db6c6d57e2140695a05dfc4040debf1542e57 commit after resolving conflict --- diff --git a/src/AST/function.c b/src/AST/function.c index d4b693e..c9d0717 100644 --- a/src/AST/function.c +++ b/src/AST/function.c @@ -1 +1,33 @@ #include "function.h" +#include "table.h" +#include "set.h" + + +Function* allocFunctionOperator( ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior){ + FunctionOperator* This = (FunctionOperator*) ourmalloc(sizeof(FunctionOperator)); + GETFUNCTIONTYPE(This)=OPERATORFUNC; + This->domains = allocVectorArraySet(numDomain, domain); + This->op=op; + This->overflowbehavior = overflowbehavior; + This->range=range; + return &This->base; +} + +Function* allocFunctionTable (Table* table){ + FunctionTable* This = (FunctionTable*) ourmalloc(sizeof(FunctionTable)); + GETFUNCTIONTYPE(This)=TABLEFUNC; + This->table = table; +} + +void deleteFunction(Function* This){ + switch( GETFUNCTIONTYPE(This)){ + case TABLEFUNC: + ourfree((FunctionTable*)This); + break; + case OPERATORFUNC: + ourfree((FunctionOperator*) This); + break; + default: + ASSERT(0); + } +} diff --git a/src/AST/function.h b/src/AST/function.h index 459f0b5..e22ec75 100644 --- a/src/AST/function.h +++ b/src/AST/function.h @@ -4,11 +4,29 @@ #include "mymemory.h" #include "ops.h" #include "structs.h" -struct Function { - ArithOp op; - VectorSet* domains; - Set * range; - OverFlowBehavior overflowbehavior; - Table* table; + + +#define GETFUNCTIONTYPE(o) (((Function*)o)->type) + +struct Function{ + FunctionType type; }; + +struct FunctionOperator { + Function base; + ArithOp op; + VectorSet* domains; + Set * range; + OverFlowBehavior overflowbehavior; +}; + +struct FunctionTable{ + Function base; + Table* table; +}; + +Function* allocFunctionOperator( ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior); +Function* allocFunctionTable (Table* table); +void deleteFunction(Function* This); + #endif diff --git a/src/AST/ops.h b/src/AST/ops.h index 3541808..63da885 100644 --- a/src/AST/ops.h +++ b/src/AST/ops.h @@ -25,4 +25,7 @@ typedef enum OverFlowBehavior OverFlowBehavior; enum BooleanType {ORDERCONST, BOOLEANVAR, LOGICOP, COMPARE}; typedef enum BooleanType BooleanType; + +enum FunctionType {TABLEFUNC, OPERATORFUNC}; +typedef enum FunctionType FunctionType; #endif diff --git a/src/AST/order.c b/src/AST/order.c index c18e039..1d7b1cf 100644 --- a/src/AST/order.c +++ b/src/AST/order.c @@ -1,6 +1,7 @@ #include "order.h" #include "structs.h" #include "set.h" +#include "boolean.h" Order* allocOrder(OrderType type, Set * set){ @@ -35,3 +36,12 @@ Boolean* getOrderConstraint(Order* order, uint64_t first, uint64_t second){ ASSERT(exist1 && exist2); */ } + +void deleteOrder(Order* order){ + uint size = getSizeVectorBoolean( order->constraints ); + for(uint i=0; iconstraints, i) ); + } + deleteSet( order->set); + ourfree(order); +} \ No newline at end of file diff --git a/src/AST/order.h b/src/AST/order.h index 727098b..0a589a5 100644 --- a/src/AST/order.h +++ b/src/AST/order.h @@ -12,4 +12,6 @@ struct Order { Order* allocOrder(OrderType type, Set * set); Boolean* getOrderConstraint(Order* order,uint64_t first, uint64_t second); +void deleteOrder(Order* order); + #endif diff --git a/src/AST/predicate.c b/src/AST/predicate.c index 09adb1b..d2a572d 100644 --- a/src/AST/predicate.c +++ b/src/AST/predicate.c @@ -10,3 +10,9 @@ Predicate* allocPredicate(CompOp op, Set ** domain, uint numDomain){ predicate->op=op; return predicate; } + +void deletePredicate(Predicate* predicate){ + deleteVectorSet(predicate->domains); + ourfree(predicate); +} + diff --git a/src/AST/predicate.h b/src/AST/predicate.h index 5d23764..513e386 100644 --- a/src/AST/predicate.h +++ b/src/AST/predicate.h @@ -12,4 +12,5 @@ struct Predicate { Predicate* allocPredicate(CompOp op, Set ** domain, uint numDomain); +void deletePredicate(Predicate* predicate); #endif diff --git a/src/AST/table.c b/src/AST/table.c index 9798d13..1f95f43 100644 --- a/src/AST/table.c +++ b/src/AST/table.c @@ -2,6 +2,7 @@ #include "common.h" #include "structs.h" #include "tableentry.h" +#include "set.h" Table * allocTable(Set **domains, uint numDomain, Set * range){ @@ -19,3 +20,17 @@ void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t r pushVectorTableEntry(table->entries, allocTableEntry(inputs, inputSize, result)); } +void deleteTable(Table* table){ + uint size = getSizeVectorSet(table->domains); + for(uint i=0; idomains,i)); + } + ourfree(table->domains); + ourfree(table->range); + size = getSizeVectorTableEntry(table->entries); + for(uint i=0; ientries, i)); + } + ourfree(table); +} + diff --git a/src/AST/table.h b/src/AST/table.h index 8027f88..21e3223 100644 --- a/src/AST/table.h +++ b/src/AST/table.h @@ -12,5 +12,5 @@ struct Table { Table * allocTable(Set **domains, uint numDomain, Set * range); void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t result); - +void deleteTable(Table* table); #endif diff --git a/src/AST/tableentry.c b/src/AST/tableentry.c index 216a2b5..b99d183 100644 --- a/src/AST/tableentry.c +++ b/src/AST/tableentry.c @@ -7,4 +7,8 @@ TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result){ te->inputs[i]=inputs[i]; } return te; +} + +void deleteTableEntry(TableEntry* tableEntry){ + ourfree(tableEntry); } \ No newline at end of file diff --git a/src/AST/tableentry.h b/src/AST/tableentry.h index f81932c..44ec39b 100644 --- a/src/AST/tableentry.h +++ b/src/AST/tableentry.h @@ -22,6 +22,7 @@ struct TableEntry{ }; TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result); +void deleteTableEntry(TableEntry* tableEntry); #endif /* TABLEENTRY_H */ diff --git a/src/Collections/structs.h b/src/Collections/structs.h index 3e08e97..bd473d5 100644 --- a/src/Collections/structs.h +++ b/src/Collections/structs.h @@ -14,6 +14,8 @@ VectorDef(Element, Element *, 4); VectorDef(TableEntry, TableEntry *, 4); VectorDef(Predicate, Predicate *, 4); VectorDef(Table, Table *, 4); +VectorDef(Order, Order *, 4); +VectorDef(Function, Function *, 4); inline unsigned int Ptr_hash_function(void * hash) { return (unsigned int)((uint64_t)hash >> 4); diff --git a/src/Encoders/functionencoding.c b/src/Encoders/functionencoding.c index 282912d..4520fa0 100644 --- a/src/Encoders/functionencoding.c +++ b/src/Encoders/functionencoding.c @@ -14,6 +14,6 @@ FunctionEncoding * allocPredicateEncoding(FunctionEncodingType type, Boolean *pr return This; } -void deleteFunctionEncoding(FunctionEncoding *This) { - ourfree(This); +void deleteFunctionEncoding(FunctionEncoding *fe) { + ourfree(fe); } diff --git a/src/Encoders/naiveelementencoder.c b/src/Encoders/naiveelementencoder.c index 4d52235..bb6e91a 100644 --- a/src/Encoders/naiveelementencoder.c +++ b/src/Encoders/naiveelementencoder.c @@ -3,7 +3,7 @@ #include "element.h" #include "set.h" #include "common.h" -#include "struct.h" +#include "structs.h" #include void baseBinaryIndexElementAssign(ElementEncoding *This) { diff --git a/src/classlist.h b/src/classlist.h index d232592..6de8bcf 100644 --- a/src/classlist.h +++ b/src/classlist.h @@ -41,6 +41,9 @@ typedef struct Set MutableSet; struct Element; typedef struct Element Element; +typedef struct FunctionOperator FunctionOperator; +typedef struct FunctionTable FunctionTable; + struct Function; typedef struct Function Function; diff --git a/src/csolver.c b/src/csolver.c index 7179222..62f4acd 100644 --- a/src/csolver.c +++ b/src/csolver.c @@ -6,6 +6,7 @@ #include "predicate.h" #include "order.h" #include "table.h" +#include "function.h" CSolver * allocCSolver() { CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver)); @@ -15,6 +16,8 @@ CSolver * allocCSolver() { tmp->allElements=allocDefVectorElement(); tmp->allPredicates = allocDefVectorPredicate(); tmp->allTables = allocDefVectorTable(); + tmp->allOrders = allocDefVectorOrder(); + tmp->allFunctions = allocDefVectorFunction(); return tmp; } @@ -41,8 +44,24 @@ void deleteSolver(CSolver *This) { for(uint i=0;iallElements, i)); } - //FIXME: Freeing alltables and allpredicates - deleteVectorElement(This->allElements); + size=getSizeVectorTable(This->allTables); + for(uint i=0;iallTables, i)); + } + size=getSizeVectorPredicate(This->allPredicates); + for(uint i=0;iallPredicates, i)); + } + size=getSizeVectorOrder(This->allOrders); + for(uint i=0;iallOrders, i)); + } + deleteVectorOrder(This->allOrders); + size=getSizeVectorFunction(This->allFunctions); + for(uint i=0;iallFunctions, i)); + } + deleteVectorOrder(This->allFunctions); ourfree(This); } @@ -86,9 +105,10 @@ Boolean * getBooleanVar(CSolver *solver, VarType type) { return boolean; } -Function * createFunctionOperator(CSolver *solver, ArithOp op, Set ** domain, uint numDomain, Set * range, - OverFlowBehavior overflowbehavior) { - 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; } Predicate * createPredicateOperator(CSolver *solver, CompOp op, Set ** domain, uint numDomain) { @@ -108,14 +128,16 @@ void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSi } 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, Boolean * overflowstatus) { +Element * applyFunction(CSolver *solver, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus) { return NULL; } -Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs) { +Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs, uint numInputs) { return NULL; } @@ -128,7 +150,9 @@ void addBoolean(CSolver *This, Boolean * constraint) { } Order * createOrder(CSolver *solver, OrderType type, Set * set) { - return allocOrder(type, set); + Order* order = allocOrder(type, set); + pushVectorOrder(solver->allOrders, order); + return order; } Boolean * orderConstraint(CSolver *solver, Order * order, uint64_t first, uint64_t second) { diff --git a/src/csolver.h b/src/csolver.h index d2e715c..93f19a4 100644 --- a/src/csolver.h +++ b/src/csolver.h @@ -16,8 +16,18 @@ struct CSolver { /** This is a vector of all element structs that we have allocated. */ VectorElement * allElements; + + /** This is a vector of all predicate structs that we have allocated. */ VectorPredicate * allPredicates; + + /** This is a vector of all table structs that we have allocated. */ VectorTable * allTables; + + /** This is a vector of all order structs that we have allocated. */ + VectorOrder * allOrders; + + /** This is a vector of all function structs that we have allocated. */ + VectorFunction* allFunctions; }; /** Create a new solver instance. */ @@ -77,11 +87,11 @@ Function * completeTable(CSolver *, Table *); /** This function applies a function to the Elements in its input. */ -Element * applyFunction(CSolver *, Function * function, Element ** array, Boolean * overflowstatus); +Element * applyFunction(CSolver *, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus); /** This function applies a predicate to the Elements in its input. */ -Boolean * applyPredicate(CSolver *, Predicate * predicate, Element ** inputs); +Boolean * applyPredicate(CSolver *, Predicate * predicate, Element ** inputs, uint numInputs); /** This function applies a logical operation to the Booleans in its input. */