X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=blobdiff_plain;f=src%2Fcsolver.cc;h=0270758af28faa087efc0d2f2cc358e15a221d53;hp=9092af9e91fe37db62d931ded3c7c2ae6a1979ac;hb=ef5d7a44cfe435c24e5f104e320b1a81835626e7;hpb=bb49b371775e60638e71a99febce2bc4a21e075e diff --git a/src/csolver.cc b/src/csolver.cc index 9092af9..0270758 100644 --- a/src/csolver.cc +++ b/src/csolver.cc @@ -11,9 +11,10 @@ #include "sattranslator.h" #include "tunable.h" #include "polarityassignment.h" -#include "analyzer.h" +#include "transformer.h" #include "autotuner.h" #include "astops.h" +#include "structs.h" CSolver::CSolver() : boolTrue(new BooleanConst(true)), @@ -23,6 +24,7 @@ CSolver::CSolver() : elapsedTime(0) { satEncoder = new SATEncoder(this); + transformer = new Transformer(this); } /** This function tears down the solver and the entire AST */ @@ -66,12 +68,13 @@ CSolver::~CSolver() { delete boolTrue; delete boolFalse; delete satEncoder; + delete transformer; } CSolver *CSolver::clone() { CSolver *copy = new CSolver(); CloneMap map; - HSIteratorBoolean *it = getConstraints(); + SetIteratorBoolean *it = getConstraints(); while (it->hasNext()) { Boolean *b = it->next(); copy->addConstraint(b->clone(copy, &map)); @@ -92,6 +95,11 @@ Set *CSolver::createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange return set; } +Element *CSolver::createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange) { + Set *s = createRangeSet(type, lowrange, highrange); + return getElementVar(s); +} + MutableSet *CSolver::createMutableSet(VarType type) { MutableSet *set = new MutableSet(type); allSets.push(set); @@ -213,6 +221,25 @@ Boolean *CSolver::applyPredicateTable(Predicate *predicate, Element **inputs, ui } } +bool CSolver::isTrue(Boolean *b) { + return b->isTrue(); +} + +bool CSolver::isFalse(Boolean *b) { + return b->isFalse(); +} + +Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean * arg1, Boolean * arg2) { + Boolean * array[] = {arg1, arg2}; + return applyLogicalOperation(op, array, 2); +} + +Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean *arg) { + Boolean * array[] = {arg}; + return applyLogicalOperation(op, array, 1); +} + + Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean **array, uint asize) { Boolean * newarray[asize]; switch(op) { @@ -220,16 +247,27 @@ Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean **array, uint asize) if (array[0]->type == LOGICOP && ((BooleanLogic *)array[0])->op==SATC_NOT) { return ((BooleanLogic *) array[0])->inputs.get(0); } else if (array[0]->type == BOOLCONST) { - bool isTrue = ((BooleanConst *) array[0])->isTrue; - return isTrue ? boolFalse : boolTrue; + return array[0]->isTrue() ? boolFalse : boolTrue; + } + break; + } + case SATC_IFF: { + for(uint i=0;i<2;i++) { + if (array[i]->type == BOOLCONST) { + if (array[i]->isTrue()) { + return array[1-i]; + } else { + newarray[0]=array[1-i]; + return applyLogicalOperation(SATC_NOT, newarray, 1); + } + } } break; } case SATC_XOR: { for(uint i=0;i<2;i++) { if (array[i]->type == BOOLCONST) { - bool isTrue = ((BooleanConst *) array[i])->isTrue; - if (isTrue) { + if (array[i]->isTrue()) { newarray[0]=array[1-i]; return applyLogicalOperation(SATC_NOT, newarray, 1); } else @@ -243,8 +281,7 @@ Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean **array, uint asize) for(uint i=0;itype == BOOLCONST) { - bool isTrue = ((BooleanConst *) b)->isTrue; - if (isTrue) + if (b->isTrue()) return b; else continue; @@ -278,8 +315,7 @@ Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean **array, uint asize) for(uint i=0;itype == BOOLCONST) { - bool isTrue = ((BooleanConst *) b)->isTrue; - if (isTrue) + if (b->isTrue()) continue; else return b; @@ -296,16 +332,14 @@ Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean **array, uint asize) } case SATC_IMPLIES: { if (array[0]->type == BOOLCONST) { - BooleanConst *b=(BooleanConst *) array[0]; - if (b->isTrue) { + if (array[0]->isTrue()) { return array[1]; } else { return boolTrue; } } else if (array[1]->type == BOOLCONST) { - BooleanConst *b=(BooleanConst *) array[0]; - if (b->isTrue) { - return b; + if (array[1]->isTrue()) { + return array[1]; } else { return applyLogicalOperation(SATC_NOT, array, 1); } @@ -347,7 +381,7 @@ Order *CSolver::createOrder(OrderType type, Set *set) { return order; } -int CSolver::startEncoding() { +int CSolver::solve() { bool deleteTuner = false; if (tuner == NULL) { tuner = new DefaultTuner(); @@ -356,7 +390,7 @@ int CSolver::startEncoding() { long long startTime = getTimeNano(); computePolarities(this); - orderAnalysis(this); + transformer->orderAnalysis(); naiveEncodingDecision(this); satEncoder->encodeAllSATEncoder(this); int result = unsat ? IS_UNSAT : satEncoder->solve();