--- /dev/null
+#include "asthash.h"
+#include "mymemory.h"
+#include "structs.h"
+#include "boolean.h"
+#include "element.h"
+
+bool compareArray(Array<Boolean *> * inputs1, Array<Boolean *> *inputs2) {
+ if (inputs1->getSize() != inputs2->getSize())
+ return false;
+ for(uint i=0;i<inputs1->getSize();i++) {
+ if (inputs1->get(i) != inputs2->get(i))
+ return false;
+ }
+ return true;
+}
+
+bool compareArray(Array<Element *> * inputs1, Array<Element *> *inputs2) {
+ if (inputs1->getSize() != inputs2->getSize())
+ return false;
+ for(uint i=0;i<inputs1->getSize();i++) {
+ if (inputs1->get(i) != inputs2->get(i))
+ return false;
+ }
+ return true;
+}
+
+uint hashArray(Array<Boolean *> * inputs) {
+ uint hash = inputs->getSize();
+ for(uint i=0;i<inputs->getSize();i++) {
+ uint newval = (uint)(uintptr_t) inputs->get(i);
+ hash ^= newval;
+ hash = (hash << 3) | (hash >> 29);
+ }
+ return hash;
+}
+
+uint hashArray(Array<Element *> * inputs) {
+ uint hash = inputs->getSize();
+ for(uint i=0;i<inputs->getSize();i++) {
+ uint newval = (uint)(uintptr_t) inputs->get(i);
+ hash ^= newval;
+ hash = (hash << 3) | (hash >> 29);
+ }
+ return hash;
+}
+
+uint hashBoolean(Boolean * b) {
+ switch(b->type) {
+ case ORDERCONST: {
+ BooleanOrder * o=(BooleanOrder *)b;
+ return ((uint)(uintptr_t) o->order) ^ ((uint) o->first) ^ (((uint)(o->second)) << 2);
+ }
+ case BOOLEANVAR: {
+ return (uint)(uintptr_t) b;
+ }
+ case LOGICOP: {
+ BooleanLogic * l=(BooleanLogic *)b;
+ return ((uint)l->op) ^ hashArray(&l->inputs);
+ }
+ case PREDICATEOP: {
+ BooleanPredicate * p=(BooleanPredicate *)b;
+ return ((uint)(uintptr_t) p->predicate) ^
+ (((uint)(uintptr_t) p->undefStatus) << 1) ^
+ hashArray(&p->inputs);
+ }
+ default:
+ ASSERT(0);
+ }
+}
+
+bool compareBoolean(Boolean *b1, Boolean *b2) {
+ if (b1->type != b2->type)
+ return false;
+ switch(b1->type) {
+ case ORDERCONST: {
+ BooleanOrder * o1=(BooleanOrder *)b1;
+ BooleanOrder * o2=(BooleanOrder *)b2;
+ return (o1->order == o2->order) && (o1->first == o2->first) && (o1->second == o2->second);
+ }
+ case BOOLEANVAR: {
+ return b1 == b2;
+ }
+ case LOGICOP: {
+ BooleanLogic * l1=(BooleanLogic *)b1;
+ BooleanLogic * l2=(BooleanLogic *)b2;
+ return (l1->op == l2->op) && compareArray(&l1->inputs, &l2->inputs);
+ }
+ case PREDICATEOP: {
+ BooleanPredicate * p1=(BooleanPredicate *)b1;
+ BooleanPredicate * p2=(BooleanPredicate *)b2;
+ return (p1->predicate == p2->predicate) &&
+ p1->undefStatus == p2->undefStatus &&
+ compareArray(&p1->inputs, &p2->inputs);
+ }
+ default:
+ ASSERT(0);
+ }
+}
+
+uint hashElement(Element *element) {
+}
+
+bool compareElement(Element *e1, Element *e2) {
+}
--- /dev/null
+#ifndef ASTHASH_H
+#define ASTHASH_H
+#include "classlist.h"
+
+uint hashBoolean(Boolean * boolean);
+bool compareBoolean(Boolean *b1, Boolean *b2);
+
+uint hashElement(Element *element);
+bool compareElement(Element *e1, Element *e2);
+
+#endif
ASTNode(_type),
polarity(P_UNDEFINED),
boolVal(BV_UNDEFINED),
- parents() {
+ parents(),
+ idNumber(0) {
}
BooleanVar::BooleanVar(VarType t) :
Polarity polarity;
BooleanValue boolVal;
Vector<Boolean *> parents;
+
MEMALLOC;
};
Element::Element(ASTNodeType _type) :
ASTNode(_type),
- encoding(this) {
+ encoding(this),
+ idNumber(0) {
}
ElementSet::ElementSet(Set *s) :
Vector<ASTNode *> parents;
ElementEncoding encoding;
virtual Element *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;};
+
MEMALLOC;
};
return element;
}
-Boolean *CSolver::getBooleanVar(VarType type) {
- Boolean *boolean = new BooleanVar(type);
- allBooleans.push(boolean);
- return boolean;
+Element *CSolver::applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
+ Element *element = new ElementFunction(function,array,numArrays,overflowstatus);
+ allElements.push(element);
+ return element;
}
Function *CSolver::createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,OverFlowBehavior overflowbehavior) {
return function;
}
-Element *CSolver::applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
- Element *element = new ElementFunction(function,array,numArrays,overflowstatus);
- allElements.push(element);
- return element;
+Boolean *CSolver::getBooleanVar(VarType type) {
+ Boolean *boolean = new BooleanVar(type);
+ allBooleans.push(boolean);
+ return boolean;
}
Boolean *CSolver::applyPredicate(Predicate *predicate, Element **inputs, uint numInputs) {
return boolean;
}
+Boolean *CSolver::orderConstraint(Order *order, uint64_t first, uint64_t second) {
+ Boolean *constraint = new BooleanOrder(order, first, second);
+ allBooleans.push(constraint);
+ return constraint;
+}
+
void CSolver::addConstraint(Boolean *constraint) {
constraints.add(constraint);
}
return order;
}
-Boolean *CSolver::orderConstraint(Order *order, uint64_t first, uint64_t second) {
- Boolean *constraint = new BooleanOrder(order, first, second);
- allBooleans.push(constraint);
- return constraint;
-}
-
int CSolver::startEncoding() {
bool deleteTuner = false;
if (tuner == NULL) {
MEMALLOC;
private:
+ void assignID(Boolean * b);
+ void assignID(Element * e);
void handleXORFalse(BooleanLogic *bexpr, Boolean *child);
void handleIMPLIESTrue(BooleanLogic *bexpr, Boolean *child);
void handleIMPLIESFalse(BooleanLogic *bexpr, Boolean *child);
SATEncoder *satEncoder;
bool unsat;
Tuner *tuner;
-
+ uint booleanID;
+ uint elementID;
+
long long elapsedTime;
};
#endif