completed serializer/deserializer
authorHamed <hamed.gorjiara@gmail.com>
Sun, 10 Sep 2017 06:59:38 +0000 (23:59 -0700)
committerHamed <hamed.gorjiara@gmail.com>
Sun, 10 Sep 2017 06:59:38 +0000 (23:59 -0700)
27 files changed:
src/AST/astops.h
src/AST/boolean.cc
src/AST/boolean.h
src/AST/element.cc
src/AST/element.h
src/AST/function.cc
src/AST/function.h
src/AST/order.h
src/AST/predicate.cc
src/AST/predicate.h
src/AST/set.h
src/AST/table.cc
src/AST/table.h
src/Serialize/deserializer.cc
src/Serialize/deserializer.h
src/Serialize/serializable.h [deleted file]
src/Serialize/serializer.cc
src/Serialize/serializer.h
src/Test/buildconstraintstest.cc
src/Test/elemequalsattest.cc
src/Test/elemequalunsattest.cc
src/Test/funcencodingtest.cc
src/Test/logicopstest.cc
src/Test/ltelemconsttest.cc
src/Test/ordergraphtest.cc
src/Test/tablefuncencodetest.cc
src/Test/tablepredicencodetest.cc

index c3244fb..f26326f 100644 (file)
@@ -7,7 +7,8 @@ typedef enum FunctionType FunctionType;
 enum PredicateType {TABLEPRED, OPERATORPRED};
 typedef enum PredicateType PredicateType;
 
-enum ASTNodeType {ORDERCONST, BOOLEANVAR, LOGICOP, PREDICATEOP, BOOLCONST, ELEMSET, ELEMFUNCRETURN, ELEMCONST, BOOLEANEDGE, ORDERTYPE, SETTYPE};
+enum ASTNodeType {ORDERCONST, BOOLEANVAR, LOGICOP, PREDICATEOP, BOOLCONST, ELEMSET, ELEMFUNCRETURN, ELEMCONST,
+       BOOLEANEDGE, ORDERTYPE, SETTYPE, PREDTABLETYPE, PREDOPERTYPE, TABLETYPE, FUNCTABLETYPE, FUNCOPTYPE};
 typedef enum ASTNodeType ASTNodeType;
 
 enum Polarity {P_UNDEFINED=0, P_TRUE=1, P_FALSE=2, P_BOTHTRUEFALSE=3};
index 1795f17..565e0ef 100644 (file)
@@ -123,9 +123,48 @@ void BooleanOrder::serialize(Serializer* serializer){
 }
 
 void BooleanPredicate::serialize(Serializer* serializer){
-       ASSERT(0);
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       
+       predicate->serialize(serializer);
+       uint size = inputs.getSize();
+       for(uint i=0; i<size; i++){
+               Element* input = inputs.get(i);
+               input->serialize(serializer);
+       }
+       serializeBooleanEdge(serializer, undefStatus);
+       
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       BooleanPredicate* This = this;
+       serializer->mywrite(&This, sizeof(BooleanPredicate*));
+       serializer->mywrite(&predicate, sizeof(Predicate *));
+       serializer->mywrite(&size, sizeof(uint));
+       for(uint i=0; i<size; i++){
+               Element *input = inputs.get(i);
+               serializer->mywrite(&input, sizeof(Element *));
+       }
+       Boolean* undefStat = undefStatus.getRaw();
+       serializer->mywrite(&undefStat, sizeof(Boolean*));
 }
 
 void BooleanLogic::serialize(Serializer* serializer){
-       ASSERT(0);
-}
\ No newline at end of file
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       uint size = inputs.getSize();
+       for(uint i=0; i<size; i++){
+               BooleanEdge input = inputs.get(i);
+               serializeBooleanEdge(serializer, input);
+       }
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       BooleanLogic* This = this;
+       serializer->mywrite(&This, sizeof(BooleanLogic*));
+       serializer->mywrite(&op, sizeof(LogicOp));
+       serializer->mywrite(&size, sizeof(uint));
+       for(uint i=0; i<size; i++){
+               Boolean* input = inputs.get(i).getRaw();
+               serializer->mywrite(&input, sizeof(Boolean*));
+       }
+}
+
index 1c45f04..df1f4e8 100644 (file)
@@ -8,10 +8,9 @@
 #include "astnode.h"
 #include "functionencoding.h"
 #include "constraint.h"
-#include "serializable.h"
 #include "serializer.h"
 
-class Boolean : public ASTNode, public Serializable {
+class Boolean : public ASTNode {
 public:
        Boolean(ASTNodeType _type);
        virtual ~Boolean() {}
index 05f6cef..2617022 100644 (file)
@@ -63,3 +63,58 @@ void ElementFunction::updateParents() {
 Set * ElementFunction::getRange() {
        return function->getRange();
 }
+
+void ElementSet::serialize(Serializer* serializer){
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       
+       set->serialize(serializer);
+       
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       ElementSet *This = this;
+       serializer->mywrite(&This, sizeof(ElementSet*));
+       serializer->mywrite(&set, sizeof(Set*));
+}
+
+void ElementConst::serialize(Serializer* serializer){
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       
+       set->serialize(serializer);
+       
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       ElementSet *This = this;
+       serializer->mywrite(&This, sizeof(ElementSet*));
+       VarType type = set->getType();
+       serializer->mywrite(&type, sizeof(VarType));
+       serializer->mywrite(&value, sizeof(uint64_t));
+}
+
+void ElementFunction::serialize(Serializer* serializer){
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+
+       function->serialize(serializer);
+       uint size = inputs.getSize();
+       for(uint i=0; i<size; i++){
+               Element *input = inputs.get(i);
+               input->serialize(serializer);
+       }
+       serializeBooleanEdge(serializer, overflowstatus);
+       
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       ElementFunction *This = this;
+       serializer->mywrite(&This, sizeof(ElementFunction *));
+       serializer->mywrite(&function, sizeof(Function *));
+       serializer->mywrite(&size, sizeof(uint));
+       for(uint i=0; i<size; i++){
+               Element* input = inputs.get(i);
+               serializer->mywrite(&input, sizeof(Element*));
+       }
+       Boolean* overflowstat = overflowstatus.getRaw();
+       serializer->mywrite(&overflowstat, sizeof(Boolean*));
+}
+
index 076e831..19e35b6 100644 (file)
@@ -15,6 +15,7 @@ public:
        Vector<ASTNode *> parents;
        ElementEncoding encoding;
        virtual Element *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;};
+       virtual void serialize(Serializer* serializer) =0;
        virtual void updateParents() {}
        virtual Set * getRange() = 0;
        CMEMALLOC;
@@ -25,9 +26,10 @@ public:
        ElementSet(ASTNodeType type, Set *s);
        ElementSet(Set *s);
        virtual Element *clone(CSolver *solver, CloneMap *map);
+       virtual void serialize(Serializer* serializer);
        CMEMALLOC;
        Set *getRange() {return set;}
- private:
+ protected:
        Set *set;
 
 };
@@ -36,6 +38,7 @@ class ElementConst : public ElementSet {
 public:
        ElementConst(uint64_t value, Set *_set);
        uint64_t value;
+       virtual void serialize(Serializer* serializer);
        Element *clone(CSolver *solver, CloneMap *map);
        CMEMALLOC;
 };
@@ -48,6 +51,7 @@ public:
        BooleanEdge overflowstatus;
        FunctionEncoding functionencoding;
        Element *clone(CSolver *solver, CloneMap *map);
+       virtual void serialize(Serializer* serializer);
        Set * getRange();
        void updateParents();
        CMEMALLOC;
index a882580..96b0797 100644 (file)
@@ -2,6 +2,7 @@
 #include "table.h"
 #include "set.h"
 #include "csolver.h"
+#include "serializer.h"
 
 FunctionOperator::FunctionOperator(ArithOp _op, Set **domain, uint numDomain, Set *_range, OverFlowBehavior _overflowbehavior) :
        Function(OPERATORFUNC),
@@ -64,3 +65,45 @@ Function *FunctionTable::clone(CSolver *solver, CloneMap *map) {
 Set * FunctionTable::getRange() {
        return table->getRange();
 }
+
+void FunctionTable::serialize(Serializer* serializer){
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       
+       table->serialize(serializer);
+       
+       ASTNodeType type = FUNCTABLETYPE;       
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       FunctionTable* This = this;
+       serializer->mywrite(&This, sizeof(FunctionTable*));
+       serializer->mywrite(&table, sizeof(Table *));
+       serializer->mywrite(&undefBehavior, sizeof(UndefinedBehavior));
+       
+}
+
+void FunctionOperator::serialize(Serializer* serializer){
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       
+       uint size = domains.getSize();
+       for(uint i=0; i<size; i++){
+               Set* domain = domains.get(i);
+               domain->serialize(serializer);
+       }
+       range->serialize(serializer);
+       
+       ASTNodeType nodeType = FUNCOPTYPE; 
+       serializer->mywrite(&nodeType, sizeof(ASTNodeType));
+       FunctionOperator* This = this;
+       serializer->mywrite(&This, sizeof(FunctionOperator*));
+       serializer->mywrite(&op, sizeof(ArithOp));
+       serializer->mywrite(&size, sizeof(uint));
+       for(uint i=0; i<size; i++){
+               Set *domain = domains.get(i);
+               serializer->mywrite(&domain, sizeof(Set *));
+       }
+       serializer->mywrite(&range, sizeof(Set *));
+       serializer->mywrite(&overflowbehavior, sizeof(OverFlowBehavior));
+}
\ No newline at end of file
index f34c02e..98ef536 100644 (file)
@@ -12,6 +12,7 @@ public:
        FunctionType type;
        virtual ~Function() {}
        virtual Function *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;}
+       virtual void serialize(Serializer* serialiezr) =0;
        virtual Set * getRange() = 0;
        CMEMALLOC;
 };
@@ -26,6 +27,7 @@ public:
        uint64_t applyFunctionOperator(uint numVals, uint64_t *values);
        bool isInRangeFunction(uint64_t val);
        Function *clone(CSolver *solver, CloneMap *map);
+       virtual void serialize(Serializer* serialiezr);
        Set * getRange() {return range;}
        CMEMALLOC;
 };
@@ -36,6 +38,7 @@ public:
        UndefinedBehavior undefBehavior;
        FunctionTable (Table *table, UndefinedBehavior behavior);
        Function *clone(CSolver *solver, CloneMap *map);
+       virtual void serialize(Serializer* serialiezr);
        Set * getRange();
        CMEMALLOC;
 };
index 2301d47..b8ca724 100644 (file)
@@ -7,9 +7,8 @@
 #include "orderencoding.h"
 #include "boolean.h"
 #include "orderpair.h"
-#include "serializable.h"
 
-class Order : public Serializable {
+class Order{
 public:
        Order(OrderType type, Set *set);
        virtual ~Order();
index d359811..7f63faa 100644 (file)
@@ -50,3 +50,42 @@ Predicate *PredicateTable::clone(CSolver *solver, CloneMap *map) {
        map->put(this, p);
        return p;
 }
+
+void PredicateTable::serialize(Serializer* serializer){        
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       
+       table->serialize(serializer);
+       
+       ASTNodeType type = PREDTABLETYPE;       
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       PredicateTable* This = this;
+       serializer->mywrite(&This, sizeof(PredicateTable*));
+       serializer->mywrite(&table, sizeof(Table *));
+       serializer->mywrite(&undefinedbehavior, sizeof(UndefinedBehavior));
+}
+
+void PredicateOperator::serialize(Serializer* serializer){     
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       
+       uint size = domains.getSize();
+       for(uint i=0; i<size; i++){
+               Set* domain = domains.get(i);
+               domain->serialize(serializer);
+       }
+               
+       ASTNodeType type = PREDOPERTYPE;        
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       PredicateOperator* This = this;
+       serializer->mywrite(&This, sizeof(PredicateOperator*));
+       serializer->mywrite(&op, sizeof(CompOp));
+       serializer->mywrite(&size, sizeof(uint));
+       for(uint i=0; i<size; i++){
+               Set* domain = domains.get(i);
+               serializer->mywrite(&domain, sizeof(Set*));
+       }
+}
+
index 183a960..2f292b2 100644 (file)
@@ -12,6 +12,7 @@ public:
        Predicate(PredicateType _type) : type(_type) {}
        virtual ~Predicate() {}
        virtual Predicate *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;}
+       virtual void serialize(Serializer* serializer) = 0;
        PredicateType type;
        CMEMALLOC;
 };
@@ -21,6 +22,7 @@ public:
        PredicateOperator(CompOp op, Set **domain, uint numDomain);
        bool evalPredicateOperator(uint64_t *inputs);
        Predicate *clone(CSolver *solver, CloneMap *map);
+       virtual void serialize(Serializer* serializer);
        CompOp op;
        Array<Set *> domains;
        CMEMALLOC;
@@ -30,6 +32,7 @@ class PredicateTable : public Predicate {
 public:
        PredicateTable(Table *table, UndefinedBehavior undefBehavior);
        Predicate *clone(CSolver *solver, CloneMap *map);
+       virtual void serialize(Serializer* serializer);
        Table *table;
        UndefinedBehavior undefinedbehavior;
        CMEMALLOC;
index 6a41815..6dbeac0 100644 (file)
@@ -11,9 +11,8 @@
 #include "classlist.h"
 #include "structs.h"
 #include "mymemory.h"
-#include "serializable.h"
 
-class Set : public Serializable {
+class Set {
 public:
        Set(VarType t);
        Set(VarType t, uint64_t *elements, uint num);
index e0f735f..4ce6270 100644 (file)
@@ -5,6 +5,7 @@
 #include "set.h"
 #include "mutableset.h"
 #include "csolver.h"
+#include "serializer.h"
 
 Table::Table(Set **_domains, uint numDomain, Set *_range) :
        domains(_domains, numDomain),
@@ -58,3 +59,40 @@ Table::~Table() {
        delete entries;
 }
 
+
+
+void Table::serialize(Serializer* serializer){
+       if(serializer->isSerialized(this))
+               return;
+       serializer->addObject(this);
+       
+       uint size = domains.getSize();
+       for(uint i=0; i<size; i++){
+               Set* domain = domains.get(i);
+               domain->serialize(serializer);
+       }
+       range->serialize(serializer);
+       
+       ASTNodeType type = TABLETYPE;   
+       serializer->mywrite(&type, sizeof(ASTNodeType));
+       Table* This = this;
+       serializer->mywrite(&This, sizeof(Table*));
+       serializer->mywrite(&size, sizeof(uint));
+       for(uint i=0; i<size; i++){
+               Set* domain = domains.get(i);
+               serializer->mywrite(&domain, sizeof(Set*));
+       }
+       serializer->mywrite(&range, sizeof(Set*));
+       size = entries->getSize();
+       serializer->mywrite(&size, sizeof(uint));
+       SetIteratorTableEntry* iterator = getEntries();
+       while(iterator->hasNext()){
+               TableEntry* entry = iterator->next();
+               serializer->mywrite(&entry->output, sizeof(uint64_t));
+               serializer->mywrite(&entry->inputSize, sizeof(uint));
+               serializer->mywrite(entry->inputs, sizeof(uint64_t) * entry->inputSize);
+               ASSERT(0);
+       }
+}
+
+
index 6c7926e..db8d188 100644 (file)
@@ -10,6 +10,7 @@ public:
        void addNewTableEntry(uint64_t *inputs, uint inputSize, uint64_t result);
        TableEntry *getTableEntry(uint64_t *inputs, uint inputSize);
        Table *clone(CSolver *solver, CloneMap *map);
+       void serialize(Serializer *serializer);
        ~Table();
        Set * getRange() {return range;}
        
index 7616cd7..2b431de 100644 (file)
@@ -10,6 +10,9 @@
 #include "csolver.h"
 #include "unistd.h"
 #include "fcntl.h"
+#include "predicate.h"
+#include "table.h"
+#include "element.h"
 
 Deserializer::Deserializer(const char* file):
        solver(new CSolver())
@@ -48,6 +51,36 @@ CSolver * Deserializer::deserialize(){
                        case SETTYPE:
                                deserializeSet();
                                break;
+                       case LOGICOP:
+                               deserializeBooleanLogic();
+                               break;
+                       case PREDICATEOP:
+                               deserializeBooleanPredicate();
+                               break;
+                       case PREDTABLETYPE:
+                               deserializePredicateTable();
+                               break;
+                       case PREDOPERTYPE:
+                               deserializePredicateOperator();
+                               break;
+                       case TABLETYPE:
+                               deserializeTable();
+                               break;
+                       case ELEMSET:
+                               deserializeElementSet();
+                               break;
+                       case ELEMCONST:
+                               deserializeElementConst();
+                               break;
+                       case ELEMFUNCRETURN:
+                               deserializeElementFunction();
+                               break;
+                       case FUNCOPTYPE:
+                               deserializeFunctionOperator();
+                               break;
+                       case FUNCTABLETYPE:
+                               deserializeFunctionTable();
+                               break;
                        default:
                                ASSERT(0);
                }
@@ -123,3 +156,202 @@ void Deserializer::deserializeSet(){
                solver->createSet(type, members.expose(), size);
        map.put(s_ptr, set);
 }
+
+void Deserializer::deserializeBooleanLogic(){
+       BooleanLogic *bl_ptr;
+       myread(&bl_ptr, sizeof(BooleanLogic *));
+       LogicOp op;
+       myread(&op, sizeof(LogicOp));
+       uint size;
+       myread(&size, sizeof(uint));
+       Vector<BooleanEdge> members;
+       for(uint i=0; i<size; i++){
+               
+       }
+       map.put(bl_ptr, solver->applyLogicalOperation(op, members.expose(), size).getBoolean());
+}
+
+void Deserializer::deserializeBooleanPredicate(){
+       BooleanPredicate *bp_ptr;
+       myread(&bp_ptr, sizeof(BooleanPredicate *));
+       Predicate* predicate;
+       myread(&predicate, sizeof(Predicate*));
+       ASSERT(map.contains(predicate));
+       predicate = (Predicate*) map.get(predicate);
+       uint size;
+       myread(&size, sizeof(uint));
+       Vector<Element*> members;
+       for(uint i=0; i<size; i++){
+               Element* input;
+               myread(&input, sizeof(Element *));
+               ASSERT(map.contains(input));
+               input = (Element*) map.get(input);
+               members.push(input);
+       }
+       
+       Boolean* stat_ptr;
+       myread(&stat_ptr, sizeof(Boolean *));
+       BooleanEdge tmp(stat_ptr);
+       bool isNegated = tmp.isNegated();
+       ASSERT(map.contains(tmp.getBoolean()));
+       stat_ptr = (Boolean*) map.get(tmp.getBoolean());
+       BooleanEdge res(stat_ptr);
+       BooleanEdge undefStatus = isNegated?res.negate():res;
+       
+       map.put(bp_ptr, solver->applyPredicateTable(predicate, members.expose(), size, undefStatus).getBoolean());
+}
+
+void Deserializer::deserializePredicateTable(){
+       PredicateTable *pt_ptr;
+       myread(&pt_ptr, sizeof(PredicateTable *));
+       Table* table;
+       myread(&table, sizeof(Table*));
+       ASSERT(map.contains(table));
+       table = (Table*) map.get(table);
+       UndefinedBehavior undefinedbehavior;
+       myread(&undefinedbehavior, sizeof(UndefinedBehavior));
+       
+       map.put(pt_ptr, solver->createPredicateTable(table, undefinedbehavior));
+}
+
+void Deserializer::deserializePredicateOperator(){
+       PredicateOperator *po_ptr;
+       myread(&po_ptr, sizeof(PredicateOperator *));
+       CompOp op;
+       myread(&op, sizeof(CompOp));
+       uint size;
+       myread(&size, sizeof(uint));
+       Vector<Set*> domains;
+       for(uint i=0; i<size; i++){
+               Set* domain;
+               myread(&domain, sizeof(Set*));
+               ASSERT(map.contains(domain));
+               domain = (Set*) map.get(domain);
+               domains.push(domain);
+       }
+
+       map.put(po_ptr, solver->createPredicateOperator(op, domains.expose(), size));
+}
+
+void Deserializer::deserializeTable(){
+       Table *t_ptr;
+       myread(&t_ptr, sizeof(Table *));
+       uint size;
+       myread(&size, sizeof(uint));
+       Vector<Set*> domains;
+       for(uint i=0; i<size; i++){
+               Set* domain;
+               myread(&domain, sizeof(Set*));
+               ASSERT(map.contains(domain));
+               domain = (Set*) map.get(domain);
+               domains.push(domain);
+       }
+       Set* range;
+       myread(&range, sizeof(Set*));
+       ASSERT(map.contains(range));
+       range = (Set*) map.get(range);
+       Table* table = solver->createTable(domains.expose(), size, range);
+       myread(&size, sizeof(uint));
+       for(uint i=0; i<size; i++){
+               uint64_t output;
+               myread(&output, sizeof(uint64_t));
+               uint inputSize;
+               myread(&inputSize, sizeof(uint));
+               Vector<uint64_t> inputs;
+               inputs.setSize(inputSize);
+               myread(inputs.expose(), sizeof(uint64_t)*inputSize);
+               ASSERT(0);
+               table->addNewTableEntry(inputs.expose(), inputSize, output);
+       }
+       
+       map.put(t_ptr, table);
+}
+
+
+void Deserializer::deserializeElementSet(){
+       ElementSet* es_ptr;
+       myread(&es_ptr, sizeof(ElementSet*));
+       Set * set;
+       myread(&set, sizeof(Set *));
+       ASSERT(map.contains(set));
+       set  = (Set*) map.get(set);
+       map.put(es_ptr, solver->getElementVar(set));
+}
+
+void Deserializer::deserializeElementConst(){
+       ElementSet* es_ptr;
+       myread(&es_ptr, sizeof(ElementSet*));
+       VarType type;
+       myread(&type, sizeof(VarType));
+       uint64_t value;
+       myread(&value, sizeof(uint64_t));
+       map.put(es_ptr, solver->getElementConst(type, value));
+}
+
+void Deserializer::deserializeElementFunction(){
+       ElementFunction *ef_ptr;
+       myread(&ef_ptr, sizeof(ElementFunction *));
+       Function *function;
+       myread(&function, sizeof(Function*));
+       ASSERT(map.contains(function));
+       function = (Function*) map.get(function);
+       uint size;
+       myread(&size, sizeof(uint));
+       Vector<Element*> members;
+       for(uint i=0; i<size; i++){
+               Element* input;
+               myread(&input, sizeof(Element *));
+               ASSERT(map.contains(input));
+               input = (Element*) map.get(input);
+               members.push(input);
+       }
+       
+       Boolean* overflowstatus;
+       myread(&overflowstatus, sizeof(Boolean *));
+       BooleanEdge tmp(overflowstatus);
+       bool isNegated = tmp.isNegated();
+       ASSERT(map.contains(tmp.getBoolean()));
+       overflowstatus = (Boolean*) map.get(tmp.getBoolean());
+       BooleanEdge res(overflowstatus);
+       BooleanEdge undefStatus = isNegated?res.negate():res;
+       
+       map.put(ef_ptr, solver->applyFunction(function, members.expose(), size, undefStatus));
+}
+
+
+void Deserializer::deserializeFunctionOperator(){
+       FunctionOperator *fo_ptr;
+       myread(&fo_ptr, sizeof(FunctionOperator *));
+       ArithOp op;
+       myread(&op, sizeof(ArithOp));
+       uint size;
+       myread(&size, sizeof(uint));
+       Vector<Set*> domains;
+       for(uint i=0; i<size; i++){
+               Set* domain;
+               myread(&domain, sizeof(Set*));
+               ASSERT(map.contains(domain));
+               domain = (Set*) map.get(domain);
+               domains.push(domain);
+       }
+       Set* range;
+       myread(&range, sizeof(Set*));
+       ASSERT(map.contains(range));
+       range = (Set*) map.get(range);
+       OverFlowBehavior overflowbehavior;
+       myread(&overflowbehavior, sizeof(OverFlowBehavior));
+       map.put(fo_ptr, solver->createFunctionOperator(op, domains.expose(), size, range, overflowbehavior));
+}
+
+void Deserializer::deserializeFunctionTable(){
+       FunctionTable *ft_ptr;
+       myread(&ft_ptr, sizeof(FunctionTable *));
+       Table* table;
+       myread(&table, sizeof(Table*));
+       ASSERT(map.contains(table));
+       table = (Table*) map.get(table);
+       UndefinedBehavior undefinedbehavior;
+       myread(&undefinedbehavior, sizeof(UndefinedBehavior));
+       
+       map.put(ft_ptr, solver->completeTable(table, undefinedbehavior));
+}
\ No newline at end of file
index 7c7d39a..057346d 100644 (file)
@@ -29,6 +29,16 @@ private:
        void deserializeBooleanOrder();
        void deserializeOrder();
        void deserializeSet();
+       void deserializeBooleanLogic();
+       void deserializeBooleanPredicate();
+       void deserializePredicateTable();
+       void deserializePredicateOperator();
+       void deserializeTable();
+       void deserializeElementSet();
+       void deserializeElementConst();
+       void deserializeElementFunction();
+       void deserializeFunctionOperator();
+       void deserializeFunctionTable();
        CSolver *solver;
        int filedesc;
        CloneMap map;
diff --git a/src/Serialize/serializable.h b/src/Serialize/serializable.h
deleted file mode 100644 (file)
index a5e769d..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-
-/* 
- * File:   serializable.h
- * Author: hamed
- *
- * Created on September 7, 2017, 3:39 PM
- */
-
-#ifndef SERIALIZABLE_H
-#define SERIALIZABLE_H
-
-class Serializable{
-       virtual void serialize(Serializer* ) = 0;
-};
-
-#endif /* SERIALIZABLE_H */
-
index 783cf88..524f9ee 100644 (file)
@@ -30,7 +30,7 @@ void Serializer::mywrite(const void *__buf, size_t __n){
 }
 
 
-void serializeBooleanEdge(Serializer* serializer, BooleanEdge& be){
+void serializeBooleanEdge(Serializer* serializer, BooleanEdge be){
        be.getBoolean()->serialize(serializer);
        ASTNodeType type = BOOLEANEDGE;
        serializer->mywrite(&type, sizeof(ASTNodeType));
index eb114dc..12bff13 100644 (file)
@@ -31,7 +31,7 @@ inline bool Serializer::isSerialized(void* obj){
 
 
 
-void serializeBooleanEdge(Serializer* serializer, BooleanEdge& be);
+void serializeBooleanEdge(Serializer* serializer, BooleanEdge be);
 
 #endif /* SERIALIZER_H */
 
index 46bc2a3..e01fb8f 100644 (file)
@@ -50,7 +50,7 @@ int main(int numargs, char **argv) {
        Element *inputs2 [] = {e4, e3};
        BooleanEdge pred = solver->applyPredicate(equal2, inputs2, 2);
        solver->addConstraint(pred);
-//     solver->serialize();
+       solver->serialize();
        if (solver->solve() == 1)
                printf("e1=%" PRIu64 " e2=%" PRIu64 " \n", solver->getElementValue(e1), solver->getElementValue(e2));
        else
index aeab4a5..e041cb0 100644 (file)
@@ -24,6 +24,7 @@ int main(int numargs, char **argv) {
        Element *inputs[] = {e1, e2};
        BooleanEdge b = solver->applyPredicate(equals, inputs, 2);
        solver->addConstraint(b);
+       solver->serialize();
 
        if (solver->solve() == 1)
                printf("e1=%" PRIu64 " e2=%" PRIu64 "\n", solver->getElementValue(e1), solver->getElementValue(e2));
index 6a7a067..123d6cd 100644 (file)
@@ -19,7 +19,7 @@ int main(int numargs, char **argv) {
        Element *inputs[] = {e1, e2};
        BooleanEdge b = solver->applyPredicate(equals, inputs, 2);
        solver->addConstraint(b);
-
+       solver->serialize();
        if (solver->solve() == 1)
                printf("e1=%" PRIu64 " e2=%" PRIu64 "\n", solver->getElementValue(e1), solver->getElementValue(e2));
        else
index e3baeb9..72a0a83 100644 (file)
@@ -72,6 +72,7 @@ int main(int numargs, char **argv) {
        Element *inputs2 [] = {e7, e6};
        BooleanEdge pred = solver->applyPredicate(gt, inputs2, 2);
        solver->addConstraint(pred);
+       solver->serialize();
 
        if (solver->solve() == 1)
                printf("e1=%" PRIu64 " e2=%" PRIu64 " e7=%" PRIu64 "\n",
index 9b20015..7b30f80 100644 (file)
@@ -24,6 +24,7 @@ int main(int numargs, char **argv) {
        solver->addConstraint(solver->applyLogicalOperation(SATC_OR, barray4, 2));
        BooleanEdge barray5[] = {b1, b4};
        solver->addConstraint(solver->applyLogicalOperation(SATC_XOR, barray5, 2));
+       solver->serialize();
        if (solver->solve() == 1)
                printf("b1=%d b2=%d b3=%d b4=%d\n",
                                         solver->getBooleanValue(b1), solver->getBooleanValue(b2),
index d666833..11a315c 100644 (file)
@@ -18,6 +18,7 @@ int main(int numargs, char **argv) {
        Element *inputs2[] = {e1, e2};
        BooleanEdge b = solver->applyPredicate(lt, inputs2, 2);
        solver->addConstraint(b);
+       solver->serialize();
        if (solver->solve() == 1)
                printf("e1=%" PRIu64 " e2=%" PRIu64 "\n", solver->getElementValue(e1), solver->getElementValue(e2));
        else
index 80a57ff..fea3a9f 100644 (file)
@@ -45,7 +45,7 @@ int main(int numargs, char **argv) {
 
        BooleanEdge array12[] = {o58, o81};
        solver->addConstraint(solver->applyLogicalOperation(SATC_AND, array12, 2) );
-
+       solver->serialize();
        /*      if (solver->solve() == 1)
           printf("SAT\n");
           else
index 11017c6..680d1c6 100644 (file)
@@ -49,6 +49,7 @@ int main(int numargs, char **argv) {
        Element *inputs2 [] = {e4, e3};
        BooleanEdge pred = solver->applyPredicate(lte, inputs2, 2);
        solver->addConstraint(pred);
+       solver->serialize();
 
        if (solver->solve() == 1)
                printf("e1=%" PRIu64 " e2=%" PRIu64 " e3=%" PRIu64 " e4=%" PRIu64 " overFlow:%d\n",
index 47113fd..4007e25 100644 (file)
@@ -57,6 +57,7 @@ int main(int numargs, char **argv) {
        Element *tmparray2[] = {e1, e2};
        BooleanEdge pred2 = solver->applyPredicate(eq, tmparray2, 2);
        solver->addConstraint(pred2);
+       solver->serialize();
 
        if (solver->solve() == 1)
                printf("e1=%" PRIu64 " e2=%" PRIu64 " e3=%" PRIu64 " undefFlag:%d\n",