From 1615693b51360f548146ef90fd603ca6d1f08ee4 Mon Sep 17 00:00:00 2001 From: Hamed Date: Fri, 8 Sep 2017 13:46:21 -0700 Subject: [PATCH] (de)serializer: BooleanOrder + BooleanVar --- src/AST/boolean.cc | 21 +++++++++++++++++++++ src/AST/boolean.h | 19 +++++++++++++------ src/Serialize/deserializer.cc | 25 +++++++++++++++++++++++++ src/Serialize/deserializer.h | 2 ++ src/Serialize/serializable.h | 1 - src/Serialize/serializer.cc | 3 ++- 6 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/AST/boolean.cc b/src/AST/boolean.cc index 9786644..58bc05e 100644 --- a/src/AST/boolean.cc +++ b/src/AST/boolean.cc @@ -98,3 +98,24 @@ void BooleanPredicate::updateParents() { void BooleanLogic::updateParents() { for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this); } + +void BooleanVar::serialize(Serializer* serializer){ + if(serializer->isSerialized(this)) + return; + serializer->addObject(this); + serializer->mywrite(&type, sizeof(ASTNodeType)); + serializer->mywrite(this, sizeof(BooleanVar*)); + serializer->mywrite(&vtype, sizeof(VarType)); +} + +void BooleanOrder::serialize(Serializer* serializer){ + if(serializer->isSerialized(this)) + return; + serializer->addObject(this); +// order->serialize(serializer); + serializer->mywrite(&type, sizeof(ASTNodeType)); + serializer->mywrite(this, sizeof(BooleanOrder*)); + serializer->mywrite(&order, sizeof(Order*)); + serializer->mywrite(&first, sizeof(uint64_t)); + serializer->mywrite(&second, sizeof(uint64_t)); +} diff --git a/src/AST/boolean.h b/src/AST/boolean.h index 8be1d30..1c45f04 100644 --- a/src/AST/boolean.h +++ b/src/AST/boolean.h @@ -8,14 +8,15 @@ #include "astnode.h" #include "functionencoding.h" #include "constraint.h" +#include "serializable.h" +#include "serializer.h" - - -class Boolean : public ASTNode { +class Boolean : public ASTNode, public Serializable { public: Boolean(ASTNodeType _type); virtual ~Boolean() {} virtual Boolean *clone(CSolver *solver, CloneMap *map) = 0; + virtual void serialize(Serializer* ) = 0; virtual bool isTrue() {return boolVal == BV_MUSTBETRUE;} virtual bool isFalse() {return boolVal == BV_MUSTBEFALSE;} Polarity polarity; @@ -32,6 +33,8 @@ public: Boolean *clone(CSolver *solver, CloneMap *map); bool isTrue() {return istrue;} bool isFalse() {return !istrue;} + void serialize(Serializer *serializer ){}; + bool istrue; CMEMALLOC; }; @@ -40,7 +43,8 @@ class BooleanVar : public Boolean { public: BooleanVar(VarType t); Boolean *clone(CSolver *solver, CloneMap *map); - + void serialize(Serializer *serializer ); + VarType vtype; Edge var; CMEMALLOC; @@ -50,7 +54,8 @@ class BooleanOrder : public Boolean { public: BooleanOrder(Order *_order, uint64_t _first, uint64_t _second); Boolean *clone(CSolver *solver, CloneMap *map); - + void serialize(Serializer *serializer ); + Order *order; uint64_t first; uint64_t second; @@ -61,6 +66,7 @@ class BooleanPredicate : public Boolean { public: BooleanPredicate(Predicate *_predicate, Element **_inputs, uint _numInputs, BooleanEdge _undefinedStatus); Boolean *clone(CSolver *solver, CloneMap *map); + void serialize(Serializer *serializer ); Predicate *predicate; FunctionEncoding encoding; @@ -76,7 +82,8 @@ class BooleanLogic : public Boolean { public: BooleanLogic(CSolver *solver, LogicOp _op, BooleanEdge *array, uint asize); Boolean *clone(CSolver *solver, CloneMap *map); - + void serialize(Serializer *serializer ); + LogicOp op; bool replaced; Array inputs; diff --git a/src/Serialize/deserializer.cc b/src/Serialize/deserializer.cc index 1c45a69..163bd19 100644 --- a/src/Serialize/deserializer.cc +++ b/src/Serialize/deserializer.cc @@ -39,6 +39,9 @@ CSolver * Deserializer::deserialize(){ case BOOLEANEDGE: deserializeBooleanEdge(); break; + case BOOLEANVAR: + deserializeBooleanVar(); + break; default: ASSERT(0); } @@ -56,3 +59,25 @@ void Deserializer::deserializeBooleanEdge(){ BooleanEdge res(b); solver->addConstraint(isNegated?res.negate():res); } + +void Deserializer::deserializeBooleanVar(){ + BooleanVar *b; + myread(&b, sizeof(BooleanVar*)); + VarType vtype; + myread(&vtype, sizeof(VarType)); + map.put(b, solver->getBooleanVar(vtype).getBoolean()); +} + +void Deserializer::deserializeBooleanOrder(){ + BooleanOrder* bo_ptr; + myread(&bo_ptr, sizeof(BooleanOrder*)); + Order* optr; + myread(&optr, sizeof(Order*)); + uint64_t first; + myread(&first, sizeof(uint64_t)); + uint64_t second; + myread(&second, sizeof(uint64_t)); + ASSERT(map.contains(optr)); + Order* order = (Order*) map.get(optr); + map.put(bo_ptr, solver->orderConstraint(order, first, second).getBoolean()); +} \ No newline at end of file diff --git a/src/Serialize/deserializer.h b/src/Serialize/deserializer.h index 8448dff..7e26cf3 100644 --- a/src/Serialize/deserializer.h +++ b/src/Serialize/deserializer.h @@ -25,6 +25,8 @@ public: private: ssize_t myread (void *__buf, size_t __nbytes); void deserializeBooleanEdge(); + void deserializeBooleanVar(); + void deserializeBooleanOrder(); CSolver *solver; int filedesc; CloneMap map; diff --git a/src/Serialize/serializable.h b/src/Serialize/serializable.h index cdaea04..a5e769d 100644 --- a/src/Serialize/serializable.h +++ b/src/Serialize/serializable.h @@ -8,7 +8,6 @@ #ifndef SERIALIZABLE_H #define SERIALIZABLE_H -#include "classlist.h" class Serializable{ virtual void serialize(Serializer* ) = 0; diff --git a/src/Serialize/serializer.cc b/src/Serialize/serializer.cc index 301a312..bf89456 100644 --- a/src/Serialize/serializer.cc +++ b/src/Serialize/serializer.cc @@ -9,6 +9,7 @@ #include "serializer.h" #include "unistd.h" #include "fcntl.h" +#include "boolean.h" Serializer::Serializer(const char *file) { filedesc = open(file, O_WRONLY | O_CREAT, 0666); @@ -35,7 +36,7 @@ void serializeBooleanEdge(Serializer* serializer, BooleanEdge& be){ if(serializer->isSerialized(be.getRaw())) return; serializer->addObject(be.getRaw()); -// b->seralize(serializer); + be.getBoolean()->serialize(serializer); ASTNodeType type = BOOLEANEDGE; serializer->mywrite(&type, sizeof(ASTNodeType)); serializer->mywrite(be.getRaw(), sizeof(Boolean*)); -- 2.34.1