More refactoring
authorbdemsky <bdemsky@uci.edu>
Fri, 8 Sep 2017 03:54:20 +0000 (20:54 -0700)
committerbdemsky <bdemsky@uci.edu>
Fri, 8 Sep 2017 03:54:20 +0000 (20:54 -0700)
src/AST/element.cc
src/AST/element.h
src/Backend/satfuncopencoder.cc
src/Encoders/elementencoding.cc
src/Translator/sattranslator.cc
src/csolver.cc

index 589e3f50130a25e8514cd6476ee8d16ba89d7598..05f6cefdc9a0ab621d092f6747687a7f2691c167 100644 (file)
@@ -16,6 +16,11 @@ ElementSet::ElementSet(Set *s) :
        set(s) {
 }
 
        set(s) {
 }
 
+ElementSet::ElementSet(ASTNodeType _type, Set *s) :
+       Element(_type),
+       set(s) {
+}
+
 ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, BooleanEdge _overflowstatus) :
        Element(ELEMFUNCRETURN),
        function(_function),
 ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, BooleanEdge _overflowstatus) :
        Element(ELEMFUNCRETURN),
        function(_function),
@@ -24,29 +29,11 @@ ElementFunction::ElementFunction(Function *_function, Element **array, uint numA
        functionencoding(this) {
 }
 
        functionencoding(this) {
 }
 
-ElementConst::ElementConst(uint64_t _value, VarType _type, Set *_set) :
-       Element(ELEMCONST),
-       set(_set),
+ElementConst::ElementConst(uint64_t _value, Set *_set) :
+       ElementSet(ELEMCONST, _set),
        value(_value) {
 }
 
        value(_value) {
 }
 
-Set *getElementSet(Element *This) {
-       switch (This->type) {
-       case ELEMSET:
-               return ((ElementSet *)This)->set;
-       case ELEMCONST:
-               return ((ElementConst *)This)->set;
-       case ELEMFUNCRETURN: {
-               Function *func = ((ElementFunction *)This)->function;
-               return func->getRange();
-       }
-       default:
-               ASSERT(0);
-       }
-       ASSERT(0);
-       return NULL;
-}
-
 Element *ElementConst::clone(CSolver *solver, CloneMap *map) {
        return solver->getElementConst(type, value);
 }
 Element *ElementConst::clone(CSolver *solver, CloneMap *map) {
        return solver->getElementConst(type, value);
 }
@@ -72,3 +59,7 @@ Element *ElementFunction::clone(CSolver *solver, CloneMap *map) {
 void ElementFunction::updateParents() {
        for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this);
 }
 void ElementFunction::updateParents() {
        for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this);
 }
+
+Set * ElementFunction::getRange() {
+       return function->getRange();
+}
index 544725624c4d4ab3ef6426fd4cc8fba070a756d0..076e83186209ea9f9e3dee0da2ed603c58cba6be 100644 (file)
@@ -16,23 +16,26 @@ public:
        ElementEncoding encoding;
        virtual Element *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;};
        virtual void updateParents() {}
        ElementEncoding encoding;
        virtual Element *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;};
        virtual void updateParents() {}
-       
+       virtual Set * getRange() = 0;
        CMEMALLOC;
 };
 
        CMEMALLOC;
 };
 
-class ElementConst : public Element {
+class ElementSet : public Element {
 public:
 public:
-       ElementConst(uint64_t value, VarType type, Set *_set);
-       Set *set;
-       uint64_t value;
-       Element *clone(CSolver *solver, CloneMap *map);
+       ElementSet(ASTNodeType type, Set *s);
+       ElementSet(Set *s);
+       virtual Element *clone(CSolver *solver, CloneMap *map);
        CMEMALLOC;
        CMEMALLOC;
+       Set *getRange() {return set;}
+ private:
+       Set *set;
+
 };
 
 };
 
-class ElementSet : public Element {
+class ElementConst : public ElementSet {
 public:
 public:
-       ElementSet(Set *s);
-       Set *set;
+       ElementConst(uint64_t value, Set *_set);
+       uint64_t value;
        Element *clone(CSolver *solver, CloneMap *map);
        CMEMALLOC;
 };
        Element *clone(CSolver *solver, CloneMap *map);
        CMEMALLOC;
 };
@@ -45,12 +48,11 @@ public:
        BooleanEdge overflowstatus;
        FunctionEncoding functionencoding;
        Element *clone(CSolver *solver, CloneMap *map);
        BooleanEdge overflowstatus;
        FunctionEncoding functionencoding;
        Element *clone(CSolver *solver, CloneMap *map);
+       Set * getRange();
        void updateParents();
        CMEMALLOC;
 };
 
        void updateParents();
        CMEMALLOC;
 };
 
-Set *getElementSet(Element *This);
-
 static inline ElementEncoding *getElementEncoding(Element *e) {
        return &e->encoding;
 }
 static inline ElementEncoding *getElementEncoding(Element *e) {
        return &e->encoding;
 }
index ba8b32b507f1a2c2f6672dbd3a7c4594813bfaaf..bfd4ea6b6cb63f0921f7707458d5877aa4ac4afb 100644 (file)
@@ -104,7 +104,7 @@ void SATEncoder::encodeOperatorElementFunctionSATEncoder(ElementFunction *func)
 
        uint64_t vals[numDomains];//setup value array
        for (uint i = 0; i < numDomains; i++) {
 
        uint64_t vals[numDomains];//setup value array
        for (uint i = 0; i < numDomains; i++) {
-               Set *set = getElementSet(func->inputs.get(i));
+               Set *set = func->inputs.get(i)->getRange();
                vals[i] = set->getElement(indices[i]);
        }
 
                vals[i] = set->getElement(indices[i]);
        }
 
@@ -173,7 +173,7 @@ void SATEncoder::encodeOperatorElementFunctionSATEncoder(ElementFunction *func)
                notfinished = false;
                for (uint i = 0; i < numDomains; i++) {
                        uint index = ++indices[i];
                notfinished = false;
                for (uint i = 0; i < numDomains; i++) {
                        uint index = ++indices[i];
-                       Set *set = getElementSet(func->inputs.get(i));
+                       Set *set = func->inputs.get(i)->getRange();
 
                        if (index < set->getSize()) {
                                vals[i] = set->getElement(index);
 
                        if (index < set->getSize()) {
                                vals[i] = set->getElement(index);
index 89d3c3262e11105e3c52de2b488de953d271ea8f..66a97d08602672d2eed1390f4788b7b50249bfa0 100644 (file)
@@ -39,7 +39,7 @@ void ElementEncoding::setElementEncodingType(ElementEncodingType _type) {
 }
 
 void ElementEncoding::encodingArrayInitialization() {
 }
 
 void ElementEncoding::encodingArrayInitialization() {
-       Set *set = getElementSet(element);
+       Set *set = element->getRange();
        uint size = set->getSize();
        uint encSize = getSizeEncodingArray(size);
        allocEncodingArrayElement(encSize);
        uint size = set->getSize();
        uint encSize = getSizeEncodingArray(size);
        allocEncodingArrayElement(encSize);
index d670a94fdff895d795ff6240233d3ff6d84369bf..bdcd1967cbf452625dc7af666e645ef650a51716 100644 (file)
@@ -59,7 +59,7 @@ uint64_t getElementValueUnarySATTranslator(CSolver *This, ElementEncoding *elemE
 uint64_t getElementValueSATTranslator(CSolver *This, Element *element) {
        ElementEncoding *elemEnc = getElementEncoding(element);
        if (elemEnc->numVars == 0)//case when the set has only one item
 uint64_t getElementValueSATTranslator(CSolver *This, Element *element) {
        ElementEncoding *elemEnc = getElementEncoding(element);
        if (elemEnc->numVars == 0)//case when the set has only one item
-               return getElementSet(element)->getElement(0);
+               return element->getRange()->getElement(0);
        switch (elemEnc->type) {
        case ONEHOT:
                return getElementValueOneHotSATTranslator(This, elemEnc);
        switch (elemEnc->type) {
        case ONEHOT:
                return getElementValueOneHotSATTranslator(This, elemEnc);
index 6454b376ed4672d05fbf31a52c77fd33695570e8..3c6767f585078bba9c0037afa6b259acb02282c2 100644 (file)
@@ -126,7 +126,7 @@ Element *CSolver::getElementVar(Set *set) {
 Element *CSolver::getElementConst(VarType type, uint64_t value) {
        uint64_t array[] = {value};
        Set *set = new Set(type, array, 1);
 Element *CSolver::getElementConst(VarType type, uint64_t value) {
        uint64_t array[] = {value};
        Set *set = new Set(type, array, 1);
-       Element *element = new ElementConst(value, type, set);
+       Element *element = new ElementConst(value, set);
        Element *e = elemMap.get(element);
        if (e == NULL) {
                allSets.push(set);
        Element *e = elemMap.get(element);
        if (e == NULL) {
                allSets.push(set);