summaryrefslogtreecommitdiff
path: root/lib/chillcg/src/CG_chillRepr.cc
blob: 044610c12abde86e242ddabc2b29ddbf95ccb09c (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
/*****************************************************************************
 Copyright (C) 2008 University of Southern California. 
 All Rights Reserved.

 Purpose:
   omega holder for chill AST  implementaion

 Notes:

 History:
   02/01/06 - Chun Chen - created
   LLVM/CLANG interface created by Saurav Muralidharan
*****************************************************************************/

#include <code_gen/CG_chillRepr.h>
#include <stdio.h>
#include <stdlib.h>
#include <code_gen/CGdebug.h>

namespace omega { 

  CG_chillRepr::~CG_chillRepr() {
  }
  
  chillAST_Node * CG_chillRepr::GetCode() {
    if (0 == chillnodes.size()) {
      CG_ERROR("No contained chillnodes\n");
      return NULL; // error?
    }

    if (1 == chillnodes.size()) return chillnodes[0];

    CG_DEBUG_PRINT("Creating a compound statements\n");
    chillAST_CompoundStmt *CS = new chillAST_CompoundStmt();
    for (int i=0; i<chillnodes.size(); i++) {
      CS->addChild( chillnodes[i] );
    }
    return CS; 
  }

  CG_outputRepr* CG_chillRepr::clone() const {
    CG_chillRepr *newrepr = new  CG_chillRepr();
    
    for (int i=0; i<chillnodes.size(); i++)
      newrepr->addStatement( chillnodes[i]->clone() );

    return newrepr;
  }

  void CG_chillRepr::clear() {
    chillnodes.clear();
  }

  void CG_chillRepr::dump() const {
    for (int i = 0; i < chillnodes.size(); i++)
      chillnodes[i]->print(0,stdout);
  }

} // namespace