From 66ab53e7949882740909d130a3f6e5c44bbe7653 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 16 Jun 2017 22:54:03 -0700 Subject: [PATCH] Use union in Boolean to save space --- src/AST/boolean.c | 14 +++++++------- src/AST/boolean.h | 35 +++++++++++++++++++++++++++++----- src/AST/ops.h | 2 +- src/Encoders/elementencoding.c | 7 +++++++ src/Encoders/elementencoding.h | 3 +++ src/classlist.h | 6 ++++++ 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/AST/boolean.c b/src/AST/boolean.c index a7ffd25..aaebba7 100644 --- a/src/AST/boolean.c +++ b/src/AST/boolean.c @@ -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; } diff --git a/src/AST/boolean.h b/src/AST/boolean.h index 030e1d9..87d7a49 100644 --- a/src/AST/boolean.h +++ b/src/AST/boolean.h @@ -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 diff --git a/src/AST/ops.h b/src/AST/ops.h index 40febd4..7fdf2f3 100644 --- a/src/AST/ops.h +++ b/src/AST/ops.h @@ -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 diff --git a/src/Encoders/elementencoding.c b/src/Encoders/elementencoding.c index b97fee0..095f99d 100644 --- a/src/Encoders/elementencoding.c +++ b/src/Encoders/elementencoding.c @@ -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); } diff --git a/src/Encoders/elementencoding.h b/src/Encoders/elementencoding.h index b94632c..eb20f2b 100644 --- a/src/Encoders/elementencoding.h +++ b/src/Encoders/elementencoding.h @@ -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); diff --git a/src/classlist.h b/src/classlist.h index f38b44b..f722a6e 100644 --- a/src/classlist.h +++ b/src/classlist.h @@ -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; -- 2.34.1