Use union in Boolean to save space
authorbdemsky <bdemsky@uci.edu>
Sat, 17 Jun 2017 05:54:03 +0000 (22:54 -0700)
committerbdemsky <bdemsky@uci.edu>
Sat, 17 Jun 2017 05:54:03 +0000 (22:54 -0700)
src/AST/boolean.c
src/AST/boolean.h
src/AST/ops.h
src/Encoders/elementencoding.c
src/Encoders/elementencoding.h
src/classlist.h

index a7ffd25..aaebba7 100644 (file)
@@ -2,17 +2,17 @@
 
 Boolean* allocBoolean(VarType t) {
        Boolean* tmp=(Boolean*) ourmalloc(sizeof (Boolean));
-       tmp->vtype=t;
-       tmp->btype=_BOOLEAN;
+       tmp->btype=BOOLEANVAR;
+       tmp->var.vtype=t;
        return tmp;
 }
 
-Boolean* allocBooleanOrder(Order* order,uint64_t first, uint64_t second) {
+Boolean* allocBooleanOrder(Order* order, uint64_t first, uint64_t second) {
        Boolean* tmp=(Boolean*) ourmalloc(sizeof (Boolean));
-       tmp->btype=_ORDER;
-       tmp->order=order;
-       tmp->first=first;
-       tmp->second=second;
+       tmp->btype=ORDERCONST;
+       tmp->order.order=order;
+       tmp->order.first=first;
+       tmp->order.second=second;
        return tmp;
 }
 
index 030e1d9..87d7a49 100644 (file)
@@ -3,16 +3,41 @@
 #include "classlist.h"
 #include "mymemory.h"
 #include "ops.h"
-struct  Boolean {
-       VarType vtype;
-       enum BooleanType btype;
+
+struct BooleanOrder {
        Order* order;
        uint64_t first;
        uint64_t second;
 };
 
-Boolean* allocBoolean(VarType t);
-Boolean* allocBooleanOrder(Order* order,uint64_t first, uint64_t second);
+struct BooleanVar {
+       VarType vtype;
+};
+
+struct BooleanLogic {
+       LogicOp op;
+       Boolean * left;
+       Boolean * right;
+};
+
+struct BooleanComp {
+       CompOp op;
+       Boolean * left;
+       Boolean * right;
+};
+
+struct Boolean {
+       BooleanType btype;
+       union {
+               BooleanOrder order;
+               BooleanVar var;
+               BooleanLogic logic;
+               BooleanComp comp;
+       };
+};
+
+Boolean * allocBoolean(VarType t);
+Boolean * allocBooleanOrder(Order * order, uint64_t first, uint64_t second);
 void deleteBoolean(Boolean * this);
 
 #endif
index 40febd4..7fdf2f3 100644 (file)
@@ -15,6 +15,6 @@ enum OrderType {PARTIAL, TOTAL};
  */
 enum OverFlowBehavior {IGNORE, WRAPAROUND, FLAGFORCESOVERFLOW, OVERFLOWSETSFLAG, FLAGIFFOVERFLOW, NOOVERFLOW};
 
-enum BooleanType {_ORDER, _BOOLEAN};
+enum BooleanType {ORDERCONST, BOOLEANVAR, LOGICOP, COMPARE};
 
 #endif
index b97fee0..095f99d 100644 (file)
@@ -4,9 +4,16 @@ ElementEncoding * allocElementEncoding(ElementEncodingType type, Element *elemen
        ElementEncoding * this=(ElementEncoding *)ourmalloc(sizeof(ElementEncoding));
        this->element=element;
        this->type=type;
+       this->variables=NULL;
+       this->encodingArray=NULL;
+       this->numVars=0;
        return this;
 }
 
 void deleteElementEncoding(ElementEncoding *this) {
+       if (this->variables!=NULL)
+               ourfree(this->variables);
+       if (this->encodingArray!=NULL)
+               ourfree(this->encodingArray);
        ourfree(this);
 }
index b94632c..eb20f2b 100644 (file)
@@ -11,6 +11,9 @@ typedef enum ElementEncodingType ElementEncodingType;
 struct ElementEncoding {
        ElementEncodingType type;
        Element * element;
+       Boolean ** variables; /* List Variables Use To Encode Element */
+       uint64_t * encodingArray; /* List the Variables in the appropriate order */
+       uint numVars; /* Number of variables */
 };
 
 ElementEncoding * allocElementEncoding(ElementEncodingType type, Element *element);
index f38b44b..f722a6e 100644 (file)
@@ -22,6 +22,11 @@ typedef struct CSolver CSolver;
 struct Constraint;
 typedef struct Constraint Constraint;
 
+typedef struct BooleanOrder BooleanOrder;
+typedef struct BooleanVar BooleanVar;
+typedef struct BooleanLogic BooleanLogic;
+typedef struct BooleanComp BooleanComp;
+
 struct Boolean;
 typedef struct Boolean Boolean;
 
@@ -62,6 +67,7 @@ typedef enum ArithOp ArithOp;
 typedef enum LogicOp LogicOp;
 typedef enum CompOp CompOp;
 typedef enum OrderType OrderType;
+typedef enum BooleanType BooleanType;
 typedef enum OverFlowBehavior OverFlowBehavior;
 
 typedef unsigned int uint;