diff options
| author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-30 12:48:59 -0600 | 
|---|---|---|
| committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-30 12:48:59 -0600 | 
| commit | f00e425e1d6ee51027e6ba66d0a82355fd788f9e (patch) | |
| tree | c2e164594671f45b29fa3d3935598381c848bc00 /include/chillAST | |
| parent | a679e8028eba8a6d9b3ed3d45ba0f397b1083f0c (diff) | |
| download | chill-f00e425e1d6ee51027e6ba66d0a82355fd788f9e.tar.gz chill-f00e425e1d6ee51027e6ba66d0a82355fd788f9e.tar.bz2 chill-f00e425e1d6ee51027e6ba66d0a82355fd788f9e.zip | |
ForStmt Cont.
Diffstat (limited to 'include/chillAST')
| -rw-r--r-- | include/chillAST/chillAST_node.hh | 58 | ||||
| -rw-r--r-- | include/chillAST/chillASTs.hh | 51 | 
2 files changed, 29 insertions, 80 deletions
| diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh index a8fb50f..255c07a 100644 --- a/include/chillAST/chillAST_node.hh +++ b/include/chillAST/chillAST_node.hh @@ -220,7 +220,7 @@ public:    void setChild(int which, chillAST_Node *n) {      children[which] = n; -    children[which]->parent = this; +    if (n) children[which]->parent = this;    };    void setMetaComment(const char *c) { metacomment = strdup(c); }; @@ -282,20 +282,10 @@ public:      exit(-1);    }; -  virtual void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) { -    CHILL_ERROR("(%s) forgot to implement gatherArrayRefs()\n", getTypeString()); -    dump(); -    print(); -    exit(-1); -  }; +  virtual void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);    // TODO we MIGHT want the VarDecl // NOTHING IMPLEMENTS THIS? ???  -  virtual void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) { -    CHILL_ERROR("(%s) forgot to implement gatherScalarRefs()\n", getTypeString()); -    dump(); -    print(); -    exit(-1); -  }; +  virtual void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);    //! recursive walk parent links, looking for loops, and grabbing the declRefExpr in the loop init and cond.    virtual void gatherLoopIndeces(std::vector<chillAST_VarDecl *> &indeces); @@ -307,25 +297,18 @@ public:    chillAST_Node *findContainingNonLoop();    // TODO gather loop init and cond (and if cond) like gatherloopindeces - -  virtual void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs) {  // both scalar and arrays -    fprintf(stderr, "(%s) forgot to implement gatherDeclRefExpr()\n", getTypeString()); -  }; +  //! gather both scalar and array references +  virtual void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs); -  virtual void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) { -    fprintf(stderr, "(%s) forgot to implement gatherVarUsage()\n", getTypeString()); -  }; +  virtual void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);    virtual void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls) {      fprintf(stderr, "(%s) forgot to implement gatherVarLHSUsage()\n", getTypeString());    };    //! ACTUAL Declaration -  virtual void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) { -    fprintf(stderr, "(%s) forgot to implement gatherVarDecls()\n", getTypeString()); -  }; - +  virtual void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);    virtual void    gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) {  // even if the decl itself is not in the ast. @@ -336,9 +319,7 @@ public:      fprintf(stderr, "(%s) forgot to implement gatherScalarVarDecls()\n", getTypeString());    }; -  virtual void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) {  // ACTUAL Declaration -    fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", getTypeString()); -  }; +  virtual void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);    virtual chillAST_VarDecl *findArrayDecl(const char *name) { // scoping TODO      if (!getSymbolTable()) return parent->findArrayDecl(name); // most things @@ -347,9 +328,7 @@ public:    } -  virtual void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { -    fprintf(stderr, "(%s) forgot to implement replaceVarDecls()\n", getTypeString()); -  }; +  virtual void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);    //! this just looks for ForStmts with preferred index metacomment attached    virtual bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { @@ -357,11 +336,12 @@ public:      return false;    } - -  virtual chillAST_Node *constantFold() {  // hacky. TODO. make nice -    CHILL_ERROR("(%s) forgot to implement constantFold()\n", getTypeString()); -    exit(-1);; -  }; +  //! Folding constant, to some degree. +  /*! +   * We shoud need to delegate this to the backend compiler +   * @return This node +   */ +  virtual chillAST_Node *constantFold();    virtual chillAST_Node *clone() {   // makes a deep COPY (?)      CHILL_ERROR("(%s) forgot to implement clone()\n", getTypeString()); @@ -409,13 +389,7 @@ public:    //! Get a vector of statements -  virtual void gatherStatements(std::vector<chillAST_Node *> &statements) { -    fprintf(stderr, "(%s) forgot to implement gatherStatements()\n", getTypeString()); -    dump(); -    fflush(stdout); -    print(); -    fprintf(stderr, "\n\n"); -  } +  virtual void gatherStatements(std::vector<chillAST_Node *> &statements);    virtual chillAST_SymbolTable *getParameters() { return parameters; } diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index a30a420..ea8feaa 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -532,11 +532,6 @@ public:  };  class chillAST_ForStmt : public chillAST_Node { -private: -  chillAST_Node *init; -  chillAST_Node *cond; -  chillAST_Node *incr; -  chillAST_Node *body; // always a compoundstmt?  public:    virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_FORSTMT; } @@ -555,17 +550,17 @@ public:    void removeSyncComment(); -  chillAST_Node *getInit() { return init; }; -  void setInit(chillAST_Node *i) { init = i; i->parent = this; } +  chillAST_Node *getInit() { return children[0]; }; +  void setInit(chillAST_Node *i) { setChild(0,i); } -  chillAST_Node *getCond() { return cond; }; -  void setCond(chillAST_Node *c) { cond = c; c->parent = this; } +  chillAST_Node *getCond() { return children[1]; }; +  void setCond(chillAST_Node *c) { setChild(1,c); } -  chillAST_Node *getInc() { return incr; }; -  void setInc(chillAST_Node *i) { incr = i; i->parent = this; } +  chillAST_Node *getInc() { return children[2]; }; +  void setInc(chillAST_Node *i) { setChild(2,i); } -  chillAST_Node *getBody() { return body; }; -  void setBody(chillAST_Node *b) { body = b; b->parent = this; }; +  chillAST_Node *getBody() { return children[3]; }; +  void setBody(chillAST_Node *b) { setChild(3,b); };    bool isNotLeaf() { return true; }; @@ -576,27 +571,10 @@ public:    // required methods that I can't seem to get to inherit    void printControl(int indent = 0, FILE *fp = stderr);  // print just for ( ... ) but not body -  chillAST_Node *constantFold(); -    chillAST_Node *clone(); -  void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls); -    void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); }; -  void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls); - -  void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls); - -  void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); - -  void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento); - -  void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls); - -  void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs); - -  void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); // will get called on inner loops    bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false);    void gatherLoopIndeces(std::vector<chillAST_VarDecl *> &indeces); @@ -607,11 +585,11 @@ public:      // ADD MYSELF!      loops.push_back(this); -    int n = body->children.size(); +    int n = getBody()->children.size();      //fprintf(stderr, "get_deep_loops of a %s with %d children\n", getTypeString(), n);       for (int i = 0; i < n; i++) { -      //fprintf(stderr, "child %d is a %s\n", i, body->children[i]->getTypeString());  -      body->children[i]->get_deep_loops(loops); +      //fprintf(stderr, "child %d is a %s\n", i, body->children[i]->getTypeString()); +      getBody()->children[i]->get_deep_loops(loops);      }      //fprintf(stderr, "found %d deep loops\n", loops.size());     } @@ -620,10 +598,10 @@ public:    void find_deepest_loops(std::vector<chillAST_ForStmt *> &loops) {      std::vector<chillAST_ForStmt *> b; // deepest loops below me -    int n = body->children.size(); +    int n = getBody()->children.size();      for (int i = 0; i < n; i++) {        std::vector<chillAST_ForStmt *> l; // deepest loops below one child -      body->children[i]->find_deepest_loops(l); +      getBody()->children[i]->find_deepest_loops(l);        if (l.size() > b.size()) { // a deeper nesting than we've seen          b = l;        } @@ -635,9 +613,6 @@ public:    void loseLoopWithLoopVar(char *var); // chillAST_ForStmt -  void replaceChild(chillAST_Node *old, chillAST_Node *newchild); - -  void gatherStatements(std::vector<chillAST_Node *> &statements);    bool lowerBound(int &l); | 
