Resolving Conflicts ... Still there're errors that should be fixed
[satune.git] / src / Encoders / naiveencoder.c
1 #include "naiveencoder.h"
2 #include "elementencoding.h"
3 #include "element.h"
4 #include "functionencoding.h"
5 #include "function.h"
6 #include "set.h"
7 #include "common.h"
8 #include "structs.h"
9 #include <strings.h>
10
11 void baseBinaryIndexElementAssign(ElementEncoding *This) {
12         Element * element=This->element;
13         ASSERT(element->type == ELEMSET);
14         Set * set= ((ElementSet*)element)->set;
15         ASSERT(set->isRange==false);
16         uint size=getSizeVectorInt(set->members);
17         uint encSize=NEXTPOW2(size);
18         allocEncodingArrayElement(This, encSize);
19         allocInUseArrayElement(This, encSize);
20
21         for(uint i=0;i<size;i++) {
22                 This->encodingArray[i]=getVectorInt(set->members, i);
23                 setInUseElement(This, i);
24         }
25 }
26
27
28 void naiveEncodeFunctionPredicate(Encodings* encodings, FunctionEncoding *This){
29         if(This->isFunction) {
30                 ASSERT(GETELEMENTTYPE(This->op.function)==ELEMFUNCRETURN);
31                 if(This->type==CIRCUIT){
32                         naiveEncodeCircuitFunction(encodings, This);
33                 } else if( This->type == ENUMERATEIMPLICATIONS){
34                         naiveEncodeEnumeratedFunction(encodings, This);
35                 } else
36                         ASSERT(0);
37                         
38         }else {
39                 ASSERT(GETBOOLEANTYPE(This->op.predicate) == PREDICATEOP);
40                 BooleanPredicate* predicate = (BooleanPredicate*)This->op.predicate;
41                 //FIXME
42                 
43         }
44 }
45
46
47 void naiveEncodeCircuitFunction(Encodings* encodings, FunctionEncoding* This){
48         
49 }
50
51 void naiveEncodeEnumeratedFunction(Encodings* encodings, FunctionEncoding* This){
52         ElementFunction* ef =(ElementFunction*)This->op.function;
53         Function * function = ef->function;
54         if(GETFUNCTIONTYPE(function)==TABLEFUNC){
55                 naiveEncodeEnumTableFunc(encodings, ef);
56         }else if (GETFUNCTIONTYPE(function)== OPERATORFUNC){
57                 naiveEncodeEnumOperatingFunc(encodings, ef);
58         }else 
59                 ASSERT(0);
60 }
61
62 void naiveEncodeEnumTableFunc(Encodings* encodings, ElementFunction* This){
63         ASSERT(GETFUNCTIONTYPE(This->function)==TABLEFUNC);
64         ArrayElement* elements= &This->inputs;
65         Table* table = ((FunctionTable*) (This->function))->table;
66         uint size = getSizeVectorTableEntry(&table->entries);
67         for(uint i=0; i<size; i++){
68                 TableEntry* entry = getVectorTableEntry(&table->entries, i);
69                 //FIXME: generate Constraints
70         }
71         
72 }
73
74 void naiveEncodeEnumOperatingFunc(Encodings* encodings, ElementFunction* This){
75         
76 }