Merge branch 'hamed' of ssh://plrg.eecs.uci.edu/home/git/constraint_compiler
[satune.git] / src / AST / element.cc
1 #include "element.h"
2 #include "structs.h"
3 #include "set.h"
4 #include "constraint.h"
5 #include "function.h"
6 #include "table.h"
7
8 Element::Element(ASTNodeType _type) : ASTNode(_type) {
9         initDefVectorASTNode(GETELEMENTPARENTS(this));
10         initElementEncoding(&encoding, (Element *) this);
11 }
12
13 ElementSet::ElementSet(Set *s) : Element(ELEMSET), set(s) {
14 }
15
16 ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, Boolean *_overflowstatus) : Element(ELEMFUNCRETURN), function(_function), overflowstatus(_overflowstatus) {
17         initArrayInitElement(&inputs, array, numArrays);
18         for (uint i = 0; i < numArrays; i++)
19                 pushVectorASTNode(GETELEMENTPARENTS(array[i]), this);
20         initFunctionEncoding(&functionencoding, this);
21 }
22
23 ElementConst::ElementConst(uint64_t _value, VarType _type) : Element(ELEMCONST), value(_value) {
24         uint64_t array[]={value};
25         set = allocSet(_type, array, 1);
26 }
27
28 Set *getElementSet(Element *This) {
29         switch (GETELEMENTTYPE(This)) {
30         case ELEMSET:
31                 return ((ElementSet *)This)->set;
32         case ELEMCONST:
33                 return ((ElementConst *)This)->set;
34         case ELEMFUNCRETURN: {
35                 Function *func = ((ElementFunction *)This)->function;
36                 switch (GETFUNCTIONTYPE(func)) {
37                 case TABLEFUNC:
38                         return ((FunctionTable *)func)->table->range;
39                 case OPERATORFUNC:
40                         return ((FunctionOperator *)func)->range;
41                 default:
42                         ASSERT(0);
43                 }
44         }
45         default:
46                 ASSERT(0);
47         }
48         ASSERT(0);
49         return NULL;
50 }
51
52 ElementFunction::~ElementFunction() {
53         deleteInlineArrayElement(&inputs);
54         deleteFunctionEncoding(&functionencoding);
55 }
56
57 ElementConst::~ElementConst() {
58         deleteSet(set);
59 }
60
61 Element::~Element() {
62         deleteElementEncoding(&encoding);
63         deleteVectorArrayASTNode(GETELEMENTPARENTS(this));
64 }