enum PredicateType {TABLEPRED, OPERATORPRED};
typedef enum PredicateType PredicateType;
- enum ASTNodeType {ORDERCONST, BOOLEANVAR, LOGICOP, PREDICATEOP, BOOLCONST, ELEMSET, ELEMFUNCRETURN, ELEMCONST};
+ 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};
enum BooleanValue {BV_UNDEFINED=0, BV_MUSTBETRUE=1, BV_MUSTBEFALSE=2, BV_UNSAT=3};
typedef enum BooleanValue BooleanValue;
+enum ElementEncodingType {
+ ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, BINARYVAL
+};
+
+typedef enum ElementEncodingType ElementEncodingType;
+
+
#endif
#include "astnode.h"
#include "functionencoding.h"
#include "constraint.h"
-
-
+ #include "serializer.h"
class Boolean : public ASTNode {
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);
- CMEMALLOC;
+ Predicate *getPredicate() {return predicate;}
+ FunctionEncoding *getFunctionEncoding() {return &encoding;}
+ void updateParents();
+ void serialize(Serializer *serializer );
+
++ CMEMALLOC;
+
Predicate *predicate;
FunctionEncoding encoding;
Array<Element *> inputs;
BooleanEdge undefStatus;
- FunctionEncoding *getFunctionEncoding() {return &encoding;}
- void updateParents();
-
- CMEMALLOC;
};
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<BooleanEdge> inputs;
ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, BooleanEdge _overflowstatus) :
Element(ELEMFUNCRETURN),
- function(_function),
inputs(array, numArrays),
overflowstatus(_overflowstatus),
- functionencoding(this) {
+ functionencoding(this),
+ function(_function) {
}
ElementConst::ElementConst(uint64_t _value, Set *_set) :
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*));
+ }
+
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;
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;
};
public:
ElementConst(uint64_t value, Set *_set);
uint64_t value;
+ virtual void serialize(Serializer* serializer);
Element *clone(CSolver *solver, CloneMap *map);
CMEMALLOC;
};
class ElementFunction : public Element {
public:
ElementFunction(Function *function, Element **array, uint numArrays, BooleanEdge overflowstatus);
- Function *function;
Array<Element *> inputs;
BooleanEdge overflowstatus;
FunctionEncoding functionencoding;
Element *clone(CSolver *solver, CloneMap *map);
+ virtual void serialize(Serializer* serializer);
Set * getRange();
void updateParents();
+ Function * getFunction() {return function;}
CMEMALLOC;
+ private:
+ Function *function;
};
static inline ElementEncoding *getElementEncoding(Element *e) {
#include "table.h"
#include "csolver.h"
-PredicateOperator::PredicateOperator(CompOp _op, Set **domain, uint numDomain) : Predicate(OPERATORPRED), op(_op), domains(domain, numDomain) {
+PredicateOperator::PredicateOperator(CompOp _op, Set **domain, uint numDomain) : Predicate(OPERATORPRED), domains(domain, numDomain), op(_op) {
}
PredicateTable::PredicateTable(Table *_table, UndefinedBehavior _undefBehavior) : Predicate(TABLEPRED), table(_table), undefinedbehavior(_undefBehavior) {
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*));
+ }
+ }
+
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;
};
PredicateOperator(CompOp op, Set **domain, uint numDomain);
bool evalPredicateOperator(uint64_t *inputs);
Predicate *clone(CSolver *solver, CloneMap *map);
- CompOp getOp() {return op;}
+ virtual void serialize(Serializer* serializer);
- CompOp op;
Array<Set *> domains;
++ CompOp getOp() {return op;}
CMEMALLOC;
+ private:
+ CompOp op;
};
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;
typedef Hashset<Boolean *, uintptr_t, PTRSHIFT> HashsetBoolean;
typedef Hashset<Element *, uintptr_t, PTRSHIFT> HashsetElement;
typedef SetIterator<Boolean *, uintptr_t, PTRSHIFT> SetIteratorBoolean;
+typedef Hashset<uint64_t, uint64_t, 0> Hashset64Int;
+
+
typedef Hashtable<OrderNode *, HashsetOrderNode *, uintptr_t, PTRSHIFT> HashtableNodeToNodeSet;
typedef Hashtable<OrderPair *, OrderPair *, uintptr_t, PTRSHIFT, order_pair_hash_function, order_pair_equals> HashtableOrderPair;
typedef Hashtable<void *, void *, uintptr_t, PTRSHIFT> CloneMap;
-typedef Hashtable<Set *, EncodingNode *, uintptr_t, PTRSHIFT> HashTableEncoding;
+typedef Hashtable<Set *, EncodingNode *, uintptr_t, PTRSHIFT> HashtableEncoding;
- typedef Hashset<EncodingNode *, uintptr_t, PTRSHIFT> HashsetEncodingNode;
- typedef SetIterator<EncodingNode *, uintptr_t, PTRSHIFT> SetIteratorEncodingNode;
+
typedef SetIterator<TableEntry *, uintptr_t, PTRSHIFT, table_entry_hash_function, table_entry_equals> SetIteratorTableEntry;
typedef SetIterator<OrderEdge *, uintptr_t, PTRSHIFT, order_edge_hash_function, order_edge_equals> SetIteratorOrderEdge;
--- /dev/null
+
+ /*
+ * File: serializer.h
+ * Author: hamed
+ *
+ * Created on September 7, 2017, 3:38 PM
+ */
+
+ #ifndef SERIALIZER_H
+ #define SERIALIZER_H
+ #include "mymemory.h"
++#include "classlist.h"
+ #include "structs.h"
+
++
+ class Serializer {
+ public:
+ Serializer(const char *file);
+ void mywrite(const void *__buf, size_t __n);
+ inline bool isSerialized(void *obj);
+ inline void addObject(void *obj) { map.put(obj, obj);}
+ virtual ~Serializer();
+ CMEMALLOC;
+ private:
+ int filedesc;
+ CloneMap map;
+ };
+
+ inline bool Serializer::isSerialized(void* obj){
+ return map.contains(obj);
+ }
+
+
+
+
+ void serializeBooleanEdge(Serializer* serializer, BooleanEdge be);
+
+ #endif /* SERIALIZER_H */
+