edits
[satune.git] / src / ASTAnalyses / Encoding / encodinggraph.cc
1 #include "encodinggraph.h"
2 #include "iterator.h"
3 #include "element.h"
4 #include "function.h"
5
6 EncodingGraph::EncodingGraph(CSolver * _solver) :
7         solver(_solver) {
8         
9
10 }
11
12 void EncodingGraph::buildGraph() {
13         ElementIterator it(solver);
14         while(it.hasNext()) {
15                 Element * e = it.next();
16                 switch(e->type) {
17                 case ELEMSET:
18                 case ELEMFUNCRETURN:
19                         processElement(e);
20                         break;
21                 case ELEMCONST:
22                         break;
23                 default:
24                         ASSERT(0);
25                 }
26         }
27 }
28
29 void EncodingGraph::processElement(Element *e) {
30         uint size=e->parents.getSize();
31         for(uint i=0;i<size;i++) {
32                 ASTNode * n = e->parents.get(i);
33                 switch(n->type) {
34                 case PREDICATEOP:
35                         processPredicate((BooleanPredicate *)n);
36                         break;
37                 case ELEMFUNCRETURN:
38                         processFunction((ElementFunction *)n);
39                         break;
40                 default:
41                         ASSERT(0);
42                 }
43         }
44 }
45
46 void EncodingGraph::processFunction(ElementFunction *ef) {
47         Function *f=ef->getFunction();
48         if (f->type==OPERATORFUNC) {
49                 FunctionOperator *fo=(FunctionOperator*)f;
50                 ArithOp op=fo->op;
51         }
52 }
53
54 void EncodingGraph::processPredicate(BooleanPredicate *b) {
55
56 }
57
58 EncodingNode * EncodingGraph::createNode(Element *e) {
59         Set *s = e->getRange();
60         EncodingNode *n = encodingMap.get(s);
61         if (n == NULL) {
62                 n = new EncodingNode(s);
63                 encodingMap.put(s, n);
64         }
65         n->addElement(e);
66         return n;
67 }
68
69 void EncodingNode::addElement(Element *e) {
70         elements.add(e);
71 }
72
73 EncodingEdge::EncodingEdge(EncodingNode *_l, EncodingNode *_r) :
74         left(_l),
75         right(_r),
76         dst(NULL)
77 {
78 }
79
80 EncodingEdge::EncodingEdge(EncodingNode *_left, EncodingNode *_right, EncodingNode *_dst) :
81         left(_left),
82         right(_right),
83         dst(_dst)
84 {
85 }
86
87 uint hashEncodingEdge(EncodingEdge *edge) {
88         uintptr_t hash=(((uintptr_t) edge->left) >> 2) ^ (((uintptr_t)edge->right) >> 4) ^ (((uintptr_t)edge->dst) >> 6);
89         return (uint) hash;
90 }
91
92 bool equalsEncodingEdge(EncodingEdge *e1, EncodingEdge *e2) {
93         return e1->left == e2->left && e1->right == e2->right && e1->dst == e2->dst;
94 }