Fix warnings, merge, and check my code in
authorbdemsky <bdemsky@uci.edu>
Tue, 20 Jun 2017 01:51:52 +0000 (18:51 -0700)
committerbdemsky <bdemsky@uci.edu>
Tue, 20 Jun 2017 01:51:52 +0000 (18:51 -0700)
15 files changed:
design/notes.txt
src/AST/element.c
src/AST/element.h
src/AST/function.c
src/AST/function.h
src/AST/ops.h
src/Backend/constraint.h
src/Backend/satencoder.c [new file with mode: 0644]
src/Backend/satencoder.h [new file with mode: 0644]
src/Encoders/elementencoding.c
src/Encoders/functionencoding.c
src/Encoders/orderencoding.c [new file with mode: 0644]
src/Encoders/orderencoding.h [new file with mode: 0644]
src/classlist.h
src/csolver.c

index 1159c96..ce399c3 100644 (file)
@@ -6,3 +6,6 @@
 
 (4) Might need to indicate what variables we can query about in
 future?
+
+(5) Could simplify output of functions...  Maybe several outputs have
+same effect...
index 45117e1..df29cfe 100644 (file)
@@ -3,6 +3,7 @@
 Element *allocElement(Set * s) {
        Element * tmp=(Element *)ourmalloc(sizeof(Element));
        tmp->set=s;
+       tmp->encoding=NULL;
        return tmp;
 }
 
index 6cbf94c..91d19db 100644 (file)
@@ -5,6 +5,7 @@
 
 struct Element {
        Set * set;
+       ElementEncoding * encoding;
 };
 
 Element * allocElement(Set *s);
index c9d0717..c816363 100644 (file)
@@ -4,30 +4,31 @@
 
 
 Function* allocFunctionOperator( ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior){
-    FunctionOperator* This = (FunctionOperator*) ourmalloc(sizeof(FunctionOperator));
-    GETFUNCTIONTYPE(This)=OPERATORFUNC;
-    This->domains = allocVectorArraySet(numDomain, domain);
-    This->op=op;
-    This->overflowbehavior = overflowbehavior;
-    This->range=range;
-    return  &This->base;
+       FunctionOperator* This = (FunctionOperator*) ourmalloc(sizeof(FunctionOperator));
+       GETFUNCTIONTYPE(This)=OPERATORFUNC;
+       This->domains = allocVectorArraySet(numDomain, domain);
+       This->op=op;
+       This->overflowbehavior = overflowbehavior;
+       This->range=range;
+       return &This->base;
 }
 
 Function* allocFunctionTable (Table* table){
-    FunctionTable* This = (FunctionTable*) ourmalloc(sizeof(FunctionTable));
-    GETFUNCTIONTYPE(This)=TABLEFUNC;
-    This->table = table;
+       FunctionTable* This = (FunctionTable*) ourmalloc(sizeof(FunctionTable));
+       GETFUNCTIONTYPE(This)=TABLEFUNC;
+       This->table = table;
+       return &This->base;
 }
 
 void deleteFunction(Function* This){
-    switch( GETFUNCTIONTYPE(This)){
+       switch(GETFUNCTIONTYPE(This)){
        case TABLEFUNC:
-           ourfree((FunctionTable*)This);
-           break;
+               ourfree((FunctionTable*)This);
+               break;
        case OPERATORFUNC:
-           ourfree((FunctionOperator*) This);
-           break;
+               ourfree((FunctionOperator*) This);
+               break;
        default:
-           ASSERT(0);
-    }
+               ASSERT(0);
+       }
 }
index e22ec75..3f2a1a9 100644 (file)
@@ -5,7 +5,6 @@
 #include "ops.h"
 #include "structs.h"
 
-
 #define GETFUNCTIONTYPE(o) (((Function*)o)->type)
 
 struct Function{
index 63da885..b330d1b 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef OPS_H
 #define OPS_H
-enum LogicOp {AND, OR, NOT, XOR, IMPLIES};
+enum LogicOp {L_AND, L_OR, L_NOT, L_XOR, L_IMPLIES};
 typedef enum LogicOp LogicOp;
 
 enum ArithOp {ADD, SUB};
index 4b59812..d6e7e86 100644 (file)
@@ -33,15 +33,15 @@ Constraint * allocVarConstraint(CType t, uint var);
 void deleteConstraint(Constraint *);
 void printConstraint(Constraint * c);
 void dumpConstraint(Constraint * c, IncrementalSolver *solver);
-uint getVarConstraint(Constraint * c) {ASSERT(c->type==VAR); return c->numoperandsorvar;}
+inline uint getVarConstraint(Constraint * c) {ASSERT(c->type==VAR); return c->numoperandsorvar;}
 VectorConstraint * simplify(Constraint * c);
-CType getType(Constraint * c) {return c->type;}
-bool isFalse(Constraint * c) {return c->type==FALSE;}
-bool isTrue(Constraint * c) {return c->type==TRUE;}
+inline CType getType(Constraint * c) {return c->type;}
+inline bool isFalse(Constraint * c) {return c->type==FALSE;}
+inline bool isTrue(Constraint * c) {return c->type==TRUE;}
 void internalfreeConstraint(Constraint * c);
 void freerecConstraint(Constraint * c);
 Constraint * cloneConstraint(Constraint * c);
-void setNegConstraint(Constraint * This, Constraint *c) {This->neg=c;}
+inline void setNegConstraint(Constraint * This, Constraint *c) {This->neg=c;}
 Constraint *negateConstraint(Constraint * c);
 
 extern Constraint ctrue;
diff --git a/src/Backend/satencoder.c b/src/Backend/satencoder.c
new file mode 100644 (file)
index 0000000..3b34c3a
--- /dev/null
@@ -0,0 +1,73 @@
+#include "satencoder.h"
+#include "structs.h"
+#include "csolver.h"
+#include "boolean.h"
+#include "constraint.h"
+
+SATEncoder * allocSATEncoder() {
+       SATEncoder *This=ourmalloc(sizeof (SATEncoder));
+       return This;
+}
+
+void deleteSATEncoder(SATEncoder *This) {
+       ourfree(This);
+}
+
+void encodeAllSATEncoder(SATEncoder * This, CSolver *csolver) {
+       VectorBoolean *constraints=csolver->constraints;
+       uint size=getSizeVectorBoolean(constraints);
+       for(uint i=0;i<size;i++) {
+               Boolean *constraint=getVectorBoolean(constraints, i);
+               encodeConstraintSATEncoder(This, constraint);
+       }
+}
+
+Constraint * encodeConstraintSATEncoder(SATEncoder *This, Boolean *constraint) {
+       switch(constraint->btype) {
+       case ORDERCONST:
+               return encodeOrderSATEncoder(This, (BooleanOrder *) constraint);
+       case BOOLEANVAR:
+               return encodeVarSATEncoder(This, (BooleanVar *) constraint);
+       case LOGICOP:
+               return encodeLogicSATEncoder(This, (BooleanLogic *) constraint);
+       case COMPARE:
+               return encodeCompareSATEncoder(This, (BooleanComp *) constraint);
+       }
+}
+
+Constraint * encodeOrderSATEncoder(SATEncoder *This, BooleanOrder * constraint) {
+       return NULL;
+}
+
+Constraint * encodeVarSATEncoder(SATEncoder *This, BooleanVar * constraint) {
+       return NULL;
+}
+
+Constraint * encodeLogicSATEncoder(SATEncoder *This, BooleanLogic * constraint) {
+       Constraint *left=encodeConstraintSATEncoder(This, constraint->left);
+       Constraint *right=NULL;
+       if (constraint->right!=NULL)
+               right=encodeConstraintSATEncoder(This, constraint->right);
+       switch(constraint->op) {
+       case L_AND:
+               return allocConstraint(AND, left, right);
+       case L_OR:
+               return allocConstraint(OR, left, right);
+       case L_NOT:
+               return negateConstraint(allocConstraint(OR, left, NULL));
+       case L_XOR: {
+               Constraint * nleft=negateConstraint(cloneConstraint(left));
+               Constraint * nright=negateConstraint(cloneConstraint(right));
+               return allocConstraint(OR,
+                                                                                                        allocConstraint(AND, left, nright),
+                                                                                                        allocConstraint(AND, nleft, right));
+       }
+       case L_IMPLIES:
+               return allocConstraint(IMPLIES, left, right);
+       }
+       return NULL;
+}
+
+Constraint * encodeCompareSATEncoder(SATEncoder *This, BooleanComp * constraint) {
+       return NULL;
+}
diff --git a/src/Backend/satencoder.h b/src/Backend/satencoder.h
new file mode 100644 (file)
index 0000000..a612930
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef SATENCODER_H
+#define SATENCODER_H
+
+#include "classlist.h"
+
+struct SATEncoder {
+
+};
+
+
+SATEncoder * allocSATEncoder();
+void deleteSATEncoder(SATEncoder *This);
+void encodeAllSATEncoder(SATEncoder *This, CSolver *csolver);
+Constraint * encodeConstraintSATEncoder(SATEncoder *This, Boolean *constraint);
+Constraint * encodeOrderSATEncoder(SATEncoder *This, BooleanOrder * constraint);
+Constraint * encodeVarSATEncoder(SATEncoder *This, BooleanVar * constraint);
+Constraint * encodeLogicSATEncoder(SATEncoder *This, BooleanLogic * constraint);
+Constraint * encodeCompareSATEncoder(SATEncoder *This, BooleanComp * constraint);
+
+#endif
index fb2ce4a..08385db 100644 (file)
@@ -1,7 +1,7 @@
 #include "elementencoding.h"
 
 ElementEncoding * allocElementEncoding(ElementEncodingType type, Element *element) {
-       ElementEncoding * This=(ElementEncoding *)ourmalloc(sizeof(ElementEncoding));
+       ElementEncoding * This=ourmalloc(sizeof(ElementEncoding));
        This->element=element;
        This->type=type;
        This->variables=NULL;
index 4520fa0..d0f8c3d 100644 (file)
@@ -1,14 +1,14 @@
 #include "functionencoding.h"
 
 FunctionEncoding * allocFunctionEncoding(FunctionEncodingType type, Element *function) {
-       FunctionEncoding * This=(FunctionEncoding *)ourmalloc(sizeof(FunctionEncoding));
+       FunctionEncoding * This=ourmalloc(sizeof(FunctionEncoding));
        This->op.function=function;
        This->type=type;
        return This;
 }
 
 FunctionEncoding * allocPredicateEncoding(FunctionEncodingType type, Boolean *predicate) {
-       FunctionEncoding * This=(FunctionEncoding *)ourmalloc(sizeof(FunctionEncoding));
+       FunctionEncoding * This=ourmalloc(sizeof(FunctionEncoding));
        This->op.predicate=predicate;
        This->type=type;
        return This;
diff --git a/src/Encoders/orderencoding.c b/src/Encoders/orderencoding.c
new file mode 100644 (file)
index 0000000..3cd78e1
--- /dev/null
@@ -0,0 +1,12 @@
+#include "orderencoding.h"
+
+OrderEncoding * allocOrderEncoding(OrderEncodingType type, Order *order) {
+       OrderEncoding *This=ourmalloc(sizeof(OrderEncoding));
+       This->type=type;
+       This->order=order;
+       return This;
+}
+
+void deleteOrderEncoding(OrderEncoding *This) {
+       ourfree(This);
+}
diff --git a/src/Encoders/orderencoding.h b/src/Encoders/orderencoding.h
new file mode 100644 (file)
index 0000000..89c436a
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef ORDERENCODING_H
+#define ORDERENCODING_H
+#include "classlist.h"
+
+enum OrderEncodingType {
+       PAIRWISE
+};
+
+typedef enum OrderEncodingType OrderEncodingType;
+
+struct OrderEncoding {
+       OrderEncodingType type;
+       Order *order;
+};
+
+OrderEncoding * allocOrderEncoding(OrderEncodingType type, Order *order);
+void deleteOrderEncoding(OrderEncoding *This);
+
+#endif
index 6de8bcf..237d529 100644 (file)
@@ -18,6 +18,9 @@
 
 struct CSolver;
 typedef struct CSolver CSolver;
+struct SATEncoder;
+typedef struct SATEncoder SATEncoder;
+
 
 struct Constraint;
 typedef struct Constraint Constraint;
@@ -35,7 +38,6 @@ typedef struct IncrementalSolver IncrementalSolver;
 
 struct Set;
 typedef struct Set Set;
-
 typedef struct Set MutableSet;
 
 struct Element;
@@ -62,6 +64,9 @@ typedef struct ElementEncoding ElementEncoding;
 struct FunctionEncoding;
 typedef struct FunctionEncoding FunctionEncoding;
 
+struct OrderEncoding;
+typedef struct OrderEncoding OrderEncoding;
+
 struct TableEntry;
 typedef struct TableEntry TableEntry;
 
index 62f4acd..7a9d1e0 100644 (file)
@@ -61,7 +61,7 @@ void deleteSolver(CSolver *This) {
        for(uint i=0;i<size;i++) {
                deleteFunction(getVectorFunction(This->allFunctions, i));
        }
-       deleteVectorOrder(This->allFunctions);
+       deleteVectorFunction(This->allFunctions);
        ourfree(This);
 }