Fixing bugs ...
authorHamed Gorjiara <hgorjiar@uci.edu>
Fri, 20 Oct 2017 22:41:55 +0000 (15:41 -0700)
committerHamed Gorjiara <hgorjiar@uci.edu>
Fri, 20 Oct 2017 22:41:55 +0000 (15:41 -0700)
src/AST/element.h
src/AST/set.cc
src/Serialize/deserializer.cc
src/csolver.cc

index c643603..1b79084 100644 (file)
@@ -26,6 +26,7 @@ public:
 class ElementSet : public Element {
 public:
        ElementSet(ASTNodeType type, Set *s);
+        virtual ~ElementSet(){}
        ElementSet(Set *s);
        virtual Element *clone(CSolver *solver, CloneMap *map);
        virtual void serialize(Serializer* serializer);
@@ -40,6 +41,7 @@ public:
 class ElementConst : public ElementSet {
 public:
        ElementConst(uint64_t value, Set *_set);
+        virtual ~ElementConst(){}
        uint64_t value;
        virtual void serialize(Serializer* serializer);
         virtual void print();
@@ -49,6 +51,7 @@ public:
 
 class ElementFunction : public Element {
 public:
+        virtual ~ElementFunction(){}
        ElementFunction(Function *function, Element **array, uint numArrays, BooleanEdge overflowstatus);
        Array<Element *> inputs;
        BooleanEdge overflowstatus;
index 25ccd05..5c07ac5 100644 (file)
@@ -131,16 +131,19 @@ void Set::serialize(Serializer* serializer){
        serializer->mywrite(&This, sizeof(Set*));
        serializer->mywrite(&type, sizeof(VarType));
        serializer->mywrite(&isRange, sizeof(bool));
-       serializer->mywrite(&low, sizeof(uint64_t));
-       serializer->mywrite(&high, sizeof(uint64_t));
-       bool isMutable = isMutableSet();
+        bool isMutable = isMutableSet();
        serializer->mywrite(&isMutable, sizeof(bool));
-       uint size = members->getSize();
-       serializer->mywrite(&size, sizeof(uint));
-       for(uint i=0; i<size; i++){
-               uint64_t mem = members->get(i);
-               serializer->mywrite(&mem, sizeof(uint64_t));
-       }
+        if(isRange){
+                serializer->mywrite(&low, sizeof(uint64_t));
+                serializer->mywrite(&high, sizeof(uint64_t));
+        }else {
+                uint size = members->getSize();
+                serializer->mywrite(&size, sizeof(uint));
+                for(uint i=0; i<size; i++){
+                        uint64_t mem = members->get(i);
+                        serializer->mywrite(&mem, sizeof(uint64_t));
+                }
+        }
 }
 
 void Set::print(){
index fc4cd7b..bffb901 100644 (file)
@@ -145,33 +145,37 @@ void Deserializer::deserializeSet(){
        myread(&type, sizeof(VarType));
        bool isRange;
        myread(&isRange, sizeof(bool));
-       uint64_t low;
-       myread(&low, sizeof(uint64_t));
-       uint64_t high;
-       myread(&high, sizeof(uint64_t));
-       bool isMutable;
+        bool isMutable;
        myread(&isMutable, sizeof(bool));
-       Set *set;
-       if(isMutable){
-               set = new MutableSet(type);
-       }
-       uint size;
-       myread(&size, sizeof(uint));
-       Vector<uint64_t> members;
-       for(uint i=0; i<size; i++){
-               uint64_t mem;
-               myread(&mem, sizeof(uint64_t));
-               if(isMutable) {
-                       ((MutableSet*) set)->addElementMSet(mem);
-               }else {
-                       members.push(mem);
-               }
-       }
-       if(!isMutable){
-               set = isRange? solver->createRangeSet(type, low, high):
-                       solver->createSet(type, members.expose(), size);
-       }
-       map.put(s_ptr, set);
+        if(isRange){
+                uint64_t low;
+                myread(&low, sizeof(uint64_t));
+                uint64_t high;
+                myread(&high, sizeof(uint64_t));
+                map.put(s_ptr, new Set(type, low, high));
+        } else{
+                Set *set;
+                if(isMutable){
+                        set = new MutableSet(type);
+                }
+                uint size;
+                myread(&size, sizeof(uint));
+                Vector<uint64_t> members;
+                for(uint i=0; i<size; i++){
+                        uint64_t mem;
+                        myread(&mem, sizeof(uint64_t));
+                        if(isMutable) {
+                                ((MutableSet*) set)->addElementMSet(mem);
+                        }else {
+                                members.push(mem);
+                        }
+                }
+                if(!isMutable){
+                        set = solver->createSet(type, members.expose(), size);
+                }
+                map.put(s_ptr, set);
+        }
+       
 }
 
 void Deserializer::deserializeBooleanLogic(){
index f1c39e0..4866887 100644 (file)
@@ -36,6 +36,7 @@ CSolver::CSolver() :
 /** This function tears down the solver and the entire AST */
 
 CSolver::~CSolver() {
+        this->serialize();
        uint size = allBooleans.getSize();
        for (uint i = 0; i < size; i++) {
                delete allBooleans.get(i);
@@ -48,7 +49,10 @@ CSolver::~CSolver() {
 
        size = allElements.getSize();
        for (uint i = 0; i < size; i++) {
-               delete allElements.get(i);
+                Element* el = allElements.get(i);
+                model_print("deleting ...%u", i);
+                ASSERT(el != NULL);
+               delete el;
        }
 
        size = allTables.getSize();
@@ -98,11 +102,11 @@ void CSolver::serialize() {
                }
                delete it;
        }
-       model_print("deserializing ...\n");
-       {
-               Deserializer deserializer("dump");
-               deserializer.deserialize();
-       }
+//     model_print("deserializing ...\n");
+//     {
+//             Deserializer deserializer("dump");
+//             deserializer.deserialize();
+//     }
        
 }
 
@@ -149,6 +153,7 @@ void CSolver::finalizeMutableSet(MutableSet* set){
 
 Element *CSolver::getElementVar(Set *set) {
        Element *element = new ElementSet(set);
+        model_println("%%%%ElementVar:%u", allElements.getSize());
        allElements.push(element);
        return element;
 }
@@ -165,6 +170,7 @@ Element *CSolver::getElementConst(VarType type, uint64_t value) {
        Element *e = elemMap.get(element);
        if (e == NULL) {
                allSets.push(set);
+                model_println("%%%%ElementConst:%u", allElements.getSize());
                allElements.push(element);
                elemMap.put(element, element);
                return element;
@@ -180,6 +186,7 @@ Element *CSolver::applyFunction(Function *function, Element **array, uint numArr
        Element *e = elemMap.get(element);
        if (e == NULL) {
                element->updateParents();
+                model_println("%%%%ElementFunction:%u", allElements.getSize());
                allElements.push(element);
                elemMap.put(element, element);
                return element;