Inline Encoding Structs into appropriate AST Nodes
authorbdemsky <bdemsky@uci.edu>
Thu, 22 Jun 2017 06:57:05 +0000 (23:57 -0700)
committerbdemsky <bdemsky@uci.edu>
Thu, 22 Jun 2017 06:57:05 +0000 (23:57 -0700)
12 files changed:
src/AST/boolean.c
src/AST/boolean.h
src/AST/element.c
src/AST/element.h
src/Encoders/elementencoding.c
src/Encoders/elementencoding.h
src/Encoders/functionencoding.c
src/Encoders/functionencoding.h
src/Encoders/naiveelementencoder.c [deleted file]
src/Encoders/naiveelementencoder.h [deleted file]
src/Encoders/naiveencoder.c [new file with mode: 0644]
src/Encoders/naiveencoder.h [new file with mode: 0644]

index 8a47f72..0432b43 100644 (file)
@@ -32,6 +32,8 @@ Boolean * allocBooleanPredicate(Predicate * predicate, Element ** inputs, uint n
        for(uint i=0;i<numInputs;i++) {
                pushVectorASTNode(GETELEMENTPARENTS(inputs[i]), (ASTNode *)This);
        }
+       initPredicateEncoding(&This->encoding, (Boolean *) This);
+
        return & This->base;
 }
 
@@ -45,11 +47,14 @@ Boolean * allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean ** array,
 
 void deleteBoolean(Boolean * This) {
        switch(GETBOOLEANTYPE(This)){
-               case PREDICATEOP:
-                       deleteInlineArrayElement(& ((BooleanPredicate*)This)->inputs );
-                       break;
-               default:
-                       break;
+       case PREDICATEOP: {
+               BooleanPredicate *bp=(BooleanPredicate *)This;
+               deleteInlineArrayElement(& bp->inputs );
+               deleteFunctionEncoding(& bp->encoding);
+               break;
+       }
+       default:
+               break;
        }
        deleteVectorArrayBoolean(GETBOOLEANPARENTS(This));
        ourfree(This);
index a9d0702..411af26 100644 (file)
@@ -5,6 +5,7 @@
 #include "ops.h"
 #include "structs.h"
 #include "astnode.h"
+#include "functionencoding.h"
 
 /**
     This is a little sketchy, but apparently legit.
@@ -40,6 +41,7 @@ struct BooleanLogic {
 struct BooleanPredicate {
        Boolean base;
        Predicate * predicate;
+       FunctionEncoding encoding;
        ArrayElement inputs;
 };
 
index 7401173..a94db4b 100644 (file)
@@ -5,8 +5,8 @@ Element *allocElementSet(Set * s) {
        ElementSet * tmp=(ElementSet *)ourmalloc(sizeof(ElementSet));
        GETELEMENTTYPE(tmp)= ELEMSET;
        tmp->set=s;
-       tmp->encoding=NULL;
        allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
+       initElementEncoding(&tmp->encoding, (Element *) tmp);
        return &tmp->base;
 }
 
@@ -19,17 +19,29 @@ Element* allocElementFunction(Function * function, Element ** array, uint numArr
        allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
        for(uint i=0;i<numArrays;i++)
                pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) tmp);
+       initElementEncoding(&tmp->domainencoding, (Element *) tmp);
+       initFunctionEncoding(&tmp->functionencoding, (Element *) tmp);
        return &tmp->base;
 }
 
 void deleteElement(Element *This) {
        switch(GETELEMENTTYPE(This)) {
-       case ELEMFUNCRETURN:
-               deleteInlineArrayElement(&((ElementFunction *)This)->inputs);
+       case ELEMFUNCRETURN: {
+               ElementFunction *ef = (ElementFunction *) This;
+               deleteInlineArrayElement(&ef->inputs);
+               deleteElementEncoding(&ef->domainencoding);
+               deleteFunctionEncoding(&ef->functionencoding);
                break;
+       }
+       case ELEMSET: {
+               ElementSet *es = (ElementSet *) This;
+               deleteElementEncoding(&es->encoding);
+               break;
+       }
        default:
                ;
        }
        deleteVectorArrayASTNode(GETELEMENTPARENTS(This));
+
        ourfree(This);
 }
index 7886e4c..b5bc9c1 100644 (file)
@@ -4,6 +4,8 @@
 #include "mymemory.h"
 #include "structs.h"
 #include "astnode.h"
+#include "functionencoding.h"
+#include "elementencoding.h"
 
 #define GETELEMENTTYPE(o) GETASTNODETYPE(o)
 #define GETELEMENTPARENTS(o) (&((Element*)o)->parents)
@@ -16,7 +18,7 @@ struct Element {
 struct ElementSet {
        Element base;
        Set * set;
-       ElementEncoding encoding;
+       ElementEncoding encoding;
 };
 
 struct ElementFunction {
@@ -24,6 +26,8 @@ struct ElementFunction {
        Function * function;
        ArrayElement inputs;
        Boolean * overflowstatus;
+       FunctionEncoding functionencoding;
+       ElementEncoding domainencoding;
 };
 
 Element * allocElementSet(Set *s);
index 08385db..ecabd1b 100644 (file)
@@ -1,13 +1,11 @@
 #include "elementencoding.h"
 
-ElementEncoding * allocElementEncoding(ElementEncodingType type, Element *element) {
-       ElementEncoding * This=ourmalloc(sizeof(ElementEncoding));
+void initElementEncoding(ElementEncoding * This, Element *element) {
        This->element=element;
-       This->type=type;
+       This->type=ELEM_UNASSIGNED;
        This->variables=NULL;
        This->encodingArray=NULL;
        This->numVars=0;
-       return This;
 }
 
 void deleteElementEncoding(ElementEncoding *This) {
@@ -17,7 +15,6 @@ void deleteElementEncoding(ElementEncoding *This) {
                ourfree(This->encodingArray);
        if (This->inUseArray!=NULL)
                ourfree(This->inUseArray);
-       ourfree(This);
 }
 
 void allocEncodingArrayElement(ElementEncoding *This, uint size) {
index bc173ea..3ade03b 100644 (file)
@@ -3,7 +3,7 @@
 #include "classlist.h"
 
 enum ElementEncodingType {
-       ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
+       ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
 };
 
 typedef enum ElementEncodingType ElementEncodingType;
@@ -17,7 +17,7 @@ struct ElementEncoding {
        uint numVars;   /* Number of variables */
 };
 
-ElementEncoding * allocElementEncoding(ElementEncodingType type, Element *element);
+void initElementEncoding(ElementEncoding *This, Element *element);
 void deleteElementEncoding(ElementEncoding *This);
 void baseBinaryIndexElementAssign(ElementEncoding *This);
 void allocEncodingArrayElement(ElementEncoding *This, uint size);
index d0f8c3d..32be4ab 100644 (file)
@@ -1,19 +1,14 @@
 #include "functionencoding.h"
 
-FunctionEncoding * allocFunctionEncoding(FunctionEncodingType type, Element *function) {
-       FunctionEncoding * This=ourmalloc(sizeof(FunctionEncoding));
+void initFunctionEncoding(FunctionEncoding *This, Element *function) {
        This->op.function=function;
-       This->type=type;
-       return This;
+       This->type=FUNC_UNASSIGNED;
 }
 
-FunctionEncoding * allocPredicateEncoding(FunctionEncodingType type, Boolean *predicate) {
-       FunctionEncoding * This=ourmalloc(sizeof(FunctionEncoding));
+void initPredicateEncoding(FunctionEncoding *This,  Boolean *predicate) {
        This->op.predicate=predicate;
-       This->type=type;
-       return This;
+       This->type=FUNC_UNASSIGNED;
 }
 
-void deleteFunctionEncoding(FunctionEncoding *fe) {
-       ourfree(fe);
+void deleteFunctionEncoding(FunctionEncoding *This) {
 }
index 63583b6..486d5eb 100644 (file)
@@ -3,7 +3,7 @@
 #include "classlist.h"
 
 enum FunctionEncodingType {
-       ENUMERATEIMPLICATIONS, CIRCUIT
+       FUNC_UNASSIGNED, ENUMERATEIMPLICATIONS, CIRCUIT
 };
 
 typedef enum FunctionEncodingType FunctionEncodingType;
@@ -21,7 +21,7 @@ struct FunctionEncoding {
        ElementPredicate op;
 };
 
-FunctionEncoding * allocFunctionEncoding(FunctionEncodingType type, Element *function);
-FunctionEncoding * allocPredicateEncoding(FunctionEncodingType type, Boolean *predicate);
+void initFunctionEncoding(FunctionEncoding *encoding, Element *function);
+void initPredicateEncoding(FunctionEncoding *encoding, Boolean *predicate);
 void deleteFunctionEncoding(FunctionEncoding *This);
 #endif
diff --git a/src/Encoders/naiveelementencoder.c b/src/Encoders/naiveelementencoder.c
deleted file mode 100644 (file)
index 242a4e7..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "naiveelementencoder.h"
-#include "elementencoding.h"
-#include "element.h"
-#include "set.h"
-#include "common.h"
-#include "structs.h"
-#include <strings.h>
-
-void baseBinaryIndexElementAssign(ElementEncoding *This) {
-       Element * element=This->element;
-       ASSERT(element->type == ELEMSET);
-       Set * set= ((ElementSet*)element)->set;
-       ASSERT(set->isRange==false);
-       uint size=getSizeVectorInt(set->members);
-       uint encSize=NEXTPOW2(size);
-       allocEncodingArrayElement(This, encSize);
-       allocInUseArrayElement(This, encSize);
-
-       for(uint i=0;i<size;i++) {
-               This->encodingArray[i]=getVectorInt(set->members, i);
-               setInUseElement(This, i);
-       }
-}
-
diff --git a/src/Encoders/naiveelementencoder.h b/src/Encoders/naiveelementencoder.h
deleted file mode 100644 (file)
index db4aeb9..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#ifndef NAIVEELEMENTENCODER_H
-#define NAIVEELEMENTENCODER_H
-#include "classlist.h"
-void baseBinaryIndexElementAssign(ElementEncoding *This);
-#endif
diff --git a/src/Encoders/naiveencoder.c b/src/Encoders/naiveencoder.c
new file mode 100644 (file)
index 0000000..ad8a650
--- /dev/null
@@ -0,0 +1,25 @@
+#include "naiveencoder.h"
+#include "elementencoding.h"
+#include "element.h"
+#include "functionencoding.h"
+#include "function.h"
+#include "set.h"
+#include "common.h"
+#include "structs.h"
+#include <strings.h>
+
+void baseBinaryIndexElementAssign(ElementEncoding *This) {
+       Element * element=This->element;
+       ASSERT(element->type == ELEMSET);
+       Set * set= ((ElementSet*)element)->set;
+       ASSERT(set->isRange==false);
+       uint size=getSizeVectorInt(set->members);
+       uint encSize=NEXTPOW2(size);
+       allocEncodingArrayElement(This, encSize);
+       allocInUseArrayElement(This, encSize);
+
+       for(uint i=0;i<size;i++) {
+               This->encodingArray[i]=getVectorInt(set->members, i);
+               setInUseElement(This, i);
+       }
+}
diff --git a/src/Encoders/naiveencoder.h b/src/Encoders/naiveencoder.h
new file mode 100644 (file)
index 0000000..db4aeb9
--- /dev/null
@@ -0,0 +1,5 @@
+#ifndef NAIVEELEMENTENCODER_H
+#define NAIVEELEMENTENCODER_H
+#include "classlist.h"
+void baseBinaryIndexElementAssign(ElementEncoding *This);
+#endif