summaryrefslogtreecommitdiff
path: root/lib/chillcg/include/code_gen/CG_chillRepr.h
blob: ea2048b75e72e6628c3b3c903468842a6c3c96a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

#ifndef CG_chillRepr_h
#define CG_chillRepr_h

//                                               Repr using chillAst internally
#include <stdio.h>
#include <string.h>
#include <code_gen/CG_outputRepr.h>

#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS 
#endif


#include "chillAST/chillASTs.hh"


namespace omega {

  class CG_chillRepr : public CG_outputRepr {
    friend class CG_chillBuilder;

  public:
    CG_chillRepr() { stmtclassname = strdup("NOTHING"); }


    char *type() const { return strdup("chill"); };
    //
    std::vector<chillAST_Node *> chillnodes;  // TODO make private
    void printChillNodes() const {
      for (int i = 0; i < chillnodes.size(); i++)
        chillnodes[i]->print();
      fflush(stdout);
    };

    CG_chillRepr(std::vector<chillAST_Node *> cnodes) {
      chillnodes = cnodes;
    }

    CG_chillRepr(chillAST_Node *chillast) {
      stmtclassname = strdup(chillast->getTypeString());
      if (chillast->getType() == CHILLAST_NODE_COMPOUNDSTMT) {
        std::vector<chillAST_Node *> &children = *(chillast->getChildren());
        int numchildren = children.size();
        for (int i = 0; i < numchildren; i++) {
          chillnodes.push_back(children[i]);
        }
      } else { // for now, assume it's a single statement
        chillnodes.push_back(chillast);  // ??
      }
    }

    void addStatement(chillAST_Node *s) { chillnodes.push_back(s); };

    std::vector<chillAST_Node *> getChillCode() const { return chillnodes; };

    chillAST_Node *GetCode();


    ~CG_chillRepr();

    CG_outputRepr *clone() const;

    void clear();


    //---------------------------------------------------------------------------
    // Dump operations
    //---------------------------------------------------------------------------
    void dump() const { printChillNodes(); };

    void Dump() const;
  private:

    char *stmtclassname;    // chill
  };


} // namespace

#endif