From: Hamed Date: Tue, 27 Jun 2017 18:39:07 +0000 (-0700) Subject: Using inline functions instead of macros for accessing function/element encodings X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=1fb95a0230a6959c8d71d5d049f0ccb90c19e749;p=satune.git Using inline functions instead of macros for accessing function/element encodings --- diff --git a/src/AST/element.c b/src/AST/element.c index 4116cc1..f219072 100644 --- a/src/AST/element.c +++ b/src/AST/element.c @@ -47,9 +47,9 @@ Constraint * getElementValueConstraint(Element* This, uint64_t value) { ElementSet* elemSet= ((ElementSet*)This); uint size = getSetSize(elemSet->set); for(uint i=0; iencodingArray[i]==value){ - return generateBinaryConstraint(GETELEMENTENCODING(elemSet)->numVars, - GETELEMENTENCODING(elemSet)->variables, i); + if( getElementEncoding(elemSet)->encodingArray[i]==value){ + return generateBinaryConstraint(getElementEncoding(elemSet)->numVars, + getElementEncoding(elemSet)->variables, i); } } break; diff --git a/src/AST/element.h b/src/AST/element.h index 3a71686..c0eeaf5 100644 --- a/src/AST/element.h +++ b/src/AST/element.h @@ -10,15 +10,6 @@ #define GETELEMENTTYPE(o) GETASTNODETYPE(o) #define GETELEMENTPARENTS(o) (&((Element*)o)->parents) -#define GETELEMENTENCODING(e) (GETELEMENTTYPE(e)==ELEMSET? \ - &((ElementSet*)e)->encoding: \ - GETELEMENTTYPE(e)==ELEMFUNCRETURN? \ - &((ElementFunction*)e)->domainencoding: NULL) -// Should be called on the element or boolean -#define GETFUNCTIONENCODING(f) (GETASTNODETYPE(f) == ELEMFUNCRETURN? \ - &((ElementFunction*)f)->functionencoding: \ - GETASTNODETYPE(f) == PREDICATEOP? \ - &((BooleanPredicate*)f)->encoding: NULL) struct Element { ASTNode base; @@ -44,6 +35,18 @@ Element * allocElementSet(Set *s); Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus); void deleteElement(Element *This); +inline ElementEncoding* getElementEncoding(Element* This){ + switch(GETELEMENTTYPE(This)){ + case ELEMSET: + return &((ElementSet*)This)->encoding; + case ELEMFUNCRETURN: + return &((ElementFunction*)This)->domainencoding; + default: + ASSERT(0); + } + return NULL; +} + uint getElementSize(Element* This); Constraint * getElementValueConstraint(Element* This, uint64_t value); #endif diff --git a/src/Encoders/functionencoding.h b/src/Encoders/functionencoding.h index a352139..60690e3 100644 --- a/src/Encoders/functionencoding.h +++ b/src/Encoders/functionencoding.h @@ -21,6 +21,18 @@ struct FunctionEncoding { ElementPredicate op; }; +inline FunctionEncoding* getFunctionEncoding(ASTNode func){ + switch(GETASTNODETYPE(func)){ + case ELEMFUNCRETURN: + return &((ElementFunction*)func)->functionencoding; + case PREDICATEOP: + return &((BooleanPredicate*)func)->encoding; + default: + ASSERT(0); + } + return NULL; +} + void initFunctionEncoding(FunctionEncoding *encoding, Element *function); void initPredicateEncoding(FunctionEncoding *encoding, Boolean *predicate); void setFunctionEncodingType(FunctionEncoding* encoding, FunctionEncodingType type); diff --git a/src/Encoders/naiveencoder.c b/src/Encoders/naiveencoder.c index 1d4455d..a4f46a5 100644 --- a/src/Encoders/naiveencoder.c +++ b/src/Encoders/naiveencoder.c @@ -28,12 +28,12 @@ void naiveEncodingDecision(CSolver* csolver, NaiveEncoder* encoder){ Element* element = getVectorElement(csolver->allElements, i); switch(GETELEMENTTYPE(element)){ case ELEMSET: - setElementEncodingType(GETELEMENTENCODING(element), BINARYINDEX); - baseBinaryIndexElementAssign(GETELEMENTENCODING(element)); - generateElementEncodingVariables(encoder,GETELEMENTENCODING(element)); + setElementEncodingType(getElementEncoding(element), BINARYINDEX); + baseBinaryIndexElementAssign(getElementEncoding(element)); + generateElementEncodingVariables(encoder,getElementEncoding(element)); break; case ELEMFUNCRETURN: - setFunctionEncodingType(GETFUNCTIONENCODING(element), ENUMERATEIMPLICATIONS); + setFunctionEncodingType(getFunctionEncoding(element), ENUMERATEIMPLICATIONS); break; default: ASSERT(0); @@ -45,7 +45,7 @@ void naiveEncodingDecision(CSolver* csolver, NaiveEncoder* encoder){ Boolean* predicate = getVectorBoolean(csolver->allBooleans, i); switch(GETBOOLEANTYPE(predicate)){ case PREDICATEOP: - setFunctionEncodingType(GETFUNCTIONENCODING(predicate), ENUMERATEIMPLICATIONS); + setFunctionEncodingType(getFunctionEncoding(predicate), ENUMERATEIMPLICATIONS); break; default: continue; @@ -104,7 +104,7 @@ void encode(CSolver* csolver){ Element* element = getVectorElement(csolver->allElements, i); switch(GETELEMENTTYPE(element)){ case ELEMFUNCRETURN: - naiveEncodeFunctionPredicate(encoder, GETFUNCTIONENCODING(element)); + naiveEncodeFunctionPredicate(encoder, getFunctionEncoding(element)); break; default: continue; @@ -116,7 +116,7 @@ void encode(CSolver* csolver){ Boolean* predicate = getVectorBoolean(csolver->allBooleans, i); switch(GETBOOLEANTYPE(predicate)){ case PREDICATEOP: - naiveEncodeFunctionPredicate(encoder, GETFUNCTIONENCODING(predicate)); + naiveEncodeFunctionPredicate(encoder, getFunctionEncoding(predicate)); break; default: continue;