diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ast/node.cpp | 10 | ||||
-rw-r--r-- | src/chillASTs.cc | 481 | ||||
-rwxr-xr-x | src/ir_clang.cc | 12 | ||||
-rw-r--r-- | src/printer/cfamily.cpp | 20 | ||||
-rw-r--r-- | src/printer/dump.cpp | 24 |
5 files changed, 88 insertions, 459 deletions
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;i<getNumChildren();++i) { if (getChild(i)) setChild(i,getChild(i)->constantFold()); @@ -270,56 +269,48 @@ chillAST_Node* chillAST_Node::constantFold(){ }; void chillAST_Node::gatherVarDecls(vector<chillAST_VarDecl*> &decls) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->gatherVarDecls(decls); } } void chillAST_Node::gatherArrayVarDecls(vector<chillAST_VarDecl*> &decls) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->gatherArrayVarDecls(decls); } } void chillAST_Node::gatherArrayRefs(vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->gatherArrayRefs(refs,writtento); } } void chillAST_Node::gatherScalarRefs(vector<chillAST_DeclRefExpr*> &refs, bool writtento) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->gatherScalarRefs(refs,writtento); } } void chillAST_Node::gatherDeclRefExprs(vector<chillAST_DeclRefExpr*> &refs) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->gatherDeclRefExprs(refs); } } void chillAST_Node::gatherVarUsage(vector<chillAST_VarDecl*> &decls) { - CHILL_DEBUG_PRINT("Using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->gatherVarUsage(decls); } } void chillAST_Node::gatherStatements(vector<chillAST_Node*> &statements) { - CHILL_DEBUG_PRINT("using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->gatherStatements(statements); } } void chillAST_Node::replaceVarDecls(chillAST_VarDecl* olddecl, chillAST_VarDecl *newdecl) { - CHILL_DEBUG_PRINT("using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->replaceVarDecls(olddecl,newdecl); @@ -327,7 +318,6 @@ void chillAST_Node::replaceVarDecls(chillAST_VarDecl* olddecl, chillAST_VarDecl } void chillAST_Node::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - CHILL_DEBUG_PRINT("using generic\n"); for (int i = 0;i<getNumChildren();++i) { if (getChild(i)) getChild(i)->gatherScalarVarDecls(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<chillAST_ArraySubscriptExpr *> &refs, bool w) { - subexpr->gatherArrayRefs(refs, w); -} - -void chillAST_ImplicitCastExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) { - subexpr->gatherScalarRefs(refs, writtento); -} - -void chillAST_ImplicitCastExpr::gatherVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherVarDecls(decls); -} - - -void chillAST_ImplicitCastExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_ImplicitCastExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_ImplicitCastExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) { - subexpr->gatherDeclRefExprs(refs); -} - - -void chillAST_ImplicitCastExpr::gatherVarUsage(vector<chillAST_VarDecl *> &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<chillAST_ArraySubscriptExpr *> &refs, bool w) { - subexpr->gatherArrayRefs(refs, w); -} - -void chillAST_CStyleCastExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) { - subexpr->gatherScalarRefs(refs, writtento); -} - - -void chillAST_CStyleCastExpr::gatherVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherVarDecls(decls); -} - - -void chillAST_CStyleCastExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_CStyleCastExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_CStyleCastExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) { - subexpr->gatherDeclRefExprs(refs); -} - - -void chillAST_CStyleCastExpr::gatherVarUsage(vector<chillAST_VarDecl *> &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<chillAST_ArraySubscriptExpr *> &refs, bool w) { - subexpr->gatherArrayRefs(refs, w); -} - -void chillAST_CStyleAddressOf::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) { - subexpr->gatherScalarRefs(refs, writtento); -} - -void chillAST_CStyleAddressOf::gatherVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherVarDecls(decls); -} - -void chillAST_CStyleAddressOf::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_CStyleAddressOf::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_CStyleAddressOf::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) { - subexpr->gatherDeclRefExprs(refs); -} - - -void chillAST_CStyleAddressOf::gatherVarUsage(vector<chillAST_VarDecl *> &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<chillAST_ArraySubscriptExpr *> &refs, bool writtento) { - sizeexpr->gatherArrayRefs(refs, writtento); -}; - - -void chillAST_Malloc::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) { - sizeexpr->gatherScalarRefs(refs, writtento); -}; - -void chillAST_Malloc::gatherVarDecls(vector<chillAST_VarDecl *> &decls) { - sizeexpr->gatherVarDecls(decls); -}; - -void chillAST_Malloc::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - sizeexpr->gatherScalarVarDecls(decls); -}; - -void chillAST_Malloc::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - sizeexpr->gatherArrayVarDecls(decls); -}; - -void chillAST_Malloc::gatherVarUsage(vector<chillAST_VarDecl *> &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<chillAST_ArraySubscriptExpr *> &refs, bool w) { - devPtr->gatherArrayRefs(refs, false); - sizeinbytes->gatherArrayRefs(refs, false); + chillAST_Node::gatherArrayRefs(refs,false); } void chillAST_CudaMalloc::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) { - devPtr->gatherScalarRefs(refs, false); - sizeinbytes->gatherScalarRefs(refs, false); -} - -void chillAST_CudaMalloc::gatherVarDecls(vector<chillAST_VarDecl *> &decls) { - devPtr->gatherVarDecls(decls); - sizeinbytes->gatherVarDecls(decls); -} - - -void chillAST_CudaMalloc::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - devPtr->gatherScalarVarDecls(decls); - sizeinbytes->gatherScalarVarDecls(decls); + chillAST_Node::gatherScalarRefs(refs,false); } - -void chillAST_CudaMalloc::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - devPtr->gatherArrayVarDecls(decls); - sizeinbytes->gatherArrayVarDecls(decls); -} - - -void chillAST_CudaMalloc::gatherVarUsage(vector<chillAST_VarDecl *> &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<chillAST_VarDecl *> &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<chillAST_VarDecl *> &decls) { - if (returnvalue) returnvalue->gatherVarDecls(decls); -} - - -void chillAST_ReturnStmt::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - if (returnvalue) returnvalue->gatherScalarVarDecls(decls); -} - - -void chillAST_ReturnStmt::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - if (returnvalue) returnvalue->gatherArrayVarDecls(decls); -} - - -void chillAST_ReturnStmt::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) { - if (returnvalue) returnvalue->gatherDeclRefExprs(refs); -} - - -void chillAST_ReturnStmt::gatherVarUsage(vector<chillAST_VarDecl *> &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<chillAST_ArraySubscriptExpr *> &refs, bool writtento) { - subexpr->gatherArrayRefs(refs, writtento); -} - -void chillAST_ParenExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &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<chillAST_VarDecl *> &decls) { - subexpr->gatherVarDecls(decls); -} - - -void chillAST_ParenExpr::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_ParenExpr::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_ParenExpr::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) { - subexpr->gatherDeclRefExprs(refs); -} - -void chillAST_ParenExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { - subexpr->replaceVarDecls(olddecl, newdecl); -} - -void chillAST_ParenExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherVarUsage(decls); -} - - chillAST_Sizeof::chillAST_Sizeof(char *athing) { thing = strdup(athing); // memory leak } -void chillAST_Sizeof::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {} - -void chillAST_Sizeof::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &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<chillAST_VarDecl *> &decls) { // TODO -} - - -void chillAST_Sizeof::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { // TODO -} - - -void chillAST_Sizeof::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { // TODO -} - - -void chillAST_Sizeof::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) { - // TODO -} - - -void chillAST_Sizeof::gatherVarUsage(vector<chillAST_VarDecl *> &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<chillAST_Node *> &code, vector<chillAST_VarDecl *> &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<chillAST_VarDecl *> &decls) { - if (cond) cond->gatherVarDecls(decls); - if (thenpart) thenpart->gatherVarDecls(decls); - if (elsepart) elsepart->gatherVarDecls(decls); -} - - -void chillAST_IfStmt::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - if (cond) cond->gatherScalarVarDecls(decls); - if (thenpart) thenpart->gatherScalarVarDecls(decls); - if (elsepart) elsepart->gatherScalarVarDecls(decls); -} - - -void chillAST_IfStmt::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - if (cond) cond->gatherArrayVarDecls(decls); - if (thenpart) thenpart->gatherArrayVarDecls(decls); - if (elsepart) elsepart->gatherArrayVarDecls(decls); -} - - -void chillAST_IfStmt::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &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<chillAST_VarDecl *> &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<chillAST_ArraySubscriptExpr *> &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<chillAST_DeclRefExpr *> &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<chillAST_Node *> &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<omega::CG_outputRepr *> 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<IntegerLiteral>(e) || isa<FloatingLiteral>(e) || isa<DeclRefExpr>(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) { |