X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=blobdiff_plain;f=src%2FAST%2Felement.c;fp=src%2FAST%2Felement.c;h=57f7b6a5b27abf9ec8cb661295451c272bad6663;hp=5b9d847fddcd9512140d70dc810fdb40a12e89f9;hb=99ace3f73ea93950e8a8a38c5aa086f1b535cf48;hpb=494125ae2742bcc5c1acd2d617a8533c5506ba97 diff --git a/src/AST/element.c b/src/AST/element.c index 5b9d847..57f7b6a 100644 --- a/src/AST/element.c +++ b/src/AST/element.c @@ -2,6 +2,8 @@ #include "structs.h" #include "set.h" #include "constraint.h" +#include "function.h" +#include "table.h" Element *allocElementSet(Set * s) { ElementSet * tmp=(ElementSet *)ourmalloc(sizeof(ElementSet)); @@ -26,38 +28,48 @@ Element* allocElementFunction(Function * function, Element ** array, uint numArr return &tmp->base; } -uint getElementSize(Element* This){ +Set* getElementSet(Element* This){ switch(GETELEMENTTYPE(This)){ case ELEMSET: - return getSetSize( ((ElementSet*)This)->set ); - break; + return ((ElementSet*)This)->set; case ELEMFUNCRETURN: - ASSERT(0); + ;//Nope is needed for label assignment. i.e. next instruction isn't + Function* func = ((ElementFunction*)This)->function; + switch(GETFUNCTIONTYPE(func)){ + case TABLEFUNC: + return ((FunctionTable*)func)->table->range; + case OPERATORFUNC: + return ((FunctionOperator*)func)->range; + default: + ASSERT(0); + } default: ASSERT(0); } - return -1; + ASSERT(0); + return NULL; } +uint getElemEncodingInUseVarsSize(ElementEncoding* This){ + uint size=0; + for(uint i=0; iencArraySize; i++){ + if(isinUseElement(This, i)){ + size++; + } + } + return size; +} -Constraint * getElementValueConstraint(Element* This, uint64_t value) { - switch(GETELEMENTTYPE(This)){ - case ELEMSET: - ; //Statement is needed for a label and This is a NOPE - uint size = getSetSize(((ElementSet*)This)->set); - //FIXME - for(uint i=0; iencodingArray[i]==value){ - return generateBinaryConstraint(getElementEncoding(This)->numVars, - getElementEncoding(This)->variables, i); - } - } - break; - case ELEMFUNCRETURN: - ASSERT(0); - break; - default: - ASSERT(0); + +Constraint * getElementValueBinaryIndexConstraint(Element* This, uint64_t value) { + ASTNodeType type = GETELEMENTTYPE(This); + ASSERT(type == ELEMSET || type == ELEMFUNCRETURN); + ElementEncoding* elemEnc = getElementEncoding(This); + for(uint i=0; iencArraySize; i++){ + if( isinUseElement(elemEnc, i) && elemEnc->encodingArray[i]==value){ + return generateBinaryConstraint(elemEnc->numVars, + elemEnc->variables, i); + } } ASSERT(0); return NULL;