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));
+}
#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;
Boolean *clone(CSolver *solver, CloneMap *map);
bool isTrue() {return istrue;}
bool isFalse() {return !istrue;}
+ void serialize(Serializer *serializer ){};
+
bool istrue;
CMEMALLOC;
};
public:
BooleanVar(VarType t);
Boolean *clone(CSolver *solver, CloneMap *map);
-
+ void serialize(Serializer *serializer );
+
VarType vtype;
Edge var;
CMEMALLOC;
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;
public:
BooleanPredicate(Predicate *_predicate, Element **_inputs, uint _numInputs, BooleanEdge _undefinedStatus);
Boolean *clone(CSolver *solver, CloneMap *map);
+ void serialize(Serializer *serializer );
Predicate *predicate;
FunctionEncoding encoding;
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<BooleanEdge> inputs;
case BOOLEANEDGE:
deserializeBooleanEdge();
break;
+ case BOOLEANVAR:
+ deserializeBooleanVar();
+ break;
default:
ASSERT(0);
}
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
private:
ssize_t myread (void *__buf, size_t __nbytes);
void deserializeBooleanEdge();
+ void deserializeBooleanVar();
+ void deserializeBooleanOrder();
CSolver *solver;
int filedesc;
CloneMap map;
#ifndef SERIALIZABLE_H
#define SERIALIZABLE_H
-#include "classlist.h"
class Serializable{
virtual void serialize(Serializer* ) = 0;
#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);
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*));