From b373ca39ded747fb61eda999a28dc178a6bb5eaa Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 16 Jun 2017 11:35:45 -0700 Subject: [PATCH] Fix freelist management --- src/AST/boolean.c | 6 ++++- src/AST/boolean.h | 2 ++ src/Makefile | 1 + src/csolver.c | 37 ++++++++++++++++++------------ src/csolver.h | 57 +++++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 84 insertions(+), 19 deletions(-) diff --git a/src/AST/boolean.c b/src/AST/boolean.c index 63df873..7373bfc 100644 --- a/src/AST/boolean.c +++ b/src/AST/boolean.c @@ -9,9 +9,13 @@ Boolean* allocBoolean(VarType t){ Boolean* allocBooleanOrder(Order* order,uint64_t first, uint64_t second){ Boolean* tmp = (Boolean*) ourmalloc(sizeof (Boolean)); - tmp ->btype= _ORDER; + tmp->btype= _ORDER; tmp->order = order; tmp->first=first; tmp->second=second; return tmp; } + +void deleteBoolean(Boolean * this) { + ourfree(this); +} diff --git a/src/AST/boolean.h b/src/AST/boolean.h index fcd4751..f1d2127 100644 --- a/src/AST/boolean.h +++ b/src/AST/boolean.h @@ -13,4 +13,6 @@ struct Boolean { Boolean* allocBoolean(VarType t); Boolean* allocBooleanOrder(Order* order,uint64_t first, uint64_t second); +void deleteBoolean(Boolean * this); + #endif diff --git a/src/Makefile b/src/Makefile index cbf758b..431d55b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,6 +10,7 @@ HEADERS := $(wildcard *.h) $(wildcard AST/*.h) $(wildcard Collections/*.h) $(wil OBJECTS := $(CPP_SOURCES:%.cc=$(OBJ_DIR)/%.o) $(C_SOURCES:%.c=$(OBJ_DIR)/%.o) +CFLAGS := -Wall -g -O0 CFLAGS += -IAST -ICollections -IBackend -I. -IEncoders LDFLAGS := -ldl -lrt -rdynamic SHARED := -shared diff --git a/src/csolver.c b/src/csolver.c index 0f971b1..c9b0633 100644 --- a/src/csolver.c +++ b/src/csolver.c @@ -9,8 +9,9 @@ CSolver * allocCSolver() { CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver)); tmp->constraints=allocDefVectorBoolean(); - tmp->sets=allocDefVectorSet(); - tmp->elements=allocDefVectorElement(); + tmp->allBooleans=allocDefVectorBoolean(); + tmp->allSets=allocDefVectorSet(); + tmp->allElements=allocDefVectorElement(); return tmp; } @@ -18,37 +19,45 @@ CSolver * allocCSolver() { void deleteSolver(CSolver *this) { deleteVectorBoolean(this->constraints); - uint size=getSizeVectorSet(this->sets); + + uint size=getSizeVectorBoolean(this->allBooleans); + for(uint i=0;iallBooleans, i)); + } + + deleteVectorBoolean(this->allBooleans); + + size=getSizeVectorSet(this->allSets); for(uint i=0;isets, i)); + deleteSet(getVectorSet(this->allSets, i)); } - deleteVectorSet(this->sets); + deleteVectorSet(this->allSets); - size=getSizeVectorElement(this->elements); + size=getSizeVectorElement(this->allElements); for(uint i=0;ielements, i)); + deleteElement(getVectorElement(this->allElements, i)); } - deleteVectorElement(this->elements); + deleteVectorElement(this->allElements); ourfree(this); } Set * createSet(CSolver * this, VarType type, uint64_t * elements, uint numelements) { Set * set=allocSet(type, elements, numelements); - pushVectorSet(this->sets, set); + pushVectorSet(this->allSets, set); return set; } Set * createRangeSet(CSolver * this, VarType type, uint64_t lowrange, uint64_t highrange) { Set * set=allocSetRange(type, lowrange, highrange); - pushVectorSet(this->sets, set); + pushVectorSet(this->allSets, set); return set; } MutableSet * createMutableSet(CSolver * this, VarType type) { MutableSet * set=allocMutableSet(type); - pushVectorSet(this->sets, set); + pushVectorSet(this->allSets, set); return set; } @@ -64,13 +73,13 @@ uint64_t createUniqueItem(CSolver *solver, MutableSet * set) { Element * getElementVar(CSolver *this, Set * set) { Element * element=allocElement(set); - pushVectorElement(this->elements, element); + pushVectorElement(this->allElements, element); return element; } Boolean * getBooleanVar(CSolver *solver, VarType type) { Boolean* boolean= allocBoolean(type); - pushVectorBoolean(solver->constraints, boolean); + pushVectorBoolean(solver->allBooleans, boolean); return boolean; } @@ -120,6 +129,6 @@ Order * createOrder(CSolver *solver, enum OrderType type, Set * set) { Boolean * orderConstraint(CSolver *solver, Order * order, uint64_t first, uint64_t second) { Boolean* constraint = allocBooleanOrder(order, first, second); - pushVectorBoolean(solver->constraints,constraint); + pushVectorBoolean(solver->allBooleans,constraint); return constraint; } diff --git a/src/csolver.h b/src/csolver.h index 3972f6c..66c2d7e 100644 --- a/src/csolver.h +++ b/src/csolver.h @@ -6,37 +6,86 @@ struct CSolver { VectorBoolean * constraints; - VectorSet * sets; - VectorElement * elements; + VectorBoolean * allBooleans; + VectorSet * allSets; + VectorElement * allElements; }; +/** Create a new solver instance. */ + CSolver * allocCSolver(); + +/** This function creates a set containing the elements passed in the array. */ + Set * createSet(CSolver *, VarType type, uint64_t * elements, uint num); + +/** This function creates a set from lowrange to highrange (inclusive). */ + Set * createRangeSet(CSolver *, VarType type, uint64_t lowrange, uint64_t highrange); + +/** This function creates a mutable set. */ + MutableSet * createMutableSet(CSolver *, VarType type); +/** This function adds a new item to a set. */ + void addItem(CSolver *, MutableSet * set, uint64_t element); + +/** This function adds a new unique item to the set and returns it. + This function cannot be used in conjunction with manually adding + items to the set. */ + uint64_t createUniqueItem(CSolver *, MutableSet * set); +/** This function creates an element variable over a set. */ + Element * getElementVar(CSolver *, Set * set); + +/** This function creates a boolean variable. */ + Boolean * getBooleanVar(CSolver *, VarType type); +/** This function creates a function operator. */ + Function * createFunctionOperator(CSolver *solver, enum ArithOp op, Set ** domain, uint numDomain, Set * range, enum OverFlowBehavior overflowbehavior, Boolean * overflowstatus); -//Does Not Overflow -//Function * createFunctionOperatorPure(CSolver *, enum ArithOp op); + +/** This function creates a predicate operator. */ + Predicate * createPredicateOperator(CSolver *solver, enum CompOp op, Set ** domain, uint numDomain); +/** This function creates an empty instance table.*/ + Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range); + +/** This function adds an input output relation to a table. */ + void addTableEntry(CSolver *solver, uint64_t* inputs, uint inputSize, uint64_t result); + +/** This function converts a completed table into a function. */ + Function * completeTable(CSolver *, Table *); +/** This function applies a function to the Elements in its input. */ + Element * applyFunction(CSolver *, Function * function, Element ** array); + +/** This function applies a predicate to the Elements in its input. */ + Boolean * applyPredicate(CSolver *, Predicate * predicate, Element ** inputs); + +/** This function applies a logical operation to the Booleans in its input. */ + Boolean * applyLogicalOperation(CSolver *, enum LogicOp op, Boolean ** array); +/** This function adds a boolean constraint to the set of constraints + to be satisfied */ + void addBoolean(CSolver *, Boolean * constraint); +/** This function instantiates an order of type type over the set set. */ Order * createOrder(CSolver *, enum OrderType type, Set * set); + +/** This function instantiates a predicate on two items in an order. */ Boolean * orderConstraint(CSolver *, Order * order, uint64_t first, uint64_t second); #endif -- 2.34.1