X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=blobdiff_plain;f=src%2FAST%2Fboolean.cc;h=fff3658abb16bc404bd0d40f8c3f9c6db5d593aa;hp=7c3771095a2ca448eab0ab4e84dea940be384da7;hb=0703630a40f4fcfd8c8dcad336472907f125c86c;hpb=7fb0eb9a3dcf843f413d858e1cf66e9e13de200f diff --git a/src/AST/boolean.cc b/src/AST/boolean.cc index 7c37710..fff3658 100644 --- a/src/AST/boolean.cc +++ b/src/AST/boolean.cc @@ -31,50 +31,53 @@ BooleanOrder::BooleanOrder(Order *_order, uint64_t _first, uint64_t _second) : order->constraints.push(this); } -BooleanPredicate::BooleanPredicate(Predicate *_predicate, Element **_inputs, uint _numInputs, Boolean *_undefinedStatus) : +BooleanPredicate::BooleanPredicate(Predicate *_predicate, Element **_inputs, uint _numInputs, BooleanEdge _undefinedStatus) : Boolean(PREDICATEOP), predicate(_predicate), encoding(this), inputs(_inputs, _numInputs), undefStatus(_undefinedStatus) { - for (uint i = 0; i < _numInputs; i++) { - _inputs[i]->parents.push(this); - } } -BooleanLogic::BooleanLogic(CSolver *solver, LogicOp _op, Boolean **array, uint asize) : +BooleanLogic::BooleanLogic(CSolver *solver, LogicOp _op, BooleanEdge *array, uint asize) : Boolean(LOGICOP), op(_op), + replaced(false), inputs(array, asize) { } +BooleanEdge cloneEdge(CSolver *solver, CloneMap *map, BooleanEdge e) { + bool isnegated=e.isNegated(); + Boolean *b=e->clone(solver, map); + BooleanEdge be=BooleanEdge(b); + return isnegated ? be.negate() : be; +} + Boolean *BooleanConst::clone(CSolver *solver, CloneMap *map) { - if (istrue) - return solver->getBooleanTrue(); - else - return solver->getBooleanFalse(); + return solver->getBooleanTrue().getRaw(); } Boolean *BooleanVar::clone(CSolver *solver, CloneMap *map) { Boolean *b = (Boolean *) map->get(this); if (b != NULL) return b; - Boolean *bvar = solver->getBooleanVar(type); - map->put(this, bvar); - return bvar; + BooleanEdge bvar = solver->getBooleanVar(type); + Boolean * base=bvar.getRaw(); + map->put(this, base); + return base; } Boolean *BooleanOrder::clone(CSolver *solver, CloneMap *map) { Order *ordercopy = order->clone(solver, map); - return solver->orderConstraint(ordercopy, first, second); + return solver->orderConstraint(ordercopy, first, second).getRaw(); } Boolean *BooleanLogic::clone(CSolver *solver, CloneMap *map) { - Boolean *array[inputs.getSize()]; + BooleanEdge array[inputs.getSize()]; for (uint i = 0; i < inputs.getSize(); i++) { - array[i] = inputs.get(i)->clone(solver, map); + array[i] = cloneEdge(solver, map, inputs.get(i)); } - return solver->applyLogicalOperation(op, array, inputs.getSize()); + return solver->applyLogicalOperation(op, array, inputs.getSize()).getRaw(); } Boolean *BooleanPredicate::clone(CSolver *solver, CloneMap *map) { @@ -83,7 +86,126 @@ Boolean *BooleanPredicate::clone(CSolver *solver, CloneMap *map) { array[i] = inputs.get(i)->clone(solver, map); } Predicate *pred = predicate->clone(solver, map); - Boolean *defstatus = (undefStatus != NULL) ? undefStatus->clone(solver, map) : NULL; + BooleanEdge defstatus = undefStatus ? cloneEdge(solver, map, undefStatus) : BooleanEdge(); - return solver->applyPredicateTable(pred, array, inputs.getSize(), defstatus); + return solver->applyPredicateTable(pred, array, inputs.getSize(), defstatus).getRaw(); } + +void BooleanPredicate::updateParents() { + for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this); +} + +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)); + BooleanVar* This = this; + serializer->mywrite(&This, sizeof(BooleanVar*)); + serializer->mywrite(&vtype, sizeof(VarType)); +} + +void BooleanVar::print(){ + model_print("BooleanVar:%lu\n", (uintptr_t)this); +} + +void BooleanConst::print(){ + model_print("BooleanConst:%s\n", istrue?"TRUE" :"FALSE"); +} + +void BooleanOrder::serialize(Serializer* serializer){ + if(serializer->isSerialized(this)) + return; + serializer->addObject(this); + order->serialize(serializer); + + serializer->mywrite(&type, sizeof(ASTNodeType)); + BooleanOrder* This = this; + serializer->mywrite(&This, sizeof(BooleanOrder*)); + serializer->mywrite(&order, sizeof(Order*)); + serializer->mywrite(&first, sizeof(uint64_t)); + serializer->mywrite(&second, sizeof(uint64_t)); +} + +void BooleanOrder::print(){ + model_print("{BooleanOrder: First= %lu, Second = %lu on Order:\n", first, second); + order->print(); + model_print("}\n"); +} + +void BooleanPredicate::serialize(Serializer* serializer){ + if(serializer->isSerialized(this)) + return; + serializer->addObject(this); + + predicate->serialize(serializer); + uint size = inputs.getSize(); + for(uint i=0; iserialize(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; imywrite(&input, sizeof(Element *)); + } + Boolean* undefStat = undefStatus!= BooleanEdge(NULL)?undefStatus.getRaw() : NULL; + serializer->mywrite(&undefStat, sizeof(Boolean*)); +} + +void BooleanPredicate::print(){ + model_print("{BooleanPredicate:\n"); + predicate->print(); + model_print("elements:\n"); + uint size = inputs.getSize(); + for(uint i=0; iprint(); + } + model_print("}\n"); +} + +void BooleanLogic::serialize(Serializer* serializer){ + if(serializer->isSerialized(this)) + return; + serializer->addObject(this); + uint size = inputs.getSize(); + for(uint i=0; imywrite(&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; imywrite(&input, sizeof(Boolean*)); + } +} + +void BooleanLogic::print(){ + model_print("{BooleanLogic: %s\n", + op ==SATC_AND? "AND": op == SATC_OR? "OR": op==SATC_NOT? "NOT": + op == SATC_XOR? "XOR" : op==SATC_IFF? "IFF" : "IMPLIES"); + uint size = inputs.getSize(); + for(uint i=0; iprint(); + } + model_print("}\n"); +} +