From 2028f3ddc680b3af6476ace8840d6bcc85b88d73 Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Fri, 30 Sep 2016 15:34:03 -0600 Subject: children cont. --- include/chillAST/chillAST_node.hh | 2 +- include/chillAST/chillASTs.hh | 318 +++--------------------- lib/chillcg/src/CG_chillBuilder.cc | 10 +- src/ast/node.cpp | 10 - src/chillASTs.cc | 481 +++++-------------------------------- src/ir_clang.cc | 12 +- src/printer/cfamily.cpp | 20 +- src/printer/dump.cpp | 24 +- 8 files changed, 129 insertions(+), 748 deletions(-) diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh index ea9bf8b..ce099e8 100644 --- a/include/chillAST/chillAST_node.hh +++ b/include/chillAST/chillAST_node.hh @@ -313,7 +313,7 @@ public: virtual void gatherVarDeclsMore(std::vector &decls) { // even if the decl itself is not in the ast. - fprintf(stderr, "(%s) forgot to implement gatherVarDeclsMore()\n", getTypeString()); + gatherVarDecls(decls); }; //! Actual declaration diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index 90f19e8..bbfeba4 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -173,8 +173,6 @@ public: void gatherVarDecls(std::vector &decls); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls); void gatherArrayVarDecls(std::vector &decls); @@ -290,8 +288,6 @@ public: void gatherVarDecls(std::vector &decls); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls); void gatherArrayVarDecls(std::vector &decls); @@ -410,8 +406,6 @@ public: void gatherVarDecls(std::vector &decls); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls); void gatherArrayVarDecls(std::vector &decls); @@ -512,8 +506,6 @@ public: // none of these make sense for macros void gatherVarDecls(std::vector &decls) {}; - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls) {}; void gatherArrayVarDecls(std::vector &decls) {}; @@ -573,8 +565,6 @@ public: chillAST_Node *clone(); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false); void gatherLoopIndeces(std::vector &indeces); @@ -656,8 +646,6 @@ public: chillAST_Node *clone(); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherVarLHSUsage(std::vector &decls); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, @@ -739,8 +727,6 @@ public: void gatherArrayRefs(std::vector &refs, bool writtento); // chillAST_BinaryOperator void gatherScalarRefs(std::vector &refs, bool writtento); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherVarLHSUsage(std::vector &decls); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, @@ -796,8 +782,6 @@ public: void gatherVarDecls(std::vector &decls); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls); void gatherArrayVarDecls(std::vector &decls); @@ -855,8 +839,6 @@ public: void gatherVarDecls(std::vector &decls); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls); void gatherArrayVarDecls(std::vector &decls); @@ -904,7 +886,6 @@ public: void gatherScalarRefs(std::vector &refs, bool writtento) {}; // does nothing void gatherVarDecls(std::vector &decls) {}; // does nothing - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; void gatherScalarVarDecls(std::vector &decls) {}; // does nothing void gatherArrayVarDecls(std::vector &decls) {}; // does nothing @@ -949,8 +930,6 @@ public: void gatherScalarRefs(std::vector &refs, bool writtento) {}; // does nothing void gatherVarDecls(std::vector &decls) {}; // does nothing - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls) {}; // does nothing ; void gatherArrayVarDecls(std::vector &decls) {}; // does nothing ; @@ -992,8 +971,6 @@ public: chillAST_Node *clone(); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherArrayRefs(std::vector &refs, bool writtento); // chillAST_UnaryOperator void gatherVarLHSUsage(std::vector &decls); @@ -1010,10 +987,8 @@ class chillAST_ImplicitCastExpr : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_IMPLICITCASTEXPR; } - // variables that are special for this type of node - chillAST_Node *subexpr; - // constructors + chillAST_ImplicitCastExpr(); chillAST_ImplicitCastExpr(chillAST_Node *sub); // other methods particular to this type of node @@ -1021,29 +996,12 @@ public: bool isLeaf() { return false; }; - // required methods that I can't seem to get to inherit - void replaceChild(chillAST_Node *old, chillAST_Node *newchild); - - chillAST_Node *constantFold(); + chillAST_Node* getSubExpr() { return getChild(0); } + void setSubExpr(chillAST_Node* sub) { return setChild(0,sub); } + // required methods that I can't seem to get to inherit chillAST_Node *clone(); - void gatherArrayRefs(std::vector &refs, bool writtento); - - void gatherScalarRefs(std::vector &refs, bool writtento); - - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - - void gatherVarUsage(std::vector &decls); - - void gatherDeclRefExprs(std::vector &refs); - //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here @@ -1058,42 +1016,23 @@ public: // variables that are special for this type of node //! String representing the type it casts to char *towhat; - chillAST_Node *subexpr; // constructors + chillAST_CStyleCastExpr(); chillAST_CStyleCastExpr(const char *to, chillAST_Node *sub); // other methods particular to this type of node // required methods that I can't seem to get to inherit - void replaceChild(chillAST_Node *old, chillAST_Node *newchild); - - chillAST_Node *constantFold(); + chillAST_Node* getSubExpr() { return getChild(0); } + void setSubExpr(chillAST_Node* sub) { return setChild(0,sub); } chillAST_Node *clone(); - void gatherArrayRefs(std::vector &refs, bool writtento); - - void gatherScalarRefs(std::vector &refs, bool writtento); - - void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - - void gatherVarUsage(std::vector &decls); - - void gatherDeclRefExprs(std::vector &refs); - bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here - chillAST_Node *findref() { return subexpr; };// find the SINGLE constant or data reference at this node or below + chillAST_Node *findref() { return getSubExpr(); };// find the SINGLE constant or data reference at this node or below }; @@ -1102,35 +1041,19 @@ public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_CSTYLEADDRESSOF; } // variables that are special for this type of node - chillAST_Node *subexpr; // constructors + chillAST_CStyleAddressOf(); chillAST_CStyleAddressOf(chillAST_Node *sub); // other methods particular to this type of node + chillAST_Node* getSubExpr() { return getChild(0); } + void setSubExpr(chillAST_Node* sub) { return setChild(0,sub); } // required methods that I can't seem to get to inherit - chillAST_Node *constantFold(); - chillAST_Node *clone(); - void gatherArrayRefs(std::vector &refs, bool writtento); - - void gatherScalarRefs(std::vector &refs, bool writtento); - - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - - void gatherVarUsage(std::vector &decls); - - void gatherDeclRefExprs(std::vector &refs); - //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here @@ -1142,47 +1065,36 @@ class chillAST_CudaMalloc : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_CUDAMALLOC; } - // variables that are special for this type of node - chillAST_Node *devPtr; // Pointer to allocated device memory - chillAST_Node *sizeinbytes; - // constructors + chillAST_CudaMalloc(); chillAST_CudaMalloc(chillAST_Node *devmemptr, chillAST_Node *size); // other methods particular to this type of node + chillAST_Node* getDevPtr() {return getChild(0);} + void setDevPtr(chillAST_Node* devptr) { setChild(0,devptr);} + chillAST_Node* getSize() {return getChild(1);} + void setSize(chillAST_Node* size) { setChild(1,size);} // required methods that I can't seem to get to inherit - chillAST_Node *constantFold(); - chillAST_Node *clone(); void gatherArrayRefs(std::vector &refs, bool writtento); void gatherScalarRefs(std::vector &refs, bool writtento); - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - - void gatherVarUsage(std::vector &decls); - - //void gatherDeclRefExprs( std::vector&refs ); - //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here }; +//! CudaFree class chillAST_CudaFree : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_CUDAFREE; } // variables that are special for this type of node + // TODO Seriously wrong, this is not a new variable declaration chillAST_VarDecl *variable; // constructors @@ -1202,8 +1114,6 @@ public: void gatherVarDecls(std::vector &decls); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls); void gatherArrayVarDecls(std::vector &decls); @@ -1222,35 +1132,18 @@ public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_MALLOC; } // variables that are special for this type of node - //! The subexpression calculating bytes - chillAST_Node *sizeexpr; // bytes // constructors + chillAST_Malloc(); chillAST_Malloc(chillAST_Node *numthings); // malloc (sizeof(int) *1024) // other methods particular to this type of node + chillAST_Node* getSize() { return getChild(0); } + void setSize(chillAST_Node* size) { setChild(0,size); } // required methods that I can't seem to get to inherit - chillAST_Node *constantFold(); - chillAST_Node *clone(); - void gatherArrayRefs(std::vector &refs, bool writtento); - - void gatherScalarRefs(std::vector &refs, bool writtento); - - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - - void gatherVarUsage(std::vector &decls); - - //void gatherDeclRefExprs( std::vector&refs ); - //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here @@ -1267,6 +1160,7 @@ public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_CUDAMEMCPY; } // variables that are special for this type of node + // TODO Very wrong, this is not a declaration chillAST_VarDecl *dest; // Pointer to allocated device memory chillAST_VarDecl *src; chillAST_Node *size; @@ -1289,8 +1183,6 @@ public: void gatherVarDecls(std::vector &decls); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls); void gatherArrayVarDecls(std::vector &decls); @@ -1307,64 +1199,24 @@ public: class chillAST_CudaSyncthreads : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_CUDASYNCTHREADS; } - // variables that are special for this type of node - // constructors chillAST_CudaSyncthreads(); - - // other methods particular to this type of node - - - // required methods that I can't seem to get to inherit - //chillAST_Node* constantFold() {}; - //chillAST_Node* clone(); - //void gatherArrayRefs( std::vector &refs, bool writtento ){}; - //void gatherScalarRefs( std::vector &refs, bool writtento ) ; - - void gatherVarDecls(std::vector &decls) {}; // does nothing - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls) {}; // does nothing - void gatherArrayVarDecls(std::vector &decls) {}; // does nothing - - void gatherVarUsage(std::vector &decls) {}; // does nothing - //void gatherDeclRefExprs( std::vector&refs ); - //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - //bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; - }; class chillAST_ReturnStmt : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_RETURNSTMT; } - - // variables that are special for this type of node - //! expression to return - chillAST_Node *returnvalue; - // constructors + chillAST_ReturnStmt(); chillAST_ReturnStmt(chillAST_Node *retval); // other methods particular to this type of node - + chillAST_Node* getRetVal() { return getChild(0); } + void setRetVal(chillAST_Node *ret) { setChild(0,ret); } // required methods that I can't seem to get to inherit - chillAST_Node *constantFold(); - chillAST_Node *clone(); - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - - void gatherVarUsage(std::vector &decls); - - void gatherDeclRefExprs(std::vector &refs); - //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here @@ -1400,8 +1252,6 @@ public: void gatherVarDecls(std::vector &decls); - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls(std::vector &decls); void gatherArrayVarDecls(std::vector &decls); @@ -1420,39 +1270,17 @@ public: class chillAST_ParenExpr : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_PARENEXPR; } - - // variables that are special for this type of node - chillAST_Node *subexpr; - // constructors + chillAST_ParenExpr(); chillAST_ParenExpr(chillAST_Node *sub); // other methods particular to this type of node - + chillAST_Node* getSubExpr() { return getChild(0); } + void setSubExpr(chillAST_Node* sub) { setChild(0, sub); } // required methods that I can't seem to get to inherit - chillAST_Node *constantFold(); - chillAST_Node *clone(); - void gatherArrayRefs(std::vector &refs, bool writtento); - - void gatherScalarRefs(std::vector &refs, bool writtento); - - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - - void gatherVarUsage(std::vector &decls); - - void gatherDeclRefExprs(std::vector &refs); - - void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here @@ -1473,28 +1301,8 @@ public: // required methods that I can't seem to get to inherit - chillAST_Node *constantFold(); - chillAST_Node *clone(); - void gatherArrayRefs(std::vector &refs, bool writtento); - - void gatherScalarRefs(std::vector &refs, bool writtento); - - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - - void gatherVarUsage(std::vector &decls); - - void gatherDeclRefExprs(std::vector &refs); - - void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {}; - bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here @@ -1504,35 +1312,15 @@ class chillAST_NoOp : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_NOOP; } - chillAST_NoOp(); // { parent = p; }; + chillAST_NoOp(); // required methods that I can't seem to get to inherit - chillAST_Node *constantFold() {}; - chillAST_Node *clone() { chillAST_Node *n = new chillAST_NoOp(); n->setParent(parent); return n; }; // ?? - void gatherArrayRefs(std::vector &refs, bool writtento) {}; - - void gatherScalarRefs(std::vector &refs, bool writtento) {}; - - void gatherVarDecls(std::vector &decls) {}; - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls) {}; - - void gatherArrayVarDecls(std::vector &decls) {}; - - void gatherVarUsage(std::vector &decls) {}; - - void gatherDeclRefExprs(std::vector &refs) {}; - - void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {}; - bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; };//no loops under here }; @@ -1542,78 +1330,42 @@ public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_IFSTMT; } // variables that are special for this type of node - chillAST_Node *cond; - chillAST_Node *thenpart; - chillAST_Node *elsepart; IR_CONDITION_TYPE conditionoperator; // from ir_code.hh // constructors chillAST_IfStmt(); - chillAST_IfStmt(chillAST_Node *c, chillAST_Node *t, chillAST_Node *e); // other methods particular to this type of node - chillAST_Node *getCond() { return cond; }; + chillAST_Node *getCond() { return getChild(0); }; - chillAST_Node *getThen() { return thenpart; }; + chillAST_Node *getThen() { return getChild(1); }; - chillAST_Node *getElse() { return elsepart; }; + chillAST_Node *getElse() { return getChild(2); }; - void setCond(chillAST_Node *b) { - cond = b; - if (cond) cond->parent = this; - }; + void setCond(chillAST_Node *b) { setChild(0,b); }; - void setThen(chillAST_Node *b) { - thenpart = b; - if (thenpart) thenpart->parent = this; - }; + void setThen(chillAST_Node *b) { setChild(1,b); }; - void setElse(chillAST_Node *b) { - elsepart = b; - if (elsepart) elsepart->parent = this; - }; + void setElse(chillAST_Node *b) { setChild(2,b); }; // required methods that I can't seem to get to inherit - chillAST_Node *constantFold(); - chillAST_Node *clone(); - void gatherVarDecls(std::vector &decls); - - void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - - void gatherScalarVarDecls(std::vector &decls); - - void gatherArrayVarDecls(std::vector &decls); - void gatherArrayRefs(std::vector &refs, bool writtento); void gatherScalarRefs(std::vector &refs, bool writtento); - void gatherVarUsage(std::vector &decls); - - void gatherDeclRefExprs(std::vector &refs); - //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false); - void gatherStatements(std::vector &statements); - }; class chillAST_something : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_UNKNOWN; } - // variables that are special for this type of node - // constructors chillAST_something(); - - // other methods particular to this type of node - - - // required methods that I can't seem to get to inherit }; diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc index 39223e9..558fe38 100755 --- a/lib/chillcg/src/CG_chillBuilder.cc +++ b/lib/chillcg/src/CG_chillBuilder.cc @@ -202,8 +202,8 @@ namespace omega { chillAST_Node *SubImplicitCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { //fprintf(stderr, "SubImplicitCastExpr subbing statement of type %s at 0x%x parent 0x%x\n", n->getTypeString(), n, parent); chillAST_ImplicitCastExpr *IC = (chillAST_ImplicitCastExpr *) n; - chillAST_Node *oldsub = IC->subexpr; - IC->subexpr = substituteChill( oldvar, newvar, oldsub, IC); + chillAST_Node *oldsub = IC->getSubExpr(); + IC->setSubExpr(substituteChill( oldvar, newvar, oldsub, IC)); //if (oldsub != IC->subexpr) { //fprintf(stderr, "ImplicitCastExpr has CHANGED\n"); @@ -221,14 +221,14 @@ namespace omega { //fprintf(stderr, "SubCStyleCastExpr() subexpr is type "); chillAST_CStyleCastExpr *CSCE = (chillAST_CStyleCastExpr *) n; //fprintf(stderr, "%s\n", CSCE->subexpr->getTypeString()); - CSCE->subexpr = substituteChill( oldvar, newvar, CSCE->subexpr, CSCE); + CSCE->setSubExpr(substituteChill( oldvar, newvar, CSCE->getSubExpr(), CSCE)); return CSCE; } chillAST_Node *SubParenExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { chillAST_ParenExpr *PE = (chillAST_ParenExpr *) n; - PE->subexpr = substituteChill( oldvar, newvar, PE->subexpr, PE); + PE->setSubExpr(substituteChill( oldvar, newvar, PE->getSubExpr(), PE)); return PE; } @@ -251,7 +251,7 @@ namespace omega { //fprintf(stderr, "SubReturnStmt()\n"); chillAST_ReturnStmt *RS = (chillAST_ReturnStmt *)n; - if (RS->returnvalue) RS->returnvalue = substituteChill(oldvar, newvar, RS->returnvalue, RS); + if (RS->getRetVal()) RS->setRetVal(substituteChill(oldvar, newvar, RS->getRetVal(), RS)); return RS; } diff --git a/src/ast/node.cpp b/src/ast/node.cpp index deee5ba..3d28d97 100644 --- a/src/ast/node.cpp +++ b/src/ast/node.cpp @@ -261,7 +261,6 @@ void chillAST_Node::print(int indent, FILE *fp) { } chillAST_Node* chillAST_Node::constantFold(){ - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;iconstantFold()); @@ -270,56 +269,48 @@ chillAST_Node* chillAST_Node::constantFold(){ }; void chillAST_Node::gatherVarDecls(vector &decls) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;igatherVarDecls(decls); } } void chillAST_Node::gatherArrayVarDecls(vector &decls) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;igatherArrayVarDecls(decls); } } void chillAST_Node::gatherArrayRefs(vector &refs, bool writtento) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;igatherArrayRefs(refs,writtento); } } void chillAST_Node::gatherScalarRefs(vector &refs, bool writtento) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;igatherScalarRefs(refs,writtento); } } void chillAST_Node::gatherDeclRefExprs(vector &refs) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;igatherDeclRefExprs(refs); } } void chillAST_Node::gatherVarUsage(vector &decls) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;igatherVarUsage(decls); } } void chillAST_Node::gatherStatements(vector &statements) { - CHILL_DEBUG_PRINT("using generic\n"); for (int i = 0;igatherStatements(statements); } } void chillAST_Node::replaceVarDecls(chillAST_VarDecl* olddecl, chillAST_VarDecl *newdecl) { - CHILL_DEBUG_PRINT("using generic\n"); for (int i = 0;ireplaceVarDecls(olddecl,newdecl); @@ -327,7 +318,6 @@ void chillAST_Node::replaceVarDecls(chillAST_VarDecl* olddecl, chillAST_VarDecl } void chillAST_Node::gatherScalarVarDecls(vector &decls) { - CHILL_DEBUG_PRINT("using generic\n"); for (int i = 0;igatherScalarVarDecls(decls); diff --git a/src/chillASTs.cc b/src/chillASTs.cc index edbe221..70c37e8 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -1071,9 +1071,9 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) { //fprintf(stderr, "loop condition RHS is ternary\nCondition RHS"); C->print(); chillAST_Node *l = C->getLHS(); - if (l->isParenExpr()) l = ((chillAST_ParenExpr *) l)->subexpr; + if (l->isParenExpr()) l = ((chillAST_ParenExpr *) l)->getSubExpr(); chillAST_Node *r = C->getRHS(); - if (r->isParenExpr()) r = ((chillAST_ParenExpr *) r)->subexpr; + if (r->isParenExpr()) r = ((chillAST_ParenExpr *) r)->getSubExpr(); //fprintf(stderr, "lhs is %s rhs is %s\n", l->getTypeString(), r->getTypeString()); @@ -1301,13 +1301,13 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_Node *bas, chi parent = NULL; metacomment = NULL; if (bas) { - if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong + if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->getSubExpr(); // probably wrong else base = bas; base->setParent(this); basedecl = multibase(); } if (indx) { - if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr *) indx)->subexpr; // probably wrong + if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr *) indx)->getSubExpr(); // probably wrong else index = indx; index->setParent(this); } @@ -1422,7 +1422,7 @@ chillAST_Node *chillAST_ArraySubscriptExpr::getIndex(int dim) { chillAST_Node *curindex = index; for (;;) { if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) - b = ((chillAST_ImplicitCastExpr *) b)->subexpr; + b = ((chillAST_ImplicitCastExpr *) b)->getSubExpr(); else if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { ind.push_back(curindex); curindex = ((chillAST_ArraySubscriptExpr *) b)->index; @@ -1852,7 +1852,7 @@ void chillAST_DeclRefExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_V } chillAST_VarDecl *chillAST_ImplicitCastExpr::multibase() { - return subexpr->multibase(); + return getSubExpr()->multibase(); } @@ -2138,256 +2138,85 @@ int chillAST_UnaryOperator::evalAsInt() { fprintf(stderr, "chillAST_UnaryOperator::evalAsInt() unhandled op '%s'\n", op); exit(-1); - -} - -chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_Node *sub) { - subexpr = sub; - subexpr->setParent(this); - //fprintf(stderr, "ImplicitCastExpr 0x%x has subexpr 0x%x", this, subexpr); - //fprintf(stderr, " of type %s\n", subexpr->getTypeString()); } -void chillAST_ImplicitCastExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { - if (subexpr == old) { // should be the case for this to get called - subexpr = newchild; - subexpr->setParent(this); - //old->parent = NULL; - return; - } - - fprintf(stderr, "chillAST_ImplicitCastExpr::replaceChild() called with bad 'old'\n"); - exit(-1); // ?? +chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr() { + children.push_back(NULL); } -class chillAST_Node *chillAST_ImplicitCastExpr::constantFold() { - chillAST_Node *child = subexpr->constantFold(); - child->setParent(parent); // remove myself !! probably a bad idea. TODO - return child; +chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_Node *sub):chillAST_ImplicitCastExpr() { + setSubExpr(sub); } - class chillAST_Node *chillAST_ImplicitCastExpr::clone() { - chillAST_ImplicitCastExpr *ICE = new chillAST_ImplicitCastExpr(subexpr->clone()); - ICE->setParent(getParent()); + chillAST_ImplicitCastExpr *ICE = new chillAST_ImplicitCastExpr(getSubExpr()->clone()); ICE->isFromSourceFile = isFromSourceFile; if (filename) ICE->filename = strdup(filename); return ICE; } - -void chillAST_ImplicitCastExpr::gatherArrayRefs(std::vector &refs, bool w) { - subexpr->gatherArrayRefs(refs, w); -} - -void chillAST_ImplicitCastExpr::gatherScalarRefs(std::vector &refs, bool writtento) { - subexpr->gatherScalarRefs(refs, writtento); -} - -void chillAST_ImplicitCastExpr::gatherVarDecls(vector &decls) { - subexpr->gatherVarDecls(decls); -} - - -void chillAST_ImplicitCastExpr::gatherScalarVarDecls(vector &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_ImplicitCastExpr::gatherArrayVarDecls(vector &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_ImplicitCastExpr::gatherDeclRefExprs(vector &refs) { - subexpr->gatherDeclRefExprs(refs); -} - - -void chillAST_ImplicitCastExpr::gatherVarUsage(vector &decls) { - subexpr->gatherVarUsage(decls); +chillAST_CStyleCastExpr::chillAST_CStyleCastExpr() { + children.push_back(NULL); } - -chillAST_CStyleCastExpr::chillAST_CStyleCastExpr(const char *to, chillAST_Node *sub) { - - //fprintf(stderr, "chillAST_CStyleCastExpr::chillAST_CStyleCastExpr( %s, ...)\n", to); +chillAST_CStyleCastExpr::chillAST_CStyleCastExpr(const char *to, chillAST_Node *sub):chillAST_CStyleCastExpr() { towhat = strdup(to); - subexpr = sub; - if (subexpr) subexpr->setParent(this); - //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub ); -} - -void chillAST_CStyleCastExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { - if (subexpr == old) { // should be the case for this to get called - subexpr = newchild; - subexpr->setParent(this); - //old->parent = NULL; - return; - } - - fprintf(stderr, "chillAST_CStyleCastExpr::replaceChild() called with bad 'old'\n"); - exit(-1); // ?? -} - -void chillAST_CStyleCastExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { - subexpr->replaceVarDecls(olddecl, newdecl); -} - -class chillAST_Node *chillAST_CStyleCastExpr::constantFold() { - subexpr = subexpr->constantFold(); - return this; + setSubExpr(sub); } - class chillAST_Node *chillAST_CStyleCastExpr::clone() { - chillAST_CStyleCastExpr *CSCE = new chillAST_CStyleCastExpr(towhat, subexpr->clone()); + chillAST_CStyleCastExpr *CSCE = new chillAST_CStyleCastExpr(towhat, getSubExpr()->clone()); CSCE->setParent(getParent()); CSCE->isFromSourceFile = isFromSourceFile; if (filename) CSCE->filename = strdup(filename); return CSCE; } -void chillAST_CStyleCastExpr::gatherArrayRefs(std::vector &refs, bool w) { - subexpr->gatherArrayRefs(refs, w); -} - -void chillAST_CStyleCastExpr::gatherScalarRefs(std::vector &refs, bool writtento) { - subexpr->gatherScalarRefs(refs, writtento); -} - - -void chillAST_CStyleCastExpr::gatherVarDecls(vector &decls) { - subexpr->gatherVarDecls(decls); -} - - -void chillAST_CStyleCastExpr::gatherScalarVarDecls(vector &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_CStyleCastExpr::gatherArrayVarDecls(vector &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_CStyleCastExpr::gatherDeclRefExprs(vector &refs) { - subexpr->gatherDeclRefExprs(refs); -} - - -void chillAST_CStyleCastExpr::gatherVarUsage(vector &decls) { - subexpr->gatherVarUsage(decls); -} - - -chillAST_CStyleAddressOf::chillAST_CStyleAddressOf(chillAST_Node *sub) { - subexpr = sub; - subexpr->setParent(this); - //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub ); +chillAST_CStyleAddressOf::chillAST_CStyleAddressOf() { + children.push_back(NULL); } - -class chillAST_Node *chillAST_CStyleAddressOf::constantFold() { - subexpr = subexpr->constantFold(); - return this; +chillAST_CStyleAddressOf::chillAST_CStyleAddressOf(chillAST_Node *sub):chillAST_CStyleAddressOf() { + setSubExpr(sub); } class chillAST_Node *chillAST_CStyleAddressOf::clone() { - chillAST_CStyleAddressOf *CSAO = new chillAST_CStyleAddressOf(subexpr->clone()); + chillAST_CStyleAddressOf *CSAO = new chillAST_CStyleAddressOf(getSubExpr()->clone()); CSAO->setParent(getParent()); CSAO->isFromSourceFile = isFromSourceFile; if (filename) CSAO->filename = strdup(filename); return CSAO; } -void chillAST_CStyleAddressOf::gatherArrayRefs(std::vector &refs, bool w) { - subexpr->gatherArrayRefs(refs, w); -} - -void chillAST_CStyleAddressOf::gatherScalarRefs(std::vector &refs, bool writtento) { - subexpr->gatherScalarRefs(refs, writtento); -} - -void chillAST_CStyleAddressOf::gatherVarDecls(vector &decls) { - subexpr->gatherVarDecls(decls); -} - -void chillAST_CStyleAddressOf::gatherScalarVarDecls(vector &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_CStyleAddressOf::gatherArrayVarDecls(vector &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_CStyleAddressOf::gatherDeclRefExprs(vector &refs) { - subexpr->gatherDeclRefExprs(refs); -} - - -void chillAST_CStyleAddressOf::gatherVarUsage(vector &decls) { - subexpr->gatherVarUsage(decls); +chillAST_Malloc::chillAST_Malloc() { + children.push_back(NULL); } - -chillAST_Malloc::chillAST_Malloc(chillAST_Node *numthings) { - sizeexpr = numthings; +chillAST_Malloc::chillAST_Malloc(chillAST_Node *numthings):chillAST_Malloc() { + setSize(numthings); isFromSourceFile = true; // default filename = NULL; }; -chillAST_Node *chillAST_Malloc::constantFold() { - sizeexpr->constantFold(); -} - chillAST_Node *chillAST_Malloc::clone() { - chillAST_Malloc *M = new chillAST_Malloc(sizeexpr); // the general version + chillAST_Malloc *M = new chillAST_Malloc(getSize()->clone()); // the general version M->setParent(getParent()); M->isFromSourceFile = isFromSourceFile; if (filename) M->filename = strdup(filename); return M; }; -void chillAST_Malloc::gatherArrayRefs(std::vector &refs, bool writtento) { - sizeexpr->gatherArrayRefs(refs, writtento); -}; - - -void chillAST_Malloc::gatherScalarRefs(std::vector &refs, bool writtento) { - sizeexpr->gatherScalarRefs(refs, writtento); -}; - -void chillAST_Malloc::gatherVarDecls(vector &decls) { - sizeexpr->gatherVarDecls(decls); -}; - -void chillAST_Malloc::gatherScalarVarDecls(vector &decls) { - sizeexpr->gatherScalarVarDecls(decls); -}; - -void chillAST_Malloc::gatherArrayVarDecls(vector &decls) { - sizeexpr->gatherArrayVarDecls(decls); -}; - -void chillAST_Malloc::gatherVarUsage(vector &decls) { - sizeexpr->gatherVarUsage(decls); -}; +chillAST_CudaMalloc::chillAST_CudaMalloc() { + children.push_back(NULL); + children.push_back(NULL); +} -chillAST_CudaMalloc::chillAST_CudaMalloc(chillAST_Node *devmemptr, chillAST_Node *size) { - devPtr = devmemptr; - sizeinbytes = size; // probably a multiply like sizeof(int) * 1024 +chillAST_CudaMalloc::chillAST_CudaMalloc(chillAST_Node *devmemptr, chillAST_Node *size):chillAST_CudaMalloc() { + setDevPtr(devmemptr); + setSize(size); }; -class chillAST_Node *chillAST_CudaMalloc::constantFold() { - devPtr = devPtr->constantFold(); - return this; -} - class chillAST_Node *chillAST_CudaMalloc::clone() { - chillAST_CudaMalloc *CM = new chillAST_CudaMalloc(devPtr->clone(), sizeinbytes->clone()); + chillAST_CudaMalloc *CM = new chillAST_CudaMalloc(getDevPtr()->clone(), getSize()->clone()); CM->setParent(getParent()); CM->isFromSourceFile = isFromSourceFile; if (filename) CM->filename = strdup(filename); @@ -2395,39 +2224,13 @@ class chillAST_Node *chillAST_CudaMalloc::clone() { } void chillAST_CudaMalloc::gatherArrayRefs(std::vector &refs, bool w) { - devPtr->gatherArrayRefs(refs, false); - sizeinbytes->gatherArrayRefs(refs, false); + chillAST_Node::gatherArrayRefs(refs,false); } void chillAST_CudaMalloc::gatherScalarRefs(std::vector &refs, bool writtento) { - devPtr->gatherScalarRefs(refs, false); - sizeinbytes->gatherScalarRefs(refs, false); -} - -void chillAST_CudaMalloc::gatherVarDecls(vector &decls) { - devPtr->gatherVarDecls(decls); - sizeinbytes->gatherVarDecls(decls); -} - - -void chillAST_CudaMalloc::gatherScalarVarDecls(vector &decls) { - devPtr->gatherScalarVarDecls(decls); - sizeinbytes->gatherScalarVarDecls(decls); + chillAST_Node::gatherScalarRefs(refs,false); } - -void chillAST_CudaMalloc::gatherArrayVarDecls(vector &decls) { - devPtr->gatherArrayVarDecls(decls); - sizeinbytes->gatherArrayVarDecls(decls); -} - - -void chillAST_CudaMalloc::gatherVarUsage(vector &decls) { - devPtr->gatherVarUsage(decls); - sizeinbytes->gatherVarUsage(decls); -} - - chillAST_CudaFree::chillAST_CudaFree(chillAST_VarDecl *var) { variable = var; }; @@ -2536,20 +2339,16 @@ void chillAST_CudaMemcpy::gatherVarUsage(vector &decls) { chillAST_CudaSyncthreads::chillAST_CudaSyncthreads() { } -chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_Node *retval) { - returnvalue = retval; - if (returnvalue) returnvalue->setParent(this); +chillAST_ReturnStmt::chillAST_ReturnStmt() { + children.push_back(NULL); } - -class chillAST_Node *chillAST_ReturnStmt::constantFold() { - if (returnvalue) returnvalue = returnvalue->constantFold(); - return this; +chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_Node *retval):chillAST_ReturnStmt() { + setRetVal(retval); } - class chillAST_Node *chillAST_ReturnStmt::clone() { chillAST_Node *val = NULL; - if (returnvalue) val = returnvalue->clone(); + if (getRetVal()) val = getRetVal()->clone(); chillAST_ReturnStmt *RS = new chillAST_ReturnStmt(val); RS->setParent(getParent()); RS->isFromSourceFile = isFromSourceFile; @@ -2557,32 +2356,6 @@ class chillAST_Node *chillAST_ReturnStmt::clone() { return RS; } - -void chillAST_ReturnStmt::gatherVarDecls(vector &decls) { - if (returnvalue) returnvalue->gatherVarDecls(decls); -} - - -void chillAST_ReturnStmt::gatherScalarVarDecls(vector &decls) { - if (returnvalue) returnvalue->gatherScalarVarDecls(decls); -} - - -void chillAST_ReturnStmt::gatherArrayVarDecls(vector &decls) { - if (returnvalue) returnvalue->gatherArrayVarDecls(decls); -} - - -void chillAST_ReturnStmt::gatherDeclRefExprs(vector &refs) { - if (returnvalue) returnvalue->gatherDeclRefExprs(refs); -} - - -void chillAST_ReturnStmt::gatherVarUsage(vector &decls) { - if (returnvalue) returnvalue->gatherVarUsage(decls); -} - - chillAST_CallExpr::chillAST_CallExpr(chillAST_Node *c) { //, int numofargs, chillAST_Node **theargs ) { //fprintf(stderr, "chillAST_CallExpr::chillAST_CallExpr callee type %s\n", c->getTypeString()); @@ -3188,75 +2961,25 @@ bool chillAST_CompoundStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symta */ } - -chillAST_ParenExpr::chillAST_ParenExpr(chillAST_Node *sub) { - subexpr = sub; - subexpr->setParent(this); -} - -void chillAST_ParenExpr::gatherArrayRefs(std::vector &refs, bool writtento) { - subexpr->gatherArrayRefs(refs, writtento); -} - -void chillAST_ParenExpr::gatherScalarRefs(std::vector &refs, bool writtento) { - subexpr->gatherScalarRefs(refs, writtento); +chillAST_ParenExpr::chillAST_ParenExpr() { + children.push_back(NULL); } - - -chillAST_Node *chillAST_ParenExpr::constantFold() { - subexpr = subexpr->constantFold(); - return this; +chillAST_ParenExpr::chillAST_ParenExpr(chillAST_Node *sub) { + setSubExpr(sub); } - chillAST_Node *chillAST_ParenExpr::clone() { - chillAST_ParenExpr *PE = new chillAST_ParenExpr(subexpr->clone()); + chillAST_ParenExpr *PE = new chillAST_ParenExpr(getSubExpr()->clone()); PE->setParent(getParent()); PE->isFromSourceFile = isFromSourceFile; if (filename) PE->filename = strdup(filename); return PE; } -void chillAST_ParenExpr::gatherVarDecls(vector &decls) { - subexpr->gatherVarDecls(decls); -} - - -void chillAST_ParenExpr::gatherScalarVarDecls(vector &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_ParenExpr::gatherArrayVarDecls(vector &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_ParenExpr::gatherDeclRefExprs(vector &refs) { - subexpr->gatherDeclRefExprs(refs); -} - -void chillAST_ParenExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { - subexpr->replaceVarDecls(olddecl, newdecl); -} - -void chillAST_ParenExpr::gatherVarUsage(vector &decls) { - subexpr->gatherVarUsage(decls); -} - - chillAST_Sizeof::chillAST_Sizeof(char *athing) { thing = strdup(athing); // memory leak } -void chillAST_Sizeof::gatherArrayRefs(std::vector &refs, bool writtento) {} - -void chillAST_Sizeof::gatherScalarRefs(std::vector &refs, bool writtento) {} - -chillAST_Node *chillAST_Sizeof::constantFold() { - return this; -} - chillAST_Node *chillAST_Sizeof::clone() { chillAST_Sizeof *SO = new chillAST_Sizeof(thing); SO->setParent(getParent()); @@ -3265,27 +2988,6 @@ chillAST_Node *chillAST_Sizeof::clone() { return SO; } -void chillAST_Sizeof::gatherVarDecls(vector &decls) { // TODO -} - - -void chillAST_Sizeof::gatherScalarVarDecls(vector &decls) { // TODO -} - - -void chillAST_Sizeof::gatherArrayVarDecls(vector &decls) { // TODO -} - - -void chillAST_Sizeof::gatherDeclRefExprs(vector &refs) { - // TODO -} - - -void chillAST_Sizeof::gatherVarUsage(vector &decls) { -} - - void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl) { //fprintf(stderr, "insertNewDeclAtLocationOfOldIfNeeded( new 0x%x old 0x%x\n", newdecl, olddecl ); @@ -3375,94 +3077,31 @@ void gatherVarUsage(vector &code, vector &d chillAST_IfStmt::chillAST_IfStmt() { - cond = thenpart = elsepart = NULL; - isFromSourceFile = true; // default - filename = NULL; -} - -chillAST_IfStmt::chillAST_IfStmt(chillAST_Node *c, chillAST_Node *t, chillAST_Node *e) { - cond = c; - if (cond) cond->setParent(this); - thenpart = t; - if (thenpart) thenpart->setParent(this); - elsepart = e; - if (elsepart) elsepart->setParent(this); -} - -void chillAST_IfStmt::gatherVarDecls(vector &decls) { - if (cond) cond->gatherVarDecls(decls); - if (thenpart) thenpart->gatherVarDecls(decls); - if (elsepart) elsepart->gatherVarDecls(decls); -} - - -void chillAST_IfStmt::gatherScalarVarDecls(vector &decls) { - if (cond) cond->gatherScalarVarDecls(decls); - if (thenpart) thenpart->gatherScalarVarDecls(decls); - if (elsepart) elsepart->gatherScalarVarDecls(decls); -} - - -void chillAST_IfStmt::gatherArrayVarDecls(vector &decls) { - if (cond) cond->gatherArrayVarDecls(decls); - if (thenpart) thenpart->gatherArrayVarDecls(decls); - if (elsepart) elsepart->gatherArrayVarDecls(decls); -} - - -void chillAST_IfStmt::gatherDeclRefExprs(vector &refs) { - if (cond) cond->gatherDeclRefExprs(refs); - if (thenpart) thenpart->gatherDeclRefExprs(refs); - if (elsepart) elsepart->gatherDeclRefExprs(refs); + children.push_back(NULL); + children.push_back(NULL); + children.push_back(NULL); } - -void chillAST_IfStmt::gatherVarUsage(vector &decls) { - if (cond) cond->gatherVarUsage(decls); - if (thenpart) thenpart->gatherVarUsage(decls); - if (elsepart) elsepart->gatherVarUsage(decls); +chillAST_IfStmt::chillAST_IfStmt(chillAST_Node *c, chillAST_Node *t, chillAST_Node *e):chillAST_IfStmt() { + setCond(c); + setThen(t); + setElse(e); } - void chillAST_IfStmt::gatherArrayRefs(std::vector &refs, bool writtento) { - cond->gatherArrayRefs(refs, 0); // 0 ?? - thenpart->gatherArrayRefs(refs, 0); // 0 ?? - if (elsepart) elsepart->gatherArrayRefs(refs, 0); // 0 ?? + chillAST_Node::gatherArrayRefs(refs,0); } void chillAST_IfStmt::gatherScalarRefs(std::vector &refs, bool writtento) { - cond->gatherScalarRefs(refs, 0); // 0 ?? - thenpart->gatherScalarRefs(refs, 0); // 0 ?? - if (elsepart) elsepart->gatherScalarRefs(refs, 0); // 0 ?? -} - - -chillAST_Node *chillAST_IfStmt::constantFold() { - if (cond) cond = cond->constantFold(); - if (thenpart) thenpart = thenpart->constantFold(); - if (elsepart) elsepart = elsepart->constantFold(); - return this; + chillAST_Node::gatherScalarRefs(refs,0); } -void chillAST_IfStmt::gatherStatements(std::vector &statements) { - - //print(); printf("\n"); fflush(stdout); - thenpart->gatherStatements(statements); - //fprintf(stderr, "ifstmt, after then, %d statements\n", statements.size()); - if (elsepart) { - //fprintf(stderr, "there is an elsepart of type %s\n", elsepart->getTypeString()); - elsepart->gatherStatements(statements); - } - //fprintf(stderr, "ifstmt, after else, %d statements\n", statements.size()); -} - - chillAST_Node *chillAST_IfStmt::clone() { chillAST_Node *c, *t, *e; c = t = e = NULL; - if (cond) c = cond->clone(); // has to be one, right? - if (thenpart) t = thenpart->clone(); - if (elsepart) e = elsepart->clone(); + if (getCond()) c = getCond()->clone(); // has to be one, right? + if (getThen()) t = getThen()->clone(); + if (getElse()) e = getElse()->clone(); chillAST_IfStmt *IS = new chillAST_IfStmt(c, t, e); IS->setParent(getParent()); @@ -3472,8 +3111,8 @@ chillAST_Node *chillAST_IfStmt::clone() { } bool chillAST_IfStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync) { - thenpart->findLoopIndexesToReplace(symtab); - elsepart->findLoopIndexesToReplace(symtab); + getThen()->findLoopIndexesToReplace(symtab); + getElse()->findLoopIndexesToReplace(symtab); return false; // ?? } diff --git a/src/ir_clang.cc b/src/ir_clang.cc index cb4cbb8..61ba36c 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -2983,9 +2983,9 @@ IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *re //fprintf(stderr, "chillAST node type %s\n", node->getTypeString()); // really need to be more rigorous than this hack // TODO - if (node->isImplicitCastExpr()) node = ((chillAST_ImplicitCastExpr *) node)->subexpr; - if (node->isCStyleCastExpr()) node = ((chillAST_CStyleCastExpr *) node)->subexpr; - if (node->isParenExpr()) node = ((chillAST_ParenExpr *) node)->subexpr; + if (node->isImplicitCastExpr()) node = ((chillAST_ImplicitCastExpr *) node)->getSubExpr(); + if (node->isCStyleCastExpr()) node = ((chillAST_CStyleCastExpr *) node)->getSubExpr(); + if (node->isParenExpr()) node = ((chillAST_ParenExpr *) node)->getSubExpr(); if (node->isIntegerLiteral() || node->isFloatingLiteral()) return IR_OP_CONSTANT; else if (node->isBinaryOperator() || node->isUnaryOperator()) { @@ -3055,9 +3055,9 @@ std::vector IR_clangCode::QueryExpOperand(const omega::C //e->print(); printf("\n"); fflush(stdout); // really need to be more rigorous than this hack // TODO - if (e->isImplicitCastExpr()) e = ((chillAST_ImplicitCastExpr *) e)->subexpr; - if (e->isCStyleCastExpr()) e = ((chillAST_CStyleCastExpr *) e)->subexpr; - if (e->isParenExpr()) e = ((chillAST_ParenExpr *) e)->subexpr; + if (e->isImplicitCastExpr()) e = ((chillAST_ImplicitCastExpr *) e)->getSubExpr(); + if (e->isCStyleCastExpr()) e = ((chillAST_CStyleCastExpr *) e)->getSubExpr(); + if (e->isParenExpr()) e = ((chillAST_ParenExpr *) e)->getSubExpr(); //if(isa(e) || isa(e) || isa(e)) { diff --git a/src/printer/cfamily.cpp b/src/printer/cfamily.cpp index 5c56bd7..3427c80 100644 --- a/src/printer/cfamily.cpp +++ b/src/printer/cfamily.cpp @@ -117,7 +117,7 @@ int CFamily::getPrecS(chillAST_CStyleAddressOf *n) { void CFamily::printS(std::string ident, chillAST_CStyleAddressOf *n, std::ostream &o) { int prec = getPrec(n); - printPrec(ident, n->subexpr, o, prec); + printPrec(ident, n->getSubExpr(), o, prec); } int CFamily::getPrecS(chillAST_CStyleCastExpr *n) { @@ -126,7 +126,7 @@ int CFamily::getPrecS(chillAST_CStyleCastExpr *n) { void CFamily::printS(std::string ident, chillAST_CStyleCastExpr *n, std::ostream &o) { o << "(" << n->towhat << ")"; - printPrec(ident, n->subexpr, o, getPrec(n)); + printPrec(ident, n->getSubExpr(), o, getPrec(n)); } void CFamily::printS(std::string ident, chillAST_CudaFree *n, std::ostream &o) { @@ -139,9 +139,9 @@ void CFamily::printS(std::string ident, chillAST_CudaKernelCall *n, std::ostream void CFamily::printS(std::string ident, chillAST_CudaMalloc *n, std::ostream &o) { o << "cudaMalloc("; - print(ident, n->devPtr, o); + print(ident, n->getDevPtr(), o); o << ", "; - print(ident, n->sizeinbytes, o); + print(ident, n->getSize(), o); o << ")"; } @@ -227,7 +227,7 @@ void CFamily::printS(std::string ident, chillAST_IfStmt *n, std::ostream &o) { CHILL_ERROR("Then part is not a CompoundStmt!\n"); if (n->getElse()) { o << "else "; - print(ident, n->elsepart, o); + print(ident, n->getElse(), o); } } @@ -236,7 +236,7 @@ void CFamily::printS(std::string ident, chillAST_IntegerLiteral *n, std::ostream } void CFamily::printS(std::string ident, chillAST_ImplicitCastExpr *n, std::ostream &o) { - print(ident, n->subexpr, o); + print(ident, n->getSubExpr(), o); } void CFamily::printS(std::string ident, chillAST_MacroDefinition *n, std::ostream &o) { @@ -254,7 +254,7 @@ void CFamily::printS(std::string ident, chillAST_MacroDefinition *n, std::ostrea void CFamily::printS(std::string ident, chillAST_Malloc *n, std::ostream &o) { o << "malloc("; - print(ident, n->sizeexpr, o); + print(ident, n->getSize(), o); o << ")"; } @@ -276,7 +276,7 @@ void CFamily::printS(std::string ident, chillAST_NoOp *n, std::ostream &o) {} void CFamily::printS(std::string ident, chillAST_ParenExpr *n, std::ostream &o) { o << "("; - print(ident, n->subexpr, o); + print(ident, n->getSubExpr(), o); o << ")"; } @@ -304,9 +304,9 @@ void CFamily::printS(std::string ident, chillAST_RecordDecl *n, std::ostream &o) void CFamily::printS(std::string ident, chillAST_ReturnStmt *n, std::ostream &o) { o << "return"; - if (n->returnvalue) { + if (n->getRetVal()) { o << " "; - print(ident, n->returnvalue, o); + print(ident, n->getRetVal(), o); } } diff --git a/src/printer/dump.cpp b/src/printer/dump.cpp index 059e56f..0e66f29 100644 --- a/src/printer/dump.cpp +++ b/src/printer/dump.cpp @@ -79,12 +79,12 @@ void Dump::printS(std::string ident, chillAST_CompoundStmt *n, std::ostream &o) } void Dump::printS(std::string ident, chillAST_CStyleAddressOf *n, std::ostream &o) { - print(ident, n->subexpr, o); + print(ident, n->getSubExpr(), o); } void Dump::printS(std::string ident, chillAST_CStyleCastExpr *n, std::ostream &o) { o << n->towhat << " "; - print(ident, n->subexpr, o); + print(ident, n->getSubExpr(), o); } void Dump::printS(std::string ident, chillAST_CudaFree *n, std::ostream &o) { @@ -96,8 +96,8 @@ void Dump::printS(std::string ident, chillAST_CudaKernelCall *n, std::ostream &o } void Dump::printS(std::string ident, chillAST_CudaMalloc *n, std::ostream &o) { - print(ident, n->devPtr, o); - print(ident, n->sizeinbytes, o); + print(ident, n->getDevPtr(), o); + print(ident, n->getSize(), o); } void Dump::printS(std::string ident, chillAST_CudaMemcpy *n, std::ostream &o) { @@ -141,10 +141,10 @@ void Dump::printS(std::string ident, chillAST_FunctionDecl *n, std::ostream &o) } void Dump::printS(std::string ident, chillAST_IfStmt *n, std::ostream &o) { - print(ident, n->cond, o); - print(ident, n->thenpart, o); - if (n->elsepart) - print(ident, n->elsepart, o); + print(ident, n->getCond(), o); + print(ident, n->getThen(), o); + if (n->getElse()) + print(ident, n->getElse(), o); } void Dump::printS(std::string ident, chillAST_IntegerLiteral *n, std::ostream &o) { @@ -152,7 +152,7 @@ void Dump::printS(std::string ident, chillAST_IntegerLiteral *n, std::ostream &o } void Dump::printS(std::string ident, chillAST_ImplicitCastExpr *n, std::ostream &o) { - print(ident, n->subexpr, o); + print(ident, n->getSubExpr(), o); } void Dump::printS(std::string ident, chillAST_MacroDefinition *n, std::ostream &o) { @@ -162,7 +162,7 @@ void Dump::printS(std::string ident, chillAST_MacroDefinition *n, std::ostream & } void Dump::printS(std::string ident, chillAST_Malloc *n, std::ostream &o) { - print(ident, n->sizeexpr, o); + print(ident, n->getSize(), o); } void Dump::printS(std::string ident, chillAST_MemberExpr *n, std::ostream &o) { @@ -179,7 +179,7 @@ void Dump::printS(std::string ident, chillAST_NULL *n, std::ostream &o) { void Dump::printS(std::string ident, chillAST_NoOp *n, std::ostream &o) {} void Dump::printS(std::string ident, chillAST_ParenExpr *n, std::ostream &o) { - print(ident, n->subexpr, o); + print(ident, n->getSubExpr(), o); } void Dump::printS(std::string ident, chillAST_Preprocessing *n, std::ostream &o) {} @@ -192,7 +192,7 @@ void Dump::printS(std::string ident, chillAST_RecordDecl *n, std::ostream &o) { } void Dump::printS(std::string ident, chillAST_ReturnStmt *n, std::ostream &o) { - if (n->returnvalue) print(ident, n->returnvalue, o); + if (n->getRetVal()) print(ident, n->getRetVal(), o); } void Dump::printS(std::string ident, chillAST_Sizeof *n, std::ostream &o) { -- cgit v1.2.3-70-g09d2