From 79b47d47c0c8ecdce651024b41b9109f05593010 Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Fri, 30 Sep 2016 14:14:51 -0600 Subject: fixes --- include/chillAST/chillAST_node.hh | 3 +- include/chillAST/chillASTs.hh | 17 +++------ lib/chillcg/src/CG_chillBuilder.cc | 4 +-- src/chillASTs.cc | 70 +++++++++++--------------------------- src/ir_clang.cc | 2 +- src/printer/cfamily.cpp | 2 +- src/printer/dump.cpp | 2 +- 7 files changed, 30 insertions(+), 70 deletions(-) diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh index 4db00ce..ea9bf8b 100644 --- a/include/chillAST/chillAST_node.hh +++ b/include/chillAST/chillAST_node.hh @@ -39,7 +39,7 @@ protected: * Fix the pointer reference in a source file * @param nameMap a mapping from string to the corresponding declarations, stack is used to mimic scoping */ - void fixReference(std::map> nameMap); + void fixReference(std::map > nameMap); public: // TODO decide how to hide some data //! this Node's parent @@ -303,6 +303,7 @@ public: virtual void gatherVarUsage(std::vector &decls); + //! Gather all variable that is used as a lefthand side operand virtual void gatherVarLHSUsage(std::vector &decls) { fprintf(stderr, "(%s) forgot to implement gatherVarLHSUsage()\n", getTypeString()); }; diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index 795f12b..90f19e8 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -973,9 +973,9 @@ public: char *op; //! true for prefix unary operator bool prefix; - chillAST_Node *subexpr; // constructors + chillAST_UnaryOperator(); chillAST_UnaryOperator(const char *oper, bool pre, chillAST_Node *sub); // other methods particular to this type of node @@ -984,29 +984,20 @@ public: (!strcmp(op, "--"))); // are there more ??? TODO } + 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 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); // chillAST_UnaryOperator void gatherVarLHSUsage(std::vector &decls); - void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - - 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 diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc index 27d0af2..39223e9 100755 --- a/lib/chillcg/src/CG_chillBuilder.cc +++ b/lib/chillcg/src/CG_chillBuilder.cc @@ -125,8 +125,8 @@ namespace omega { chillAST_Node *SubUnaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { chillAST_UnaryOperator *u = (chillAST_UnaryOperator *) n; - chillAST_Node *sub = u->subexpr; - u->subexpr = substituteChill( oldvar, newvar, sub, u); + chillAST_Node *sub = u->getSubExpr(); + u->setSubExpr(substituteChill( oldvar, newvar, sub, u)); return u; } diff --git a/src/chillASTs.cc b/src/chillASTs.cc index 2f57197..edbe221 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -2070,45 +2070,43 @@ chillAST_Node *chillAST_FloatingLiteral::clone() { return newone; } -chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_Node *sub) { +chillAST_UnaryOperator::chillAST_UnaryOperator() { + children.push_back(NULL); +} + +chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_Node *sub):chillAST_UnaryOperator() { op = strdup(oper); prefix = pre; - subexpr = sub; - subexpr->setParent(this); + setSubExpr(sub); isFromSourceFile = true; // default filename = NULL; } void chillAST_UnaryOperator::gatherArrayRefs(std::vector &refs, bool w) { - subexpr->gatherArrayRefs(refs, isAssignmentOp()); // + getSubExpr()->gatherArrayRefs(refs, isAssignmentOp()); // } void chillAST_UnaryOperator::gatherVarLHSUsage(vector &decls) { - if ((!strcmp("++", op)) || (!strcmp("--", op))) { - subexpr->gatherVarUsage(decls); // do all unary modify the subexpr? (no, - ) + if (isAssignmentOp()) { + getSubExpr()->gatherVarUsage(decls); // do all unary modify the subexpr? (no, - ) } } chillAST_Node *chillAST_UnaryOperator::constantFold() { - //fprintf(stderr, "chillAST_UnaryOperator::constantFold() "); - //print(); fprintf(stderr, "\n"); + chillAST_Node::constantFold(); - subexpr = subexpr->constantFold(); chillAST_Node *returnval = this; - if (subexpr->isConstant()) { - //fprintf(stderr, "unary op folding constants\n"); - //print(0,stderr); fprintf(stderr, "\n"); - + if (getSubExpr()->isConstant()) { if (streq(op, "-")) { - if (subexpr->isIntegerLiteral()) { - int intval = ((chillAST_IntegerLiteral *) subexpr)->value; + if (getSubExpr()->isIntegerLiteral()) { + int intval = ((chillAST_IntegerLiteral *) getSubExpr())->value; chillAST_IntegerLiteral *I = new chillAST_IntegerLiteral(-intval); I->setParent(parent); returnval = I; //fprintf(stderr, "integer -%d becomes %d\n", intval, I->value); } else { - chillAST_FloatingLiteral *FL = (chillAST_FloatingLiteral *) subexpr; + chillAST_FloatingLiteral *FL = (chillAST_FloatingLiteral *) getSubExpr(); chillAST_FloatingLiteral *F = new chillAST_FloatingLiteral(FL); // clone F->parent = FL->parent; @@ -2125,48 +2123,18 @@ chillAST_Node *chillAST_UnaryOperator::constantFold() { class chillAST_Node *chillAST_UnaryOperator::clone() { - chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, subexpr->clone()); + chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, getSubExpr()->clone()); UO->setParent(parent); UO->isFromSourceFile = isFromSourceFile; if (filename) UO->filename = strdup(filename); return UO; } - -void chillAST_UnaryOperator::gatherVarDecls(vector &decls) { - subexpr->gatherVarDecls(decls); -} - - -void chillAST_UnaryOperator::gatherScalarVarDecls(vector &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_UnaryOperator::gatherArrayVarDecls(vector &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_UnaryOperator::gatherDeclRefExprs(vector &refs) { - subexpr->gatherDeclRefExprs(refs); -} - - -void chillAST_UnaryOperator::gatherVarUsage(vector &decls) { - subexpr->gatherVarUsage(decls); -} - -void chillAST_UnaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { - subexpr->replaceVarDecls(olddecl, newdecl); -} - - int chillAST_UnaryOperator::evalAsInt() { - if (!strcmp("+", op)) return subexpr->evalAsInt(); - if (!strcmp("-", op)) return -subexpr->evalAsInt(); - if (!strcmp("++", op)) return 1 + subexpr->evalAsInt(); - if (!strcmp("--", op)) return subexpr->evalAsInt() - 1; + if (!strcmp("+", op)) return getSubExpr()->evalAsInt(); + if (!strcmp("-", op)) return -getSubExpr()->evalAsInt(); + if (!strcmp("++", op)) return 1 + getSubExpr()->evalAsInt(); + if (!strcmp("--", op)) return getSubExpr()->evalAsInt() - 1; fprintf(stderr, "chillAST_UnaryOperator::evalAsInt() unhandled op '%s'\n", op); exit(-1); diff --git a/src/ir_clang.cc b/src/ir_clang.cc index b5634af..cb4cbb8 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -3085,7 +3085,7 @@ std::vector IR_clangCode::QueryExpOperand(const omega::C chillAST_UnaryOperator *uop = (chillAST_UnaryOperator *) e; char *op = uop->op; // TODO enum if (!strcmp(op, "+") || !strcmp(op, "-")) { - v.push_back(new omega::CG_chillRepr(uop->subexpr)); + v.push_back(new omega::CG_chillRepr(uop->getSubExpr())); } else { CHILL_ERROR("ir_clang.cc IR_clangCode::QueryExpOperand() Unary Operator UNHANDLED op (%s)\n", op); exit(-1); diff --git a/src/printer/cfamily.cpp b/src/printer/cfamily.cpp index 8aa6e62..5c56bd7 100644 --- a/src/printer/cfamily.cpp +++ b/src/printer/cfamily.cpp @@ -373,7 +373,7 @@ int CFamily::getPrecS(chillAST_UnaryOperator *n) { void CFamily::printS(std::string ident, chillAST_UnaryOperator *n, std::ostream &o) { int prec = getPrec(n); if (n->prefix) o << n->op; - printPrec(ident, n->subexpr, o, prec); + printPrec(ident, n->getSubExpr(), o, prec); if (!n->prefix) o << n->op; } diff --git a/src/printer/dump.cpp b/src/printer/dump.cpp index 066a2fe..059e56f 100644 --- a/src/printer/dump.cpp +++ b/src/printer/dump.cpp @@ -217,7 +217,7 @@ void Dump::printS(std::string ident, chillAST_TernaryOperator *n, std::ostream & void Dump::printS(std::string ident, chillAST_UnaryOperator *n, std::ostream &o) { if (n->prefix) o << "prefix "; else o << "postfix "; - print(ident, n->subexpr, o); + print(ident, n->getSubExpr(), o); } void Dump::printS(std::string ident, chillAST_VarDecl *n, std::ostream &o) { -- cgit v1.2.3-70-g09d2