#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)),
elapsedTime(0)
{
satEncoder = new SATEncoder(this);
+ transformer = new Transformer(this);
}
/** This function tears down the solver and the entire AST */
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));
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);
}
uint64_t CSolver::createUniqueItem(MutableSet *set) {
- uint64_t element = set->low++;
+ uint64_t element = set->getNewUniqueItem();
set->addElementMSet(element);
return element;
}
}
}
+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) {
- case L_NOT: {
- if (array[0]->type == LOGICOP && ((BooleanLogic *)array[0])->op==L_NOT) {
+ case SATC_NOT: {
+ 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 L_XOR: {
+ case SATC_IFF: {
for(uint i=0;i<2;i++) {
if (array[i]->type == BOOLCONST) {
- bool isTrue = ((BooleanConst *) array[i])->isTrue;
- if (isTrue) {
+ if (array[i]->isTrue()) {
+ return array[1-i];
+ } else {
newarray[0]=array[1-i];
- return applyLogicalOperation(L_NOT, newarray, 1);
+ return applyLogicalOperation(SATC_NOT, newarray, 1);
+ }
+ }
+ }
+ break;
+ }
+ case SATC_XOR: {
+ for(uint i=0;i<2;i++) {
+ if (array[i]->type == BOOLCONST) {
+ if (array[i]->isTrue()) {
+ newarray[0]=array[1-i];
+ return applyLogicalOperation(SATC_NOT, newarray, 1);
} else
return array[1-i];
}
}
break;
}
- case L_OR: {
+ case SATC_OR: {
uint newindex=0;
for(uint i=0;i<asize;i++) {
Boolean *b=array[i];
if (b->type == BOOLCONST) {
- bool isTrue = ((BooleanConst *) b)->isTrue;
- if (isTrue)
+ if (b->isTrue())
return b;
else
continue;
if (newindex==1)
return newarray[0];
else if (newindex == 2) {
- bool isNot0 = (newarray[0]->type==BOOLCONST) && ((BooleanLogic *)newarray[0])->op == L_NOT;
- bool isNot1 = (newarray[1]->type==BOOLCONST) && ((BooleanLogic *)newarray[1])->op == L_NOT;
+ bool isNot0 = (newarray[0]->type==BOOLCONST) && ((BooleanLogic *)newarray[0])->op == SATC_NOT;
+ bool isNot1 = (newarray[1]->type==BOOLCONST) && ((BooleanLogic *)newarray[1])->op == SATC_NOT;
if (isNot0 != isNot1) {
if (isNot0) {
array[1] = array[0];
array[0] = tmp;
}
- return applyLogicalOperation(L_IMPLIES, newarray, 2);
+ return applyLogicalOperation(SATC_IMPLIES, newarray, 2);
}
} else {
array = newarray;
}
break;
}
- case L_AND: {
+ case SATC_AND: {
uint newindex=0;
for(uint i=0;i<asize;i++) {
Boolean *b=array[i];
if (b->type == BOOLCONST) {
- bool isTrue = ((BooleanConst *) b)->isTrue;
- if (isTrue)
+ if (b->isTrue())
continue;
else
return b;
}
break;
}
- case L_IMPLIES: {
+ 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(L_NOT, array, 1);
+ return applyLogicalOperation(SATC_NOT, array, 1);
}
}
break;
return order;
}
-int CSolver::startEncoding() {
+int CSolver::solve() {
bool deleteTuner = false;
if (tuner == NULL) {
tuner = new DefaultTuner();
long long startTime = getTimeNano();
computePolarities(this);
- orderAnalysis(this);
+ transformer->orderAnalysis();
naiveEncodingDecision(this);
satEncoder->encodeAllSATEncoder(this);
int result = unsat ? IS_UNSAT : satEncoder->solve();