From 699861922d5349ffa98b518f34016b2be2ca368d Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Fri, 23 Sep 2016 10:59:54 -0600 Subject: more changes --- include/chillAST/chillAST_def.hh | 90 +- include/chillAST/chillAST_node.hh | 665 ++++++------ include/chillAST/chillASTs.hh | 2174 +++++++++++++++++++++---------------- 3 files changed, 1676 insertions(+), 1253 deletions(-) (limited to 'include/chillAST') diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh index 318b51b..0e5832e 100644 --- a/include/chillAST/chillAST_def.hh +++ b/include/chillAST/chillAST_def.hh @@ -19,7 +19,7 @@ #define CHILLAST_NODETYPE_TRANSLATIONUNIT CHILLAST_NODETYPE_SOURCEFILE enum CHILL_ASTNODE_TYPE { - CHILLAST_NODETYPE_UNKNOWN=0, + CHILLAST_NODETYPE_UNKNOWN = 0, CHILLAST_NODETYPE_SOURCEFILE, CHILLAST_NODETYPE_TYPEDEFDECL, CHILLAST_NODETYPE_VARDECL, @@ -58,26 +58,26 @@ enum CHILL_ASTNODE_TYPE { CHILLAST_NODETYPE_CUDASYNCTHREADS, CHILLAST_NODETYPE_NULL // explicit non-statement // TODO - -} ; -enum CHILL_FUNCTION_TYPE { +}; + +enum CHILL_FUNCTION_TYPE { CHILL_FUNCTION_CPU = 0, CHILL_FUNCTION_GPU }; - -enum CHILL_MEMBER_EXP_TYPE { + +enum CHILL_MEMBER_EXP_TYPE { CHILL_MEMBER_EXP_DOT = 0, CHILL_MEMBER_EXP_ARROW }; - -enum CHILL_PREPROCESSING_TYPE { + +enum CHILL_PREPROCESSING_TYPE { CHILL_PREPROCESSING_TYPEUNKNOWN = 0, CHILL_PREPROCESSING_COMMENT, CHILL_PREPROCESSING_POUNDDEFINE, CHILL_PREPROCESSING_POUNDINCLUDE, CHILL_PREPROCESSING_PRAGMA // unused so far -}; +}; enum CHILL_PREPROCESSING_POSITION { // when tied to another statement CHILL_PREPROCESSING_POSITIONUNKNOWN = 0, @@ -87,14 +87,18 @@ enum CHILL_PREPROCESSING_POSITION { // when tied to another statement CHILL_PREPROCESSING_IMMEDIATELYBEFORE // on same line }; -char *parseUnderlyingType( char *sometype ); -char *parseArrayParts( char *sometype ); -bool isRestrict( const char *sometype ); -char *splitTypeInfo( char *underlyingtype ); -char *ulhack( char *brackets ); // change "1024UL" to "1024" -char *restricthack( char *typeinfo ); // remove __restrict__ , MODIFIES the argument! +char *parseUnderlyingType(char *sometype); + +char *parseArrayParts(char *sometype); + +bool isRestrict(const char *sometype); + +char *splitTypeInfo(char *underlyingtype); + +char *ulhack(char *brackets); // change "1024UL" to "1024" +char *restricthack(char *typeinfo); // remove __restrict__ , MODIFIES the argument! -extern const char* Chill_AST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST +extern const char *Chill_AST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST // fwd declarations class chillAST_node; // the generic node. specific types derive from this @@ -102,60 +106,88 @@ class chillAST_NULL; // empty class chillAST_SourceFile; // ast for an entire source file (translationunit) class chillAST_TypedefDecl; + class chillAST_VarDecl; + //class chillAST_ParmVarDecl; class chillAST_FunctionDecl; + class chillAST_RecordDecl; // structs and unions (and classes?) class chillAST_MacroDefinition; + class chillAST_CompoundStmt; // just a bunch of other statements class chillAST_ForStmt; // AKA a LOOP class chillAST_TernaryOperator; + class chillAST_BinaryOperator; + class chillAST_ArraySubscriptExpr; + class chillAST_MemberExpr; + class chillAST_DeclRefExpr; + class chillAST_IntegerLiteral; + class chillAST_FloatingLiteral; + class chillAST_UnaryOperator; + class chillAST_ImplicitCastExpr; + class chillAST_CStyleCastExpr; + class chillAST_CStyleAddressOf; + class chillAST_ReturnStmt; + class chillAST_CallExpr; + class chillAST_ParenExpr; + class chillAST_Sizeof; + class chillAST_Malloc; + class chillAST_Free; + class chillAST_NoOp; + class chillAST_CudaMalloc; + class chillAST_CudaFree; + class chillAST_CudaMemcpy; + class chillAST_CudaKernelCall; + class chillAST_CudaSyncthreads; + class chillAST_Preprocessing; -typedef std::vector chillAST_SymbolTable; // typedef +typedef std::vector chillAST_SymbolTable; // typedef typedef std::vector chillAST_TypedefTable; // typedef -bool symbolTableHasVariableNamed( chillAST_SymbolTable *table, const char *name ); // fwd decl -chillAST_VarDecl *symbolTableFindVariableNamed( chillAST_SymbolTable *table, const char *name ); // fwd decl TODO too many similar named functions +bool symbolTableHasVariableNamed(chillAST_SymbolTable *table, const char *name); // fwd decl +chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, + const char *name); // fwd decl TODO too many similar named functions -void printSymbolTable( chillAST_SymbolTable *st ); // fwd decl -void printSymbolTableMoreInfo( chillAST_SymbolTable *st ); // fwd decl +void printSymbolTable(chillAST_SymbolTable *st); // fwd decl +void printSymbolTableMoreInfo(chillAST_SymbolTable *st); // fwd decl -chillAST_node *lessthanmacro( chillAST_node *left, chillAST_node *right); // fwd declaration -chillAST_SymbolTable *addSymbolToTable( chillAST_SymbolTable *st, chillAST_VarDecl *vd ); // fwd decl -chillAST_TypedefTable *addTypedefToTable( chillAST_TypedefTable *tt, chillAST_TypedefDecl *td ); // fwd decl +chillAST_node *lessthanmacro(chillAST_node *left, chillAST_node *right); // fwd declaration +chillAST_SymbolTable *addSymbolToTable(chillAST_SymbolTable *st, chillAST_VarDecl *vd); // fwd decl +chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tt, chillAST_TypedefDecl *td); // fwd decl -bool streq( const char *a, const char *b); // fwd decl -void chillindent( int i, FILE *fp ); // fwd declaration -void insertNewDeclAtLocationOfOldIfNeeded( chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl); +bool streq(const char *a, const char *b); // fwd decl +void chillindent(int i, FILE *fp); // fwd declaration +void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl); -chillAST_DeclRefExpr *buildDeclRefExpr( chillAST_VarDecl *); +chillAST_DeclRefExpr *buildDeclRefExpr(chillAST_VarDecl *); -chillAST_FunctionDecl *findFunctionDecl( chillAST_node *node, const char *procname); +chillAST_FunctionDecl *findFunctionDecl(chillAST_node *node, const char *procname); #endif diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh index 70660c5..bc3facb 100644 --- a/include/chillAST/chillAST_node.hh +++ b/include/chillAST/chillAST_node.hh @@ -9,363 +9,402 @@ // nodes based on clang AST which are in turn based on C++ class chillAST_node { // generic node. a tree of these is the AST. this is virtual (can't instantiate) -public: +public: static int chill_scalar_counter; // for manufactured scalars - static int chill_array_counter ; // for manufactured arrays - static int chill_pointer_counter ; // for manufactured arrays + static int chill_array_counter; // for manufactured arrays + static int chill_pointer_counter; // for manufactured arrays CHILL_ASTNODE_TYPE asttype; - - bool isSourceFile() { return (asttype == CHILLAST_NODETYPE_SOURCEFILE); }; - bool isTypeDefDecl() { return (asttype == CHILLAST_NODETYPE_TYPEDEFDECL); }; - bool isVarDecl() { return (asttype == CHILLAST_NODETYPE_VARDECL); }; - bool isFunctionDecl() { return (asttype == CHILLAST_NODETYPE_FUNCTIONDECL); }; - bool isRecordDecl() { return (asttype == CHILLAST_NODETYPE_RECORDDECL); }; - bool isMacroDefinition() { return (asttype == CHILLAST_NODETYPE_MACRODEFINITION); }; - bool isCompoundStmt() { return (asttype == CHILLAST_NODETYPE_COMPOUNDSTMT); }; - bool isLoop() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA ForStmt - bool isForStmt() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA Loop - bool isIfStmt() { return (asttype == CHILLAST_NODETYPE_IFSTMT); }; - bool isTernaryOperator() { return (asttype == CHILLAST_NODETYPE_TERNARYOPERATOR);}; - bool isBinaryOperator() { return (asttype == CHILLAST_NODETYPE_BINARYOPERATOR); }; - bool isUnaryOperator() { return (asttype == CHILLAST_NODETYPE_UNARYOPERATOR); }; - bool isArraySubscriptExpr() { return (asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR); }; - bool isMemberExpr() { return (asttype == CHILLAST_NODETYPE_MEMBEREXPR); }; - bool isDeclRefExpr() { return (asttype == CHILLAST_NODETYPE_DECLREFEXPR); }; - bool isIntegerLiteral() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL); }; - bool isFloatingLiteral() { return (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); }; - bool isImplicitCastExpr() { return (asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR); }; - bool isReturnStmt() { return (asttype == CHILLAST_NODETYPE_RETURNSTMT); }; - bool isCallExpr() { return (asttype == CHILLAST_NODETYPE_CALLEXPR); }; - bool isParenExpr() { return (asttype == CHILLAST_NODETYPE_PARENEXPR); }; - bool isSizeof() { return (asttype == CHILLAST_NODETYPE_SIZEOF); }; - bool isMalloc() { return (asttype == CHILLAST_NODETYPE_MALLOC); }; - bool isFree() { return (asttype == CHILLAST_NODETYPE_FREE); }; - bool isPreprocessing() { return (asttype == CHILLAST_NODETYPE_PREPROCESSING); }; - bool isNoOp() { return (asttype == CHILLAST_NODETYPE_NOOP); }; - bool isNull() { return (asttype == CHILLAST_NODETYPE_NULL); }; - bool isCStyleCastExpr() { return (asttype == CHILLAST_NODETYPE_CSTYLECASTEXPR); }; - bool isCStyleAddressOf() { return (asttype == CHILLAST_NODETYPE_CSTYLEADDRESSOF); }; - bool isCudaMalloc() { return (asttype == CHILLAST_NODETYPE_CUDAMALLOC); }; - bool isCudaFree() { return (asttype == CHILLAST_NODETYPE_CUDAFREE); }; - bool isCudaMemcpy() { return (asttype == CHILLAST_NODETYPE_CUDAMEMCPY); }; - bool isCudaKERNELCALL() { return (asttype == CHILLAST_NODETYPE_CUDAKERNELCALL); }; - bool isCudaSYNCTHREADS() { return (asttype == CHILLAST_NODETYPE_CUDASYNCTHREADS); }; - - bool isDeclStmt() { return (asttype == CHILLAST_NODETYPE_DECLSTMT); }; // doesn't exist - - bool isConstant() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL) || (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); } - - - virtual bool isAssignmentOp() { return false; }; - virtual bool isComparisonOp() { return false; }; - virtual bool isNotLeaf() { return false; }; - virtual bool isLeaf() { return true; }; - virtual bool isParmVarDecl() { return false; }; - - virtual bool isPlusOp() { return false; }; - virtual bool isMinusOp() { return false; }; - virtual bool isPlusMinusOp() { return false; }; - virtual bool isMultDivOp() { return false; }; - - virtual bool isAStruct() { return false; }; - virtual bool isAUnion() { return false; }; - - virtual bool hasSymbolTable() { return false; } ; // most nodes do NOT have a symbol table - virtual bool hasTypedefTable() { return false; } ; // most nodes do NOT have a typedef table + + bool isSourceFile() { return (asttype == CHILLAST_NODETYPE_SOURCEFILE); }; + + bool isTypeDefDecl() { return (asttype == CHILLAST_NODETYPE_TYPEDEFDECL); }; + + bool isVarDecl() { return (asttype == CHILLAST_NODETYPE_VARDECL); }; + + bool isFunctionDecl() { return (asttype == CHILLAST_NODETYPE_FUNCTIONDECL); }; + + bool isRecordDecl() { return (asttype == CHILLAST_NODETYPE_RECORDDECL); }; + + bool isMacroDefinition() { return (asttype == CHILLAST_NODETYPE_MACRODEFINITION); }; + + bool isCompoundStmt() { return (asttype == CHILLAST_NODETYPE_COMPOUNDSTMT); }; + + bool isLoop() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA ForStmt + bool isForStmt() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA Loop + bool isIfStmt() { return (asttype == CHILLAST_NODETYPE_IFSTMT); }; + + bool isTernaryOperator() { return (asttype == CHILLAST_NODETYPE_TERNARYOPERATOR); }; + + bool isBinaryOperator() { return (asttype == CHILLAST_NODETYPE_BINARYOPERATOR); }; + + bool isUnaryOperator() { return (asttype == CHILLAST_NODETYPE_UNARYOPERATOR); }; + + bool isArraySubscriptExpr() { return (asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR); }; + + bool isMemberExpr() { return (asttype == CHILLAST_NODETYPE_MEMBEREXPR); }; + + bool isDeclRefExpr() { return (asttype == CHILLAST_NODETYPE_DECLREFEXPR); }; + + bool isIntegerLiteral() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL); }; + + bool isFloatingLiteral() { return (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); }; + + bool isImplicitCastExpr() { return (asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR); }; + + bool isReturnStmt() { return (asttype == CHILLAST_NODETYPE_RETURNSTMT); }; + + bool isCallExpr() { return (asttype == CHILLAST_NODETYPE_CALLEXPR); }; + + bool isParenExpr() { return (asttype == CHILLAST_NODETYPE_PARENEXPR); }; + + bool isSizeof() { return (asttype == CHILLAST_NODETYPE_SIZEOF); }; + + bool isMalloc() { return (asttype == CHILLAST_NODETYPE_MALLOC); }; + + bool isFree() { return (asttype == CHILLAST_NODETYPE_FREE); }; + + bool isPreprocessing() { return (asttype == CHILLAST_NODETYPE_PREPROCESSING); }; + + bool isNoOp() { return (asttype == CHILLAST_NODETYPE_NOOP); }; + + bool isNull() { return (asttype == CHILLAST_NODETYPE_NULL); }; + + bool isCStyleCastExpr() { return (asttype == CHILLAST_NODETYPE_CSTYLECASTEXPR); }; + + bool isCStyleAddressOf() { return (asttype == CHILLAST_NODETYPE_CSTYLEADDRESSOF); }; + + bool isCudaMalloc() { return (asttype == CHILLAST_NODETYPE_CUDAMALLOC); }; + + bool isCudaFree() { return (asttype == CHILLAST_NODETYPE_CUDAFREE); }; + + bool isCudaMemcpy() { return (asttype == CHILLAST_NODETYPE_CUDAMEMCPY); }; + + bool isCudaKERNELCALL() { return (asttype == CHILLAST_NODETYPE_CUDAKERNELCALL); }; + + bool isCudaSYNCTHREADS() { return (asttype == CHILLAST_NODETYPE_CUDASYNCTHREADS); }; + + bool isDeclStmt() { return (asttype == CHILLAST_NODETYPE_DECLSTMT); }; // doesn't exist + + bool isConstant() { + return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL) || (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); + } + + + virtual bool isAssignmentOp() { return false; }; + + virtual bool isComparisonOp() { return false; }; + + virtual bool isNotLeaf() { return false; }; + + virtual bool isLeaf() { return true; }; + + virtual bool isParmVarDecl() { return false; }; + + virtual bool isPlusOp() { return false; }; + + virtual bool isMinusOp() { return false; }; + + virtual bool isPlusMinusOp() { return false; }; + + virtual bool isMultDivOp() { return false; }; + + virtual bool isAStruct() { return false; }; + + virtual bool isAUnion() { return false; }; + + virtual bool hasSymbolTable() { return false; }; // most nodes do NOT have a symbol table + virtual bool hasTypedefTable() { return false; }; // most nodes do NOT have a typedef table virtual chillAST_SymbolTable *getSymbolTable() { return NULL; } // most nodes do NOT have a symbol table - virtual chillAST_VarDecl *findVariableNamed( const char *name ); // recursive + virtual chillAST_VarDecl *findVariableNamed(const char *name); // recursive + + chillAST_RecordDecl *findRecordDeclNamed(const char *name); // recursive - chillAST_RecordDecl *findRecordDeclNamed( const char *name ); // recursive - // void addDecl( chillAST_VarDecl *vd); // recursive, adds to first symbol table it can find // TODO decide how to hide some data - chillAST_node *parent; + chillAST_node *parent; bool isFromSourceFile; // false = #included char *filename; // file this node is from - void segfault() { fprintf(stderr, "segfaulting on purpose\n"); int *i=0; int j = i[0]; }; // seg fault - int getNumChildren() { return children.size(); }; - std::vector children; - std::vector getChildren() { return children; } ; // not usually useful - void setChildren( std::vector&c ) { children = c; } ; // does not set parent. probably should - chillAST_node *getChild( int which) { return children[which]; }; - void setChild( int which, chillAST_node *n ) { children[which] = n; children[which]->parent = this; } ; - + int getNumChildren() { return children.size(); }; + std::vector children; + + std::vector& getChildren() { return children; }; // not usually useful + void setChildren(std::vector &c) { children = c; }; // does not set parent. probably should + chillAST_node *getChild(int which) { return children[which]; }; + + void setChild(int which, chillAST_node *n) { + children[which] = n; + children[which]->parent = this; + }; + char *metacomment; // for compiler internals, formerly a comment - void setMetaComment( char *c ) { metacomment = strdup(c); }; + void setMetaComment(const char *c) { metacomment = strdup(c); }; - std::vector preprocessinginfo; + std::vector preprocessinginfo; - virtual void addChild( chillAST_node* c) { - //if (c->isFunctionDecl()) fprintf(stderr, "addchild FunctionDecl\n"); + virtual void addChild(chillAST_node *c) { c->parent = this; // check to see if it's already there - for (int i=0; igetTypeString(), i); - node->parent = this; - children.insert( children.begin()+i, node ); + node->parent = this; + children.insert(children.begin() + i, node); }; - - virtual void removeChild(int i) { - children.erase( children.begin()+i ); + + virtual void removeChild(int i) { + children.erase(children.begin() + i); }; - - int findChild( chillAST_node *c ) { - for (int i=0; isetParent( this ); - return; + newchild->setParent(this); + return; } } - fprintf(stderr, "%s %p generic replaceChild called with oldchild that was not a child\n", - getTypeString(), this) ; - fprintf(stderr, "printing\n"); - print(); fprintf(stderr, "\nchild: "); - if (!old) fprintf(stderr, "oldchild NULL!\n"); - old->print(); fprintf(stderr, "\nnew: "); - newchild->print(); fprintf(stderr, "\n"); - segfault(); // make easier for gdb + CHILL_ERROR("%s %p generic replaceChild called with oldchild that was not a child\n", + getTypeString(), this); + CHILL_DEBUG_BEGIN + fprintf(stderr, "printing\n"); + print(); + fprintf(stderr, "\nchild: "); + if (!old) fprintf(stderr, "oldchild NULL!\n"); + old->print(); + fprintf(stderr, "\nnew: "); + newchild->print(); + fprintf(stderr, "\n"); + CHILL_DEBUG_END + exit(-1); }; - - virtual void loseLoopWithLoopVar( char *var ) { - // walk tree. If a loop has this loop variable, replace the loop with the loop body, - // removing the loop. The loop will be spread across a bunch of cores that will each - // calculate their own loop variable. - - // things that can not have loops as substatements can have a null version of this method - // things that have more complicated sets of "children" will have specialized versions - - // this is the generic version of the method. It just recurses among its children. - // ForStmt is the only one that can actually remove itself. When it does, it will - // potentially change the children vector, which is not the simple array it might appear. - // so you have to make a copy of the vector to traverse - - std::vector dupe = children; // simple enough? - //fprintf(stderr, "node XXX has %d children\n", dupe.size()); - //fprintf(stderr, "generic node %s has %d children\n", getTypeString(), dupe.size()); - for (int i=0; iloseLoopWithLoopVar( var ); + + //! Spread the loop across a bunch of cores that will each calculate its own loop variable. + /*! + * If a loop has this loop variable, replace the loop with the loop body, calculate their own loop variable. + * + * things that can not have loops as substatements can have a null version of this method + * things that have more complicated sets of "children" will have specialized versions + * + * this is the generic version of the method. It just recurses among its children. + * ForStmt is the only one that can actually remove itself. When it does, it will + * potentially change the children vector, which is not the simple array it might appear. + * so you have to make a copy of the vector to traverse + * + * @param var + */ + virtual void loseLoopWithLoopVar(char *var) { + std::vector dupe = children; // simple enough? + for (int i = 0; i < dupe.size(); i++) { // recurse on all children + dupe[i]->loseLoopWithLoopVar(var); } } - virtual int evalAsInt() { - fprintf(stderr,"(%s) can't be evaluated as an integer??\n", Chill_AST_Node_Names[asttype]); - print(); fprintf(stderr, "\n"); - segfault(); + virtual int evalAsInt() { + CHILL_ERROR("(%s) can't be evaluated as an integer??\n", Chill_AST_Node_Names[asttype]); + print(); + exit(-1); } - virtual const char* getUnderlyingType() { - fprintf(stderr,"(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]); + virtual const char *getUnderlyingType() { + CHILL_ERROR("(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]); dump(); print(); - fprintf(stderr, "\n\n"); - segfault(); - }; + exit(-1); + }; - virtual chillAST_VarDecl* getUnderlyingVarDecl() { - fprintf(stderr,"(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]); + virtual chillAST_VarDecl *getUnderlyingVarDecl() { + CHILL_ERROR("(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]); dump(); print(); - fprintf(stderr, "\n\n"); - segfault(); - }; + exit(-1); + }; - virtual chillAST_node *findref(){// find the SINGLE constant or data reference at this node or below - fprintf(stderr,"(%s) forgot to implement findref()\n" ,Chill_AST_Node_Names[asttype]); + virtual chillAST_node *findref() {// find the SINGLE constant or data reference at this node or below + CHILL_ERROR("(%s) forgot to implement findref()\n", Chill_AST_Node_Names[asttype]); dump(); print(); - fprintf(stderr, "\n\n"); - segfault(); + exit(-1); }; - virtual void gatherArrayRefs( std::vector &refs, bool writtento ) { - fprintf(stderr,"(%s) forgot to implement gatherArrayRefs()\n" ,Chill_AST_Node_Names[asttype]); + virtual void gatherArrayRefs(std::vector &refs, bool writtento) { + CHILL_ERROR("(%s) forgot to implement gatherArrayRefs()\n", Chill_AST_Node_Names[asttype]); dump(); print(); - fprintf(stderr, "\n\n"); + exit(-1); }; - + // TODO we MIGHT want the VarDecl // NOTHING IMPLEMENTS THIS? ??? - virtual void gatherScalarRefs( std::vector &refs, bool writtento ) { - fprintf(stderr,"(%s) forgot to implement gatherScalarRefs()\n" ,Chill_AST_Node_Names[asttype]); + virtual void gatherScalarRefs(std::vector &refs, bool writtento) { + CHILL_ERROR("(%s) forgot to implement gatherScalarRefs()\n", Chill_AST_Node_Names[asttype]); dump(); print(); - fprintf(stderr, "\n\n"); + exit(-1); }; - - virtual void gatherLoopIndeces( std::vector &indeces ) { // recursive walk parent links, looking for loops, and grabbing the declRefExpr in the loop init and cond. - // you can quit when you get to certain nodes - //fprintf(stderr, "%s::gatherLoopIndeces()\n", getTypeString()); - - if (isSourceFile() || isFunctionDecl() ) return; // end of the line + //! recursive walk parent links, looking for loops, and grabbing the declRefExpr in the loop init and cond. + virtual void gatherLoopIndeces( + std::vector &indeces) { + // you can quit when you get to certain nodes - // just for debugging - //if (parent) { - // fprintf(stderr, "%s has parent of type %s\n", getTypeString(), parent->getTypeString()); - //} - //else fprintf(stderr, "this %s %p has no parent???\n", getTypeString(), this); + CHILL_DEBUG_PRINT("%s::gatherLoopIndeces()\n", getTypeString()); + if (isSourceFile() || isFunctionDecl()) return; // end of the line if (!parent) return; // should not happen, but be careful // for most nodes, this just recurses upwards - //fprintf(stderr, "%s::gatherLoopIndeces() %p recursing up\n", this); - parent->gatherLoopIndeces( indeces ); + parent->gatherLoopIndeces(indeces); } - - chillAST_ForStmt* findContainingLoop() { // recursive walk parent links, looking for loops - //fprintf(stderr, "%s::findContainingLoop() ", getTypeString()); - //if (parent) fprintf(stderr, "parents is a %s\n", parent->getTypeString()); - //else fprintf(stderr, "no parent\n"); - // do not check SELF type, as we may want to find the loop containing a loop + //! recursive walk parent links, looking for loops + chillAST_ForStmt *findContainingLoop() { + CHILL_DEBUG_PRINT("%s::findContainingLoop() ", getTypeString()); if (!parent) return NULL; - if (parent->isForStmt()) return (chillAST_ForStmt*)parent; + if (parent->isForStmt()) return (chillAST_ForStmt *) parent; return parent->findContainingLoop(); // recurse upwards } - chillAST_node* findContainingNonLoop() { // recursive walk parent links, avoiding loops - fprintf(stderr, "%s::findContainingNonLoop() ", getTypeString()); - //if (parent) fprintf(stderr, "parent is a %s\n", parent->getTypeString()); - //else fprintf(stderr, "no parent\n"); - // do not check SELF type, as we may want to find the loop containing a loop + //! recursive walk parent links, avoiding loops + chillAST_node *findContainingNonLoop() { + fprintf(stderr, "%s::findContainingNonLoop() ", getTypeString()); if (!parent) return NULL; - if (parent->isCompoundStmt() && parent->getParent()->isForStmt()) return parent->getParent()->findContainingNonLoop(); // keep recursing + if (parent->isCompoundStmt() && parent->getParent()->isForStmt()) + return parent->getParent()->findContainingNonLoop(); // keep recursing if (parent->isForStmt()) return parent->findContainingNonLoop(); // keep recursing - return (chillAST_node*)parent; // return non-loop + return (chillAST_node *) parent; // return non-loop } // TODO gather loop init and cond (and if cond) like gatherloopindeces - virtual void gatherDeclRefExprs( std::vector&refs ){ // both scalar and arrays - fprintf(stderr,"(%s) forgot to implement gatherDeclRefExpr()\n" ,Chill_AST_Node_Names[asttype]); + virtual void gatherDeclRefExprs(std::vector &refs) { // both scalar and arrays + fprintf(stderr, "(%s) forgot to implement gatherDeclRefExpr()\n", Chill_AST_Node_Names[asttype]); }; + virtual void gatherVarUsage(std::vector &decls) { + fprintf(stderr, "(%s) forgot to implement gatherVarUsage()\n", Chill_AST_Node_Names[asttype]); + }; - virtual void gatherVarUsage( std::vector &decls ) { - fprintf(stderr,"(%s) forgot to implement gatherVarUsage()\n" ,Chill_AST_Node_Names[asttype]); - }; - - virtual void gatherVarLHSUsage( std::vector &decls ) { - fprintf(stderr,"(%s) forgot to implement gatherVarLHSUsage()\n" ,Chill_AST_Node_Names[asttype]); - }; + virtual void gatherVarLHSUsage(std::vector &decls) { + fprintf(stderr, "(%s) forgot to implement gatherVarLHSUsage()\n", Chill_AST_Node_Names[asttype]); + }; + //! ACTUAL Declaration + virtual void gatherVarDecls(std::vector &decls) { + fprintf(stderr, "(%s) forgot to implement gatherVarDecls()\n", Chill_AST_Node_Names[asttype]); + }; - virtual void gatherVarDecls( std::vector &decls ) { // ACTUAL Declaration - fprintf(stderr,"(%s) forgot to implement gatherVarDecls()\n" ,Chill_AST_Node_Names[asttype]); - }; - - virtual void gatherVarDeclsMore( std::vector &decls ) { // even if the decl itself is not in the ast. - fprintf(stderr,"(%s) forgot to implement gatherVarDeclsMore()\n" ,Chill_AST_Node_Names[asttype]); - }; + virtual void + gatherVarDeclsMore(std::vector &decls) { // even if the decl itself is not in the ast. + fprintf(stderr, "(%s) forgot to implement gatherVarDeclsMore()\n", Chill_AST_Node_Names[asttype]); + }; - virtual void gatherScalarVarDecls( std::vector &decls ) { // ACTUAL Declaration - fprintf(stderr,"(%s) forgot to implement gatherScalarVarDecls()\n" ,Chill_AST_Node_Names[asttype]); - }; + virtual void gatherScalarVarDecls(std::vector &decls) { // ACTUAL Declaration + fprintf(stderr, "(%s) forgot to implement gatherScalarVarDecls()\n", Chill_AST_Node_Names[asttype]); + }; - virtual void gatherArrayVarDecls( std::vector &decls ) { // ACTUAL Declaration - fprintf(stderr,"(%s) forgot to implement gatherArrayVarDecls()\n" ,Chill_AST_Node_Names[asttype]); - }; + virtual void gatherArrayVarDecls(std::vector &decls) { // ACTUAL Declaration + fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", Chill_AST_Node_Names[asttype]); + }; - virtual chillAST_VarDecl *findArrayDecl( const char *name ) { // scoping TODO - if (!hasSymbolTable()) return parent->findArrayDecl( name ); // most things + virtual chillAST_VarDecl *findArrayDecl(const char *name) { // scoping TODO + if (!hasSymbolTable()) return parent->findArrayDecl(name); // most things else - fprintf(stderr,"(%s) forgot to implement gatherArrayVarDecls()\n" ,Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", Chill_AST_Node_Names[asttype]); } - virtual void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { - fprintf(stderr,"(%s) forgot to implement replaceVarDecls()\n" ,Chill_AST_Node_Names[asttype]); - }; + virtual void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { + fprintf(stderr, "(%s) forgot to implement replaceVarDecls()\n", Chill_AST_Node_Names[asttype]); + }; - virtual bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ) { - // this just looks for ForStmts with preferred index metacomment attached - fprintf(stderr,"(%s) forgot to implement findLoopIndexesToReplace()\n" ,Chill_AST_Node_Names[asttype]); - return false; + //! this just looks for ForStmts with preferred index metacomment attached + virtual bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { + fprintf(stderr, "(%s) forgot to implement findLoopIndexesToReplace()\n", Chill_AST_Node_Names[asttype]); + return false; } - - virtual chillAST_node* constantFold() { // hacky. TODO. make nice - fprintf(stderr,"(%s) forgot to implement constantFold()\n" ,Chill_AST_Node_Names[asttype]); - exit(-1); ; + + virtual chillAST_node *constantFold() { // hacky. TODO. make nice + CHILL_ERROR("(%s) forgot to implement constantFold()\n", Chill_AST_Node_Names[asttype]); + exit(-1);; }; - virtual chillAST_node* clone() { // makes a deep COPY (?) - fprintf(stderr,"(%s) forgot to implement clone()\n" ,Chill_AST_Node_Names[asttype]); - exit(-1); ; + virtual chillAST_node *clone() { // makes a deep COPY (?) + CHILL_ERROR("(%s) forgot to implement clone()\n", Chill_AST_Node_Names[asttype]); + exit(-1);; }; - virtual void dump( int indent=0, FILE *fp = stderr ) { - fflush(fp); - fprintf(fp,"(%s) forgot to implement dump()\n" ,Chill_AST_Node_Names[asttype]); };// print ast - - virtual void print( int indent=0, FILE *fp = stderr ) { - fflush(fp); - //fprintf(stderr, "generic chillAST_node::print() called!\n"); - //fprintf(stderr, "asttype is %d\n", asttype); + + //! Print AST + virtual void dump(int indent = 0, FILE *fp = stderr) { + fflush(fp); + CHILL_ERROR("(%s) forgot to implement dump()\n", Chill_AST_Node_Names[asttype]); + };// print ast + + // TODO We might want to print the code a bit differently, This can be only a generic dump + //! Print CODE + virtual void print(int indent = 0, FILE *fp = stderr) { + fflush(fp); fprintf(fp, "\n"); - chillindent(indent, fp); - fprintf(fp,"(%s) forgot to implement print()\n" ,Chill_AST_Node_Names[asttype]); - };// print CODE - - virtual void printName( int indent=0, FILE *fp = stderr ) { - fflush(fp); - //fprintf(stderr, "generic chillAST_node::printName() called!\n"); - //fprintf(stderr, "asttype is %d\n", asttype); + chillindent(indent, fp); + fprintf(fp, "(%s) forgot to implement print()\n", Chill_AST_Node_Names[asttype]); + }; + + virtual void printName(int indent = 0, FILE *fp = stderr) { + fflush(fp); fprintf(fp, "\n"); - chillindent(indent, fp); - fprintf(fp,"(%s) forgot to implement printName()\n" ,Chill_AST_Node_Names[asttype]); + chillindent(indent, fp); + fprintf(fp, "(%s) forgot to implement printName()\n", Chill_AST_Node_Names[asttype]); };// print CODE - virtual char *stringRep(int indent=0 ) { // the ast's print version + //! The AST's print version + virtual char *stringRep(int indent = 0) { fflush(stdout); - // chillindent(indent, fp); TODO - fprintf(stderr,"(%s) forgot to implement stringRep()\n" ,Chill_AST_Node_Names[asttype]); - segfault(); + // TODO chillindent(indent, fp); + CHILL_ERROR("(%s) forgot to implement stringRep()\n", Chill_AST_Node_Names[asttype]); + exit(-1); } - virtual void printonly( int indent=0, FILE *fp = stderr ) { print( indent, fp); }; + virtual void printonly(int indent = 0, FILE *fp = stderr) { print(indent, fp); }; - //virtual void printString( std::string &s ) { + //virtual void printString( std::string &s ) { // fprintf(stderr,"(%s) forgot to implement printString()\n" ,Chill_AST_Node_Names[asttype]); //} - virtual void get_top_level_loops( std::vector &loops) { - int n = children.size(); + virtual void get_top_level_loops(std::vector &loops) { + int n = children.size(); //fprintf(stderr, "get_top_level_loops of a %s with %d children\n", getTypeString(), n); - for (int i=0; igetTypeString()); if (children[i]->isForStmt()) { - loops.push_back( ((chillAST_ForStmt *)(children[i])) ); + loops.push_back(((chillAST_ForStmt *) (children[i]))); } } //fprintf(stderr, "found %d top level loops\n", loops.size()); @@ -373,128 +412,142 @@ public: virtual void repairParentChild() { // for nodes where all subnodes are children - int n = children.size(); - for (int i=0; iparent != this) { - fprintf(stderr, "fixing child %s that didn't know its parent\n", children[i]->getTypeString()); - children[i]->parent = this; + int n = children.size(); + for (int i = 0; i < n; i++) { + if (children[i]->parent != this) { + fprintf(stderr, "fixing child %s that didn't know its parent\n", children[i]->getTypeString()); + children[i]->parent = this; } } } - - virtual void get_deep_loops( std::vector &loops) { // this is probably broken - returns ALL loops under it - int n = children.size(); + virtual void + get_deep_loops(std::vector &loops) { // this is probably broken - returns ALL loops under it + int n = children.size(); //fprintf(stderr, "get_deep_loops of a %s with %d children\n", getTypeString(), n); - for (int i=0; igetTypeString()); - children[i]->get_deep_loops( loops ); + children[i]->get_deep_loops(loops); } //fprintf(stderr, "found %d deep loops\n", loops.size()); } // generic for chillAST_node with children - virtual void find_deepest_loops( std::vector &loops) { // returns DEEPEST nesting of loops - std::vectordeepest; // deepest below here - - int n = children.size(); + virtual void find_deepest_loops(std::vector &loops) { // returns DEEPEST nesting of loops + std::vector deepest; // deepest below here + + int n = children.size(); //fprintf(stderr, "find_deepest_loops of a %s with %d children\n", getTypeString(), n); - for (int i=0; i subloops; // loops below here among a child of mine - + //fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString()); - children[i]->find_deepest_loops( subloops ); - - if (subloops.size() > deepest.size()) { + children[i]->find_deepest_loops(subloops); + + if (subloops.size() > deepest.size()) { deepest = subloops; } } - + // append deepest we see at this level to loops - for ( int i=0; igetSourceFile(); - fprintf(stderr, "UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n", this, this->getTypeString()); - this->print(); printf("\n\n"); fflush(stdout); + chillAST_SourceFile *getSourceFile() { + if (isSourceFile()) return ((chillAST_SourceFile *) this); + if (parent != NULL) return parent->getSourceFile(); + fprintf(stderr, "UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n", + this, this->getTypeString()); + this->print(); + printf("\n\n"); + fflush(stdout); exit(-1); } - - virtual chillAST_node *findDatatype( char *t ) { - fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t); + + virtual chillAST_node *findDatatype(char *t) { + fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t); if (parent != NULL) return parent->findDatatype(t); // most nodes do this - return NULL; + return NULL; } - virtual chillAST_SymbolTable *addVariableToSymbolTable( chillAST_VarDecl *vd ) { - if (!parent) { - fprintf(stderr, "%s with no parent addVariableToSymbolTable()\n", getTypeString()); + virtual chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { + if (!parent) { + fprintf(stderr, "%s with no parent addVariableToSymbolTable()\n", getTypeString()); exit(-1); } //fprintf(stderr, "%s::addVariableToSymbolTable() (default) headed up\n", getTypeString()); - return parent->addVariableToSymbolTable( vd ); // default, defer to parent + return parent->addVariableToSymbolTable(vd); // default, defer to parent } - virtual void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) { - parent->addTypedefToTypedefTable( tdd ); // default, defer to parent + virtual void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) { + parent->addTypedefToTypedefTable(tdd); // default, defer to parent } - void walk_parents() { - fprintf(stderr, "wp: (%s) ", getTypeString()); - print(); printf("\n"); fflush(stdout); - if (isSourceFile()) { fprintf(stderr, "(top sourcefile)\n\n"); return;} + void walk_parents() { + fprintf(stderr, "wp: (%s) ", getTypeString()); + print(); + printf("\n"); + fflush(stdout); + if (isSourceFile()) { + fprintf(stderr, "(top sourcefile)\n\n"); + return; + } if (parent) parent->walk_parents(); else fprintf(stderr, "UHOH, %s has no parent??\n", getTypeString()); - return; + return; } - virtual chillAST_node *getEnclosingStatement( int level = 0 ); - virtual chillAST_VarDecl *multibase() { - fprintf(stderr,"(%s) forgot to implement multibase()\n", Chill_AST_Node_Names[asttype]); + virtual chillAST_node *getEnclosingStatement(int level = 0); + + virtual chillAST_VarDecl *multibase() { + fprintf(stderr, "(%s) forgot to implement multibase()\n", Chill_AST_Node_Names[asttype]); exit(-1); } - virtual chillAST_node *multibase2() { - fprintf(stderr,"(%s) forgot to implement multibase2()\n", Chill_AST_Node_Names[asttype]); + + virtual chillAST_node *multibase2() { + fprintf(stderr, "(%s) forgot to implement multibase2()\n", Chill_AST_Node_Names[asttype]); exit(-1); } - - virtual void gatherStatements( std::vector &statements ) { - fprintf(stderr,"(%s) forgot to implement gatherStatements()\n" ,Chill_AST_Node_Names[asttype]); - dump();fflush(stdout); + + virtual void gatherStatements(std::vector &statements) { + fprintf(stderr, "(%s) forgot to implement gatherStatements()\n", Chill_AST_Node_Names[asttype]); + dump(); + fflush(stdout); print(); - fprintf(stderr, "\n\n"); + fprintf(stderr, "\n\n"); } - virtual bool isSameAs( chillAST_node *other ){ // for tree comparison - fprintf(stderr,"(%s) forgot to implement isSameAs()\n" ,Chill_AST_Node_Names[asttype]); - dump(); fflush(stdout); + virtual bool isSameAs(chillAST_node *other) { // for tree comparison + fprintf(stderr, "(%s) forgot to implement isSameAs()\n", Chill_AST_Node_Names[asttype]); + dump(); + fflush(stdout); print(); - fprintf(stderr, "\n\n"); } + fprintf(stderr, "\n\n"); + } - void printPreprocBEFORE( int indent, FILE *fp ); - void printPreprocAFTER( int indent, FILE *fp ); + void printPreprocBEFORE(int indent, FILE *fp); + void printPreprocAFTER(int indent, FILE *fp); }; diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index 228cf3f..c7d13dd 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -6,22 +6,28 @@ #include "chillAST_def.hh" #include "chillAST_node.hh" -class chillAST_NULL: public chillAST_node { // NOOP? +class chillAST_NULL : public chillAST_node { // NOOP? public: - chillAST_NULL(chillAST_node *p = NULL) { parent = p; asttype = CHILLAST_NODETYPE_NULL; }; - void print( int indent=0, FILE *fp = stderr ) { - chillindent( indent, fp ); + chillAST_NULL(chillAST_node *p = NULL) { + parent = p; + asttype = CHILLAST_NODETYPE_NULL; + }; + + void print(int indent = 0, FILE *fp = stderr) { + chillindent(indent, fp); fprintf(fp, "/* (NULL statement); */ "); fflush(fp); } - void dump( int indent=0, FILE *fp = stderr ) { - chillindent( indent, fp ); - fprintf(fp, "(NULL statement) "); fflush(fp); + + void dump(int indent = 0, FILE *fp = stderr) { + chillindent(indent, fp); + fprintf(fp, "(NULL statement) "); + fflush(fp); } }; - -class chillAST_Preprocessing: public chillAST_node { + +class chillAST_Preprocessing : public chillAST_node { public: // variables that are special for this type of node CHILL_PREPROCESSING_POSITION position; @@ -30,18 +36,18 @@ public: // constructors chillAST_Preprocessing(); // not sure what this is good for - chillAST_Preprocessing( CHILL_PREPROCESSING_POSITION pos, CHILL_PREPROCESSING_TYPE t, char *text ); - + chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos, CHILL_PREPROCESSING_TYPE t, char *text); + // other methods particular to this type of node - + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc //void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc -}; +}; //typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another. -class chillAST_TypedefDecl: public chillAST_node { +class chillAST_TypedefDecl : public chillAST_node { private: bool isStruct; bool isUnion; @@ -54,53 +60,72 @@ public: chillAST_RecordDecl *rd; // if it's a struct, point to the recorddecl ?? // TODO what if "typedef int[10] tenints; " ?? - void setStructInfo( chillAST_RecordDecl *arrdee ) { rd = arrdee; }; - chillAST_RecordDecl * getStructDef(); + void setStructInfo(chillAST_RecordDecl *arrdee) { rd = arrdee; }; + + chillAST_RecordDecl *getStructDef(); - bool isAStruct() { return isStruct; }; - bool isAUnion() { return isUnion; }; - void setStruct(bool tf) { isStruct = tf; fprintf(stderr, "%s isStruct %d\n", structname, isStruct); }; - void setUnion( bool tf) { isUnion = tf; }; - void setStructName( const char *newname) { structname = strdup(newname); }; - char *getStructName( ) { return structname; }; - bool nameis( const char *n ) { return !strcmp(n, structname); }; + bool isAStruct() { return isStruct; }; + + bool isAUnion() { return isUnion; }; + + void setStruct(bool tf) { + isStruct = tf; + fprintf(stderr, "%s isStruct %d\n", structname, isStruct); + }; + + void setUnion(bool tf) { isUnion = tf; }; + + void setStructName(const char *newname) { structname = strdup(newname); }; + + char *getStructName() { return structname; }; + + bool nameis(const char *n) { return !strcmp(n, structname); }; // special for struct/unions rethink TODO std::vector subparts; - chillAST_VarDecl *findSubpart( const char *name ); + + chillAST_VarDecl *findSubpart(const char *name); //TODO hide data, set/get type and alias chillAST_TypedefDecl(); + chillAST_TypedefDecl(char *t, const char *nt, chillAST_node *p); + chillAST_TypedefDecl(char *t, const char *nt, char *a, chillAST_node *par); - - const char* getUnderlyingType() { fprintf(stderr, "TypedefDecl getUnderLyingType()\n"); return underlyingtype; }; + + const char *getUnderlyingType() { + fprintf(stderr, "TypedefDecl getUnderLyingType()\n"); + return underlyingtype; + }; //virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; }; // ?? - void dump( int indent=0, FILE *fp = stderr ) { - fprintf(fp, "(TypedefDecl %s %s %s)\n", underlyingtype, newtype, arraypart); }; - void print( int indent=0, FILE *fp = stderr ) ; + void dump(int indent = 0, FILE *fp = stderr) { + fprintf(fp, "(TypedefDecl %s %s %s)\n", underlyingtype, newtype, arraypart); + }; + + void print(int indent = 0, FILE *fp = stderr); //void printString( std::string &s ); }; -class chillAST_VarDecl: public chillAST_node { +class chillAST_VarDecl : public chillAST_node { public: char *vartype; // should probably be an enum, except it's used for unnamed structs too - chillAST_RecordDecl *vardef;// the thing that says what the struct looks like + chillAST_RecordDecl *vardef;// the thing that says what the struct looks like chillAST_TypedefDecl *typedefinition; // NULL for float, int, etc. - chillAST_RecordDecl * getStructDef(); // TODO make vardef private? + chillAST_RecordDecl *getStructDef(); // TODO make vardef private? //bool insideAStruct; // this variable is itself part of a struct - + char *underlyingtype; char *varname; char *arraypart; // [ 12 ] [ 34 ] if that is how it was defined char *arraypointerpart; - char *arraysetpart; + char *arraysetpart; + void splitarraypart(); int numdimensions; @@ -111,142 +136,188 @@ public: bool isRestrict; // C++ __restrict__ bool isShared; // CUDA __shared__ bool isDevice; // CUDA __device__ - bool isStruct; - - int isAParameter; + bool isStruct; + + int isAParameter; bool byreference; - void setByReference( bool tf ) { byreference = tf; fprintf(stderr, "byref %d\n", tf); }; + + void setByReference(bool tf) { + byreference = tf; + fprintf(stderr, "byref %d\n", tf); + }; bool isABuiltin; // if variable is builtin, we don't need to declare it void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! just used to differentiate declarations - bool isArray() { return (numdimensions != 0); }; + bool isArray() { return (numdimensions != 0); }; + bool isAStruct() { return (isStruct || (typedefinition && typedefinition->isAStruct())); } - void setStruct( bool b ) {isStruct = b;/*fprintf(stderr,"vardecl %s IS A STRUCT\n",varname);*/ }; - bool isPointer() { return isArray() && !knownArraySizes; } // - bool knowAllDimensions() { return knownArraySizes; } ; + void setStruct(bool b) { isStruct = b;/*fprintf(stderr,"vardecl %s IS A STRUCT\n",varname);*/ }; + + bool isPointer() { return isArray() && !knownArraySizes; } // + + bool knowAllDimensions() { return knownArraySizes; }; chillAST_node *init; - void setInit( chillAST_node *i ) { init = i; i->setParent(this); }; + + void setInit(chillAST_node *i) { + init = i; + i->setParent(this); + }; + bool hasInit() { return init != NULL; }; + chillAST_node *getInit() { return init; }; - + chillAST_VarDecl(); - chillAST_VarDecl( const char *t, const char *n, const char *a, chillAST_node *p); - chillAST_VarDecl( const char *t, const char *n, const char *a, void *ptr, chillAST_node *p); - chillAST_VarDecl( chillAST_TypedefDecl *tdd, const char *n, const char *arraypart, chillAST_node *par); - chillAST_VarDecl( chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_node *par); - - void dump( int indent=0, FILE *fp = stderr ); - void print( int indent=0, FILE *fp = stderr ); - void printName( int indent=0, FILE *fp = stderr ); - bool isParmVarDecl() { return( isAParameter == 1 ); }; - bool isBuiltin() { return( isABuiltin == 1 ); }; // designate variable as a builtin - void setLocation( void *ptr ) { uniquePtr = ptr; } ; - - - 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 ) {}; // does nothing - void gatherDeclRefExprs( std::vector&refs ) {}; // does nothing - void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {}; - bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here - const char* getUnderlyingType() { /* fprintf(stderr, "VarDecl getUnderLyingType()\n"); */return underlyingtype; }; - virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; }; - - chillAST_node* constantFold(); - chillAST_node* clone(); + + chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_node *p); + + chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, chillAST_node *p); + + chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, const char *arraypart, chillAST_node *par); + + chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_node *par); + + void dump(int indent = 0, FILE *fp = stderr); + + void print(int indent = 0, FILE *fp = stderr); + + void printName(int indent = 0, FILE *fp = stderr); + + bool isParmVarDecl() { return (isAParameter == 1); }; + + bool isBuiltin() { return (isABuiltin == 1); }; // designate variable as a builtin + void setLocation(void *ptr) { uniquePtr = ptr; }; + + + 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) {}; // does nothing + void gatherDeclRefExprs(std::vector &refs) {}; // does nothing + void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {}; + + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here + const char *getUnderlyingType() { /* fprintf(stderr, "VarDecl getUnderLyingType()\n"); */return underlyingtype; }; + + virtual chillAST_VarDecl *getUnderlyingVarDecl() { return this; }; + + chillAST_node *constantFold(); + + chillAST_node *clone(); }; -class chillAST_DeclRefExpr: public chillAST_node { +class chillAST_DeclRefExpr : public chillAST_node { public: // variables that are special for this type of node - char *declarationType; - char *declarationName; + char *declarationType; + char *declarationName; chillAST_node *decl; // the declaration of this variable or function ... uhoh //char *functionparameters; // TODO probably should split this node into 2 types, one for variables, one for functions // constructors - chillAST_DeclRefExpr(); - chillAST_DeclRefExpr( const char *variablename, chillAST_node *p); - chillAST_DeclRefExpr( const char *vartype, const char *variablename, chillAST_node *p); - chillAST_DeclRefExpr( const char *vartype, const char *variablename, chillAST_node *dec, chillAST_node *p); - chillAST_DeclRefExpr( chillAST_VarDecl *vd, chillAST_node *p=NULL); - chillAST_DeclRefExpr( chillAST_FunctionDecl *fd, chillAST_node *p=NULL); - + chillAST_DeclRefExpr(); + + chillAST_DeclRefExpr(const char *variablename, chillAST_node *p); + + chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_node *p); + + chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_node *dec, chillAST_node *p); + + chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_node *p = NULL); + + chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_node *p = NULL); + // other methods particular to this type of node - bool operator!=( chillAST_DeclRefExpr &other ) { return decl != other.decl ; }; - bool operator==( chillAST_DeclRefExpr &other ) { return decl == other.decl ; }; // EXACT SAME VARECL BY ADDRESS - + bool operator!=(chillAST_DeclRefExpr &other) { return decl != other.decl; }; + + bool operator==(chillAST_DeclRefExpr &other) { return decl == other.decl; }; // EXACT SAME VARECL BY ADDRESS + chillAST_node *getDecl() { return decl; }; - chillAST_VarDecl *getVarDecl() { + chillAST_VarDecl *getVarDecl() { if (!decl) return NULL; // should never happen - if (decl->isVarDecl()) return (chillAST_VarDecl *)decl; - return NULL; - }; - - chillAST_FunctionDecl *getFunctionDecl() { + if (decl->isVarDecl()) return (chillAST_VarDecl *) decl; + return NULL; + }; + + chillAST_FunctionDecl *getFunctionDecl() { if (!decl) return NULL; // should never happen - if (decl->isFunctionDecl()) return (chillAST_FunctionDecl *)decl; - return NULL; - }; - + if (decl->isFunctionDecl()) return (chillAST_FunctionDecl *) decl; + return NULL; + }; + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE - void dump( int indent=0, FILE *fp = stderr ); // print ast - char *stringRep(int indent=0 ); + void print(int indent = 0, FILE *fp = stderr); // print CODE + void dump(int indent = 0, FILE *fp = stderr); // print ast + char *stringRep(int indent = 0); - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ) {}; // do nothing - void gatherScalarRefs( std::vector &refs, bool writtento ); + chillAST_node *constantFold(); + + chillAST_node *clone(); + + void gatherArrayRefs(std::vector &refs, bool writtento) {}; // do nothing + void gatherScalarRefs(std::vector &refs, bool writtento); // this is the AST node where these 2 differ - void gatherVarDecls ( std::vector &decls ) {}; // does nothing, to get the cvardecl using this method, the actual vardecl must be in the AST - void gatherVarDeclsMore ( std::vector &decls ); // returns the decl this declrefexpr references, even if the decl is not in the AST + void gatherVarDecls( + std::vector &decls) {}; // does nothing, to get the cvardecl using this method, the actual vardecl must be in the AST + void gatherVarDeclsMore( + std::vector &decls); // returns the decl this declrefexpr references, even if the decl is not in the AST - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherScalarVarDecls(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 - chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below - - const char* getUnderlyingType() {fprintf(stderr, "DeclRefExpr getUnderLyingType()\n"); return decl->getUnderlyingType();}; + void gatherArrayVarDecls(std::vector &decls); - virtual chillAST_VarDecl* getUnderlyingVarDecl() { return decl->getUnderlyingVarDecl(); } // functions?? TODO + void gatherVarUsage(std::vector &decls); - chillAST_VarDecl* multibase(); - chillAST_node *multibase2() { return (chillAST_node *)multibase(); } -}; + 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 + chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below + const char *getUnderlyingType() { + fprintf(stderr, "DeclRefExpr getUnderLyingType()\n"); + return decl->getUnderlyingType(); + }; + virtual chillAST_VarDecl *getUnderlyingVarDecl() { return decl->getUnderlyingVarDecl(); } // functions?? TODO -class chillAST_CompoundStmt: public chillAST_node { + chillAST_VarDecl *multibase(); + + chillAST_node *multibase2() { return (chillAST_node *) multibase(); } +}; + + +class chillAST_CompoundStmt : public chillAST_node { public: // variables that are special for this type of node - chillAST_SymbolTable *symbol_table; // symbols defined inside this compound statement + chillAST_SymbolTable *symbol_table; // symbols defined inside this compound statement chillAST_TypedefTable *typedef_table; - bool hasSymbolTable() { return true; } ; - bool hasTypeDefTable() { return true; } ; - chillAST_node *findDatatype( char *t ) { - fprintf(stderr, "chillAST_CompoundStmt::findDatatype( %s )\n", t); - if (typedef_table) { - for (int i=0; i< typedef_table->size(); i++) { + bool hasSymbolTable() { return true; }; + + bool hasTypeDefTable() { return true; }; + + chillAST_node *findDatatype(char *t) { + fprintf(stderr, "chillAST_CompoundStmt::findDatatype( %s )\n", t); + if (typedef_table) { + for (int i = 0; i < typedef_table->size(); i++) { chillAST_TypedefDecl *tdd = (*typedef_table)[i]; - if (tdd->nameis( t )) return tdd; + if (tdd->nameis(t)) return tdd; } } if (parent) return parent->findDatatype(t); @@ -255,106 +326,125 @@ public: chillAST_SymbolTable *getSymbolTable() { return symbol_table; } - chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_CompoundStmt method + chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_CompoundStmt method //fprintf(stderr, "\nchillAST_CompoundStmt addVariableToSymbolTable( %s )\n", vd->varname); - symbol_table = addSymbolToTable( symbol_table, vd ); + symbol_table = addSymbolToTable(symbol_table, vd); //printSymbolTable( symbol_table ); return symbol_table; } - void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) { - typedef_table = addTypedefToTable( typedef_table, tdd ); + void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) { + typedef_table = addTypedefToTable(typedef_table, tdd); } // constructors chillAST_CompoundStmt(); // never has any args ??? - + // other methods particular to this type of node - - + + // required methods - void replaceChild( chillAST_node *old, chillAST_node *newchild ); - void dump( int indent=0, FILE *fp = stderr ); - void print( int indent=0, FILE *fp = stderr ); - chillAST_node* constantFold(); - chillAST_node* clone(); + void replaceChild(chillAST_node *old, chillAST_node *newchild); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void dump(int indent = 0, FILE *fp = stderr); - 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 print(int indent = 0, FILE *fp = stderr); - 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 loseLoopWithLoopVar( char *var ); // special case this for not for debugging + chillAST_node *constantFold(); - void gatherStatements( std::vector &statements ); -}; + chillAST_node *clone(); + void gatherVarDecls(std::vector &decls); + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; + void gatherScalarVarDecls(std::vector &decls); -class chillAST_RecordDecl: public chillAST_node { // declaration of the shape of a struct or union + 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 loseLoopWithLoopVar(char *var); // special case this for not for debugging + + void gatherStatements(std::vector &statements); +}; + + +class chillAST_RecordDecl : public chillAST_node { // declaration of the shape of a struct or union private: char *name; // could be NULL? for unnamed structs? - char *originalname; + char *originalname; bool isStruct; bool isUnion; std::vector subparts; - + public: chillAST_RecordDecl(); - chillAST_RecordDecl( const char *nam, chillAST_node *p ); - chillAST_RecordDecl( const char *nam, const char *orig, chillAST_node *p ); - - void setName( const char *newname) { name = strdup(newname); }; - char *getName( ) { return name; }; - - bool isAUnion() { return isUnion; }; - bool isAStruct() { return isStruct; }; + + chillAST_RecordDecl(const char *nam, chillAST_node *p); + + chillAST_RecordDecl(const char *nam, const char *orig, chillAST_node *p); + + void setName(const char *newname) { name = strdup(newname); }; + + char *getName() { return name; }; + + bool isAUnion() { return isUnion; }; + + bool isAStruct() { return isStruct; }; bool isUnnamed; - void setUnnamed( bool b ) { isUnnamed = b; }; - - void setStruct(bool tf) { isStruct = tf; }; + void setUnnamed(bool b) { isUnnamed = b; }; + + + void setStruct(bool tf) { isStruct = tf; }; + //fprintf(stderr, "%s isStruct %d\n", structname, isStruct); }; - void setUnion( bool tf) { isUnion = tf; }; - - chillAST_SymbolTable *addVariableToSymbolTable( chillAST_VarDecl *vd ); // RecordDecl does NOTHING - - int numSubparts() { return subparts.size(); }; - void addSubpart( chillAST_VarDecl *s ) { subparts.push_back(s); }; - chillAST_VarDecl *findSubpart( const char *name ); - chillAST_VarDecl *findSubpartByType( const char *typ ); - - void dump( int indent=0, FILE *fp = stderr ); - void print( int indent=0, FILE *fp = stderr ) ; - void printStructure( int indent=0, FILE *fp = stderr ) ; -}; + void setUnion(bool tf) { isUnion = tf; }; + chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd); // RecordDecl does NOTHING + int numSubparts() { return subparts.size(); }; + + void addSubpart(chillAST_VarDecl *s) { subparts.push_back(s); }; + + chillAST_VarDecl *findSubpart(const char *name); + + chillAST_VarDecl *findSubpartByType(const char *typ); + + void dump(int indent = 0, FILE *fp = stderr); + + void print(int indent = 0, FILE *fp = stderr); + + void printStructure(int indent = 0, FILE *fp = stderr); +}; -class chillAST_FunctionDecl: public chillAST_node { +class chillAST_FunctionDecl : public chillAST_node { private: chillAST_CompoundStmt *body; // always a compound statement? CHILL_FUNCTION_TYPE function_type; // CHILL_FUNCTION_CPU or CHILL_FUNCTION_GPU bool externfunc; // function is external bool builtin; // function is a builtin - bool forwarddecl; + bool forwarddecl; public: char *returnType; char *functionName; // parameters - int numParameters() { return parameters.size(); } ; + int numParameters() { return parameters.size(); }; chillAST_SymbolTable parameters; // this is probably a mistake, but symbol_table here is pointing to BODY'S symbol table @@ -363,201 +453,220 @@ public: chillAST_TypedefTable *typedef_table; // function typedef table - bool hasSymbolTable() { return true; } ; // COULD HAVE - bool hasTypeDefTable(){ return true; } ; // COULD HAVE + bool hasSymbolTable() { return true; }; // COULD HAVE + bool hasTypeDefTable() { return true; }; // COULD HAVE //char *parametertypes; // a single string?? - void printParameterTypes( FILE *fp ); - void setName( char *n ) { functionName = strdup(n); /* probable memory leak */ }; + void printParameterTypes(FILE *fp); - void setBuiltin() { builtin = true; } ; // designate function as a builtin - bool isBuiltin() { return builtin; } ; // report whether is a builtin + void setName(char *n) { functionName = strdup(n); /* probable memory leak */ }; + + void setBuiltin() { builtin = true; }; // designate function as a builtin + bool isBuiltin() { return builtin; }; // report whether is a builtin void setExtern() { externfunc = true; }; // designate function as external - bool isExtern() { return externfunc; }; // report whether function is external + bool isExtern() { return externfunc; }; // report whether function is external void setForward() { forwarddecl = true; }; // designate function as fwd declaration - bool isForward() { return forwarddecl; }; // report whether function is external + bool isForward() { return forwarddecl; }; // report whether function is external + + bool isFunctionCPU() { return (function_type == CHILL_FUNCTION_CPU); }; + + bool isFunctionGPU() { return (function_type == CHILL_FUNCTION_GPU); }; - bool isFunctionCPU() { return( function_type == CHILL_FUNCTION_CPU ); }; - bool isFunctionGPU() { return( function_type == CHILL_FUNCTION_GPU ); }; void setFunctionCPU() { function_type = CHILL_FUNCTION_CPU; }; + void setFunctionGPU() { function_type = CHILL_FUNCTION_GPU; }; void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! USED AS A UNIQUE ID - - + + chillAST_FunctionDecl(); // { asttype = CHILLAST_NODETYPE_FUNCTIONDECL; numparameters = 0;}; - chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p=NULL ) ; - chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p, void *unique ) ; - - void addParameter( chillAST_VarDecl *p); - chillAST_VarDecl *hasParameterNamed( const char *name ); - chillAST_VarDecl *findParameterNamed( const char *name ) { return hasParameterNamed( name ); }; + chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p = NULL); + + chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *p, void *unique); - void addDecl( chillAST_VarDecl *vd); // just adds to symbol table?? TODO + void addParameter(chillAST_VarDecl *p); - chillAST_VarDecl *funcHasVariableNamed( const char *name ); // functiondecl::hasVariableNamed + chillAST_VarDecl *hasParameterNamed(const char *name); + + chillAST_VarDecl *findParameterNamed(const char *name) { return hasParameterNamed(name); }; + + void addDecl(chillAST_VarDecl *vd); // just adds to symbol table?? TODO + + chillAST_VarDecl *funcHasVariableNamed(const char *name); // functiondecl::hasVariableNamed //chillAST_VarDecl *findVariableNamed( const char *name ) { return hasVariableNamed( name ); }; - void addChild(chillAST_node* node); // special because inserts into BODY - void insertChild(int i, chillAST_node* node); // special because inserts into BODY + void addChild(chillAST_node *node); // special because inserts into BODY + void insertChild(int i, chillAST_node *node); // special because inserts into BODY + + void setBody(chillAST_node *bod); + + chillAST_CompoundStmt *getBody() { return (body); } + + void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // in chill_ast.cc + + void gatherVarDecls(std::vector &decls); - void setBody( chillAST_node * bod ); - chillAST_CompoundStmt *getBody() { return( body); } - - void print( int indent=0, FILE *fp = stderr ); // in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // in chill_ast.cc + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherScalarVarDecls(std::vector &decls); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); - chillAST_VarDecl *findArrayDecl( const char *name ); + void gatherArrayVarDecls(std::vector &decls); + + chillAST_VarDecl *findArrayDecl(const char *name); //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 cleanUpVarDecls(); + void gatherVarUsage(std::vector &decls); + + void gatherDeclRefExprs(std::vector &refs); + + void cleanUpVarDecls(); //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ); + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false); - chillAST_node* constantFold(); + chillAST_node *constantFold(); - chillAST_node *findDatatype( char *t ) { - fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t); + chillAST_node *findDatatype(char *t) { + fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t); if (!typedef_table) { // not here if (parent) return parent->findDatatype(t); // not here, check parents else return NULL; // not defined here and no parent } - + //fprintf(stderr, "%d typedefs\n", typedef_table->size()); - for (int i=0; i< typedef_table->size(); i++) { + for (int i = 0; i < typedef_table->size(); i++) { chillAST_TypedefDecl *tdd = (*typedef_table)[i]; - if ( tdd->nameis( t )) return tdd; + if (tdd->nameis(t)) return tdd; } if (parent) return parent->findDatatype(t); return NULL; // should not happen } chillAST_SymbolTable *getParameterSymbolTable() { return ¶meters; } - chillAST_SymbolTable *getSymbolTable() { return body->getSymbolTable(); } //symbol_table; } // - void setSymbolTable( chillAST_SymbolTable *tab ) { + + chillAST_SymbolTable *getSymbolTable() { return body->getSymbolTable(); } //symbol_table; } // + void setSymbolTable(chillAST_SymbolTable *tab) { // no longer keeping a local ?? symbol_table = tab; if (!body) { // can never happen now - body = new chillAST_CompoundStmt(); + body = new chillAST_CompoundStmt(); } // only if func is empty! - body->symbol_table = tab; + body->symbol_table = tab; } - chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_FunctionDecl method + chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_FunctionDecl method //fprintf(stderr, "\nchillAST_FunctionDecl addVariableToSymbolTable( %s )\n", vd->varname); - + // this is all dealing with the body's symbol table // the function has a symbol table called "parameters" but that is a special case - addSymbolToTable( getSymbolTable(), vd ); - if (!vd->parent) { + addSymbolToTable(getSymbolTable(), vd); + if (!vd->parent) { //fprintf(stderr, "setting parent of vardecl to be the function whose symbol table it is going into\n"); // ?? - vd->setParent( this ); - insertChild(0,vd); + vd->setParent(this); + insertChild(0, vd); } //printSymbolTable( getSymbolTable() ); return getSymbolTable(); } - void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) { - typedef_table = addTypedefToTable( typedef_table, tdd ); + void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) { + typedef_table = addTypedefToTable(typedef_table, tdd); } - void replaceChild( chillAST_node *old, chillAST_node *newchild ) { - body->replaceChild( old, newchild ); + void replaceChild(chillAST_node *old, chillAST_node *newchild) { + body->replaceChild(old, newchild); } }; // end FunctionDecl -class chillAST_SourceFile: public chillAST_node { +class chillAST_SourceFile : public chillAST_node { public: // constructors chillAST_SourceFile(); // defined in chill_ast.cc - chillAST_SourceFile(const char *filename ); // defined in chill_ast.cc + chillAST_SourceFile(const char *filename); // defined in chill_ast.cc + + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void printToFile(char *filename = NULL); - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void printToFile( char *filename = NULL ); - char *SourceFileName; // where this originated - char *FileToWrite; + char *FileToWrite; char *frontend; - void setFileToWrite( char *f ) { FileToWrite = strdup( f ); }; - - void setFrontend( const char *compiler ) { if (frontend) free(frontend); frontend = strdup(compiler); } + void setFileToWrite(char *f) { FileToWrite = strdup(f); }; + + void setFrontend(const char *compiler) { + if (frontend) free(frontend); + frontend = strdup(compiler); + } // get, set filename ? - chillAST_SymbolTable *global_symbol_table; // (global) symbols defined inside this source file + chillAST_SymbolTable *global_symbol_table; // (global) symbols defined inside this source file chillAST_TypedefTable *global_typedef_table; // source file - chillAST_VarDecl *findVariableNamed( const char *name ); // looks in global_symbol_table; + chillAST_VarDecl *findVariableNamed(const char *name); // looks in global_symbol_table; - bool hasSymbolTable() { return true; } ; // "has" vs "can have" TODO - bool hasTypeDefTable() { return true; } ; + bool hasSymbolTable() { return true; }; // "has" vs "can have" TODO + bool hasTypeDefTable() { return true; }; - chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_SourceFile method + chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_SourceFile method fprintf(stderr, "\nchillAST_SourceFile addVariableToSymbolTable( %s )\n", vd->varname); - global_symbol_table = addSymbolToTable( global_symbol_table, vd ); + global_symbol_table = addSymbolToTable(global_symbol_table, vd); //addChild( vd ); // ?? //printSymbolTable( global_symbol_table ); return global_symbol_table; } - void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) { + void addTypedefToTypedefTable(chillAST_TypedefDecl *tdd) { //fprintf(stderr, "SOURCEFILE adding typedef %s to typedeftable\n", tdd->getStructName()); - global_typedef_table = addTypedefToTable( global_typedef_table, tdd ); + global_typedef_table = addTypedefToTable(global_typedef_table, tdd); //fprintf(stderr, "now global typedef table has %d entries\n", global_typedef_table->size()); } - chillAST_node *findDatatype( char *t ) { - fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t); + chillAST_node *findDatatype(char *t) { + fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t); fprintf(stderr, "%d global typedefs\n", global_typedef_table->size()); - for (int i=0; i< global_typedef_table->size(); i++) { - + for (int i = 0; i < global_typedef_table->size(); i++) { + chillAST_TypedefDecl *tdd = (*global_typedef_table)[i]; //fprintf(stderr, "comparing to %s\n", tdd->getStructName()); - if (tdd->nameis( t )) { + if (tdd->nameis(t)) { //fprintf(stderr, "found it\n"); - return (chillAST_node *)tdd; + return (chillAST_node *) tdd; } } return NULL; } - std::vector< chillAST_FunctionDecl *> functions; // at top level, or anywhere? - std::vector< chillAST_MacroDefinition *> macrodefinitions; + std::vector functions; // at top level, or anywhere? + std::vector macrodefinitions; - chillAST_MacroDefinition* findMacro( const char *name ); // TODO ignores arguments - chillAST_FunctionDecl *findFunction( const char *name ); // TODO ignores arguments - chillAST_node *findCall( const char *name ); - void addMacro(chillAST_MacroDefinition* md) { + chillAST_MacroDefinition *findMacro(const char *name); // TODO ignores arguments + chillAST_FunctionDecl *findFunction(const char *name); // TODO ignores arguments + chillAST_node *findCall(const char *name); + + void addMacro(chillAST_MacroDefinition *md) { macrodefinitions.push_back(md); //fprintf(stderr, "addMacro(), now %d macros\n", macrodefinitions.size()); } - void addFunc(chillAST_FunctionDecl* fd) { + + void addFunc(chillAST_FunctionDecl *fd) { //fprintf(stderr, "chillAST_SourceFile::addFunc( %s %p)\n", fd->functionName, fd); - bool already = false; - for (int i=0; ifunctionName, functions[i]); - if (functions[i] == fd) { + if (functions[i] == fd) { //fprintf(stderr, "function %s was already in source functions\n", fd->functionName); already = true; } @@ -565,71 +674,88 @@ public: if (!already) functions.push_back(fd); // PROBABLY fd was created with sourcefile as its parent. Don't add it twice - addChild( (chillAST_node *)fd); } + addChild((chillAST_node *) fd); + } }; -class chillAST_MacroDefinition: public chillAST_node { +class chillAST_MacroDefinition : public chillAST_node { private: chillAST_node *body; // rhs always a compound statement? chillAST_SymbolTable *symbol_table; public: char *macroName; - char *rhsString; + char *rhsString; // parameters - these will be odd, in that they HAVE NO TYPE - int numParameters() { return parameters.size(); } ; - std::vectorparameters; - - void setName( char *n ) { macroName = strdup(n); /* probable memory leak */ }; - void setRhsString( char *n ) { rhsString = strdup(n); /* probable memory leak */ }; + int numParameters() { return parameters.size(); }; + std::vector parameters; + + void setName(char *n) { macroName = strdup(n); /* probable memory leak */ }; + + void setRhsString(char *n) { rhsString = strdup(n); /* probable memory leak */ }; + char *getRhsString() { return rhsString; } chillAST_MacroDefinition(); - chillAST_MacroDefinition( const char *name, chillAST_node *par); - chillAST_MacroDefinition( const char *name, const char *rhs, chillAST_node *par); - - void addParameter( chillAST_VarDecl *p); // parameters have no TYPE ?? - chillAST_VarDecl *hasParameterNamed( const char *name ); - chillAST_VarDecl *findParameterNamed( const char *name ) { return hasParameterNamed( name ); }; - void addChild(chillAST_node* node); // special because inserts into BODY - void insertChild(int i, chillAST_node* node); // special because inserts into BODY - - void setBody( chillAST_node * bod ); - chillAST_node *getBody() { return( body); } - - void print( int indent=0, FILE *fp = stderr ); // in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // in chill_ast.cc - - bool hasSymbolTable() { return true; } ; + + chillAST_MacroDefinition(const char *name, chillAST_node *par); + + chillAST_MacroDefinition(const char *name, const char *rhs, chillAST_node *par); + + void addParameter(chillAST_VarDecl *p); // parameters have no TYPE ?? + chillAST_VarDecl *hasParameterNamed(const char *name); + + chillAST_VarDecl *findParameterNamed(const char *name) { return hasParameterNamed(name); }; + + void addChild(chillAST_node *node); // special because inserts into BODY + void insertChild(int i, chillAST_node *node); // special because inserts into BODY + + void setBody(chillAST_node *bod); + + chillAST_node *getBody() { return (body); } + + void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // in chill_ast.cc + + bool hasSymbolTable() { return true; }; //const std::vector getSymbolTable() { return symbol_table; } chillAST_SymbolTable *getSymbolTable() { return symbol_table; } - chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_MacroDefinition method ?? + + chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_MacroDefinition method ?? //fprintf(stderr, "\nchillAST_MacroDefinition addVariableToSymbolTable( %s )\n", vd->varname); - symbol_table = addSymbolToTable( symbol_table, vd ); + symbol_table = addSymbolToTable(symbol_table, vd); //printSymbolTable( symbol_table ); return symbol_table; } - chillAST_node* clone(); + chillAST_node *clone(); // 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 ){}; - chillAST_VarDecl *findArrayDecl( const char *name ){}; - void gatherVarUsage( std::vector &decls ){}; - void gatherDeclRefExprs( std::vector&refs ){}; - void cleanUpVarDecls(); - bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){}; - chillAST_node* constantFold(){}; + void gatherVarDecls(std::vector &decls) {}; + + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; + + void gatherScalarVarDecls(std::vector &decls) {}; + + void gatherArrayVarDecls(std::vector &decls) {}; + + chillAST_VarDecl *findArrayDecl(const char *name) {}; + + void gatherVarUsage(std::vector &decls) {}; + + void gatherDeclRefExprs(std::vector &refs) {}; + + void cleanUpVarDecls(); + + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) {}; + + chillAST_node *constantFold() {}; }; -class chillAST_ForStmt: public chillAST_node { +class chillAST_ForStmt : public chillAST_node { public: // variables that are special for this type of node chillAST_node *init; @@ -639,250 +765,320 @@ public: IR_CONDITION_TYPE conditionoperator; // from ir_code.hh chillAST_SymbolTable *symbol_table; // symbols defined inside this forstmt (in init but not body?) body is compound stmt - bool hasSymbolTable() { return true; } ; + bool hasSymbolTable() { return true; }; // constructors chillAST_ForStmt(); - chillAST_ForStmt( chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, chillAST_node *p); - + + chillAST_ForStmt(chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, chillAST_node *p); + // other methods particular to this type of node void addSyncs(); - void removeSyncComment(); + + void removeSyncComment(); + chillAST_node *getInit() { return init; }; + chillAST_node *getCond() { return cond; }; - chillAST_node *getInc() { return incr; }; - chillAST_node *getBody() { //fprintf(stderr, "chillAST_ForStmt::getBody(), returning a chillAST_node of type %s\n", body->getTypeString()); - return body; }; - void setBody( chillAST_node *b ) { body = b; b->parent = this; }; - - bool isNotLeaf() { return true; }; - bool isLeaf() { return false; }; - - + + chillAST_node *getInc() { return incr; }; + + chillAST_node * + getBody() { //fprintf(stderr, "chillAST_ForStmt::getBody(), returning a chillAST_node of type %s\n", body->getTypeString()); + return body; + }; + + void setBody(chillAST_node *b) { + body = b; + b->parent = this; + }; + + bool isNotLeaf() { return true; }; + + bool isLeaf() { return false; }; + + // required methods that I can't seem to get to inherit - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void printControl( int indent=0, FILE *fp = stderr ); // print just for ( ... ) but not body + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void printControl(int indent = 0, FILE *fp = stderr); // print just for ( ... ) but not body + + chillAST_node *constantFold(); + + chillAST_node *clone(); + + void gatherVarDecls(std::vector &decls); + + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - chillAST_node* constantFold(); - chillAST_node* clone(); + void gatherScalarVarDecls(std::vector &decls); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherArrayVarDecls(std::vector &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 gatherArrayRefs(std::vector &refs, bool writtento); - void gatherVarUsage( std::vector &decls ); - void gatherDeclRefExprs( std::vector&refs ); - void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); // will get called on inner loops - bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ); + void gatherScalarRefs(std::vector &refs, bool writtento); - void gatherLoopIndeces( std::vector &indeces ); - void gatherLoopVars( std::vector &loopvars ); // gather as strings ?? + void gatherVarUsage(std::vector &decls); - void get_deep_loops( std::vector &loops) { // chillAST_ForStmt version + void gatherDeclRefExprs(std::vector &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 &indeces); + + void gatherLoopVars(std::vector &loopvars); // gather as strings ?? + + void get_deep_loops(std::vector &loops) { // chillAST_ForStmt version // ADD MYSELF! - loops.push_back( this ); + loops.push_back(this); - int n = body->children.size(); + int n = body->children.size(); //fprintf(stderr, "get_deep_loops of a %s with %d children\n", getTypeString(), n); - for (int i=0; ichildren[i]->getTypeString()); - body->children[i]->get_deep_loops( loops ); + body->children[i]->get_deep_loops(loops); } //fprintf(stderr, "found %d deep loops\n", loops.size()); } - void find_deepest_loops( std::vector &loops) { + void find_deepest_loops(std::vector &loops) { std::vector b; // deepest loops below me - int n = body->children.size(); - for (int i=0; ichildren.size(); + for (int i = 0; i < n; i++) { std::vector l; // deepest loops below one child - body->children[i]->find_deepest_loops( l ); - if ( l.size() > b.size() ) { // a deeper nesting than we've seen + body->children[i]->find_deepest_loops(l); + if (l.size() > b.size()) { // a deeper nesting than we've seen b = l; } } - loops.push_back( this ); // add myself - for (int i=0; ivarname); - symbol_table = addSymbolToTable( symbol_table, vd ); + symbol_table = addSymbolToTable(symbol_table, vd); //printSymbolTable( symbol_table ); return symbol_table; } - void gatherStatements( std::vector &statements ); - bool lowerBound( int &l ); - bool upperBound( int &u ); + void gatherStatements(std::vector &statements); -}; + bool lowerBound(int &l); + bool upperBound(int &u); + +}; -class chillAST_TernaryOperator: public chillAST_node { +class chillAST_TernaryOperator : public chillAST_node { public: // variables that are special for this type of node char *op; // TODO need enum so far, only "?" conditional operator chillAST_node *condition; chillAST_node *lhs; // keep name from binary chillAST_node *rhs; - - + + // constructors chillAST_TernaryOperator(); - chillAST_TernaryOperator(const char *op, chillAST_node *cond, chillAST_node *lhs, chillAST_node *rhs, chillAST_node *p=NULL); - + + chillAST_TernaryOperator(const char *op, chillAST_node *cond, chillAST_node *lhs, chillAST_node *rhs, + chillAST_node *p = NULL); + // other methods particular to this type of node - bool isNotLeaf() { return true; }; - bool isLeaf() { return false; }; - - - char *getOp() { return op; }; // dangerous. could get changed! - chillAST_node *getCond() { return condition; }; - chillAST_node *getRHS() { return rhs; }; + bool isNotLeaf() { return true; }; + + bool isLeaf() { return false; }; + + + char *getOp() { return op; }; // dangerous. could get changed! + chillAST_node *getCond() { return condition; }; + + chillAST_node *getRHS() { return rhs; }; + chillAST_node *getLHS() { return lhs; }; - void setCond( chillAST_node *newc ) { condition = newc; newc->setParent( this ); } - void setLHS( chillAST_node *newlhs ) { lhs = newlhs; newlhs->setParent( this ); } - void setRHS( chillAST_node *newrhs ) { rhs = newrhs; newrhs->setParent( this ); } + void setCond(chillAST_node *newc) { + condition = newc; + newc->setParent(this); + } + + void setLHS(chillAST_node *newlhs) { + lhs = newlhs; + newlhs->setParent(this); + } + + void setRHS(chillAST_node *newrhs) { + rhs = newrhs; + newrhs->setParent(this); + } + - - - // required methods that I can't seem to get to inherit - void dump( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void printonly( int indent=0, FILE *fp = stderr ); + void dump(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void printonly(int indent = 0, FILE *fp = stderr); + + chillAST_node *constantFold(); - chillAST_node* constantFold(); - chillAST_node* clone(); - void replaceChild( chillAST_node *old, chillAST_node *newchild ) ; - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + chillAST_node *clone(); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void replaceChild(chillAST_node *old, chillAST_node *newchild); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherArrayRefs(std::vector &refs, bool writtento); - void gatherVarUsage( std::vector &decls ); - void gatherDeclRefExprs( std::vector&refs ); - void gatherVarLHSUsage( std::vector &decls ); - void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here - void loseLoopWithLoopVar( char *var ){}; // ternop can't have loop as child? -}; + void gatherScalarRefs(std::vector &refs, bool writtento); + void gatherVarDecls(std::vector &decls); + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; -class chillAST_BinaryOperator: public chillAST_node { + void gatherScalarVarDecls(std::vector &decls); + + void gatherArrayVarDecls(std::vector &decls); + + void gatherVarUsage(std::vector &decls); + + void gatherDeclRefExprs(std::vector &refs); + + void gatherVarLHSUsage(std::vector &decls); + + void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); + + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here + void loseLoopWithLoopVar(char *var) {}; // ternop can't have loop as child? +}; + + +class chillAST_BinaryOperator : public chillAST_node { public: // variables that are special for this type of node char *op; // TODO need enum chillAST_node *lhs; chillAST_node *rhs; - - + + // constructors chillAST_BinaryOperator(); - chillAST_BinaryOperator(chillAST_node *lhs, const char *op, chillAST_node *rhs, chillAST_node *p=NULL); - + + chillAST_BinaryOperator(chillAST_node *lhs, const char *op, chillAST_node *rhs, chillAST_node *p = NULL); + // other methods particular to this type of node int evalAsInt(); - chillAST_IntegerLiteral *evalAsIntegerLiteral(); - bool isNotLeaf() { return true; }; - bool isLeaf() { return false; }; - - chillAST_node *getRHS() { return rhs; }; + chillAST_IntegerLiteral *evalAsIntegerLiteral(); + + bool isNotLeaf() { return true; }; + + bool isLeaf() { return false; }; + + chillAST_node *getRHS() { return rhs; }; + chillAST_node *getLHS() { return lhs; }; - void setLHS( chillAST_node *newlhs ) { lhs = newlhs; newlhs->setParent( this ); } - void setRHS( chillAST_node *newrhs ) { rhs = newrhs; newrhs->setParent( this ); } - - char *getOp() { return op; }; // dangerous. could get changed! - bool isAugmentedAssignmentOp() { - return - (!strcmp(op, "*=")) || // BO_MulAssign, - (!strcmp(op, "/=")) || // BO_DivAssign - (!strcmp(op, "%=")) || // BO_RemAssign - (!strcmp(op, "+=")) || // BO_AddAssign - (!strcmp(op, "-=")) || // BO_SubAssign - - (!strcmp(op, "<<=")) || // BO_ShlAssign - (!strcmp(op, ">>=")) || // BO_ShrAssign - (!strcmp(op, "&&=")) || // BO_AndAssign - (!strcmp(op, "||=")) || // BO_OrAssign - - (!strcmp(op, "^=")) // BO_XorAssign - ; + + void setLHS(chillAST_node *newlhs) { + lhs = newlhs; + newlhs->setParent(this); + } + + void setRHS(chillAST_node *newrhs) { + rhs = newrhs; + newrhs->setParent(this); + } + + char *getOp() { return op; }; // dangerous. could get changed! + bool isAugmentedAssignmentOp() { + return + (!strcmp(op, "*=")) || // BO_MulAssign, + (!strcmp(op, "/=")) || // BO_DivAssign + (!strcmp(op, "%=")) || // BO_RemAssign + (!strcmp(op, "+=")) || // BO_AddAssign + (!strcmp(op, "-=")) || // BO_SubAssign + + (!strcmp(op, "<<=")) || // BO_ShlAssign + (!strcmp(op, ">>=")) || // BO_ShrAssign + (!strcmp(op, "&&=")) || // BO_AndAssign + (!strcmp(op, "||=")) || // BO_OrAssign + + (!strcmp(op, "^=")) // BO_XorAssign + ; } - bool isAssignmentOp() { - return( (!strcmp(op, "=")) || // BO_Assign, - isAugmentedAssignmentOp() ); - }; - bool isComparisonOp() { return (!strcmp(op,"<")) || (!strcmp(op,">")) || (!strcmp(op,"<=")) || (!strcmp(op,">=")); }; - - bool isPlusOp() { return (!strcmp(op,"+")); }; - bool isMinusOp() { return (!strcmp(op,"-")); }; - bool isPlusMinusOp() { return (!strcmp(op,"+")) || (!strcmp(op,"-")); }; - bool isMultDivOp() { return (!strcmp(op,"*")) || (!strcmp(op,"/")); }; - - bool isStructOp() { return (!strcmp(op,".")) || (!strcmp(op,"->")); }; - - + + bool isAssignmentOp() { + return ((!strcmp(op, "=")) || // BO_Assign, + isAugmentedAssignmentOp()); + }; + + bool isComparisonOp() { + return (!strcmp(op, "<")) || (!strcmp(op, ">")) || (!strcmp(op, "<=")) || (!strcmp(op, ">=")); + }; + + bool isPlusOp() { return (!strcmp(op, "+")); }; + + bool isMinusOp() { return (!strcmp(op, "-")); }; + + bool isPlusMinusOp() { return (!strcmp(op, "+")) || (!strcmp(op, "-")); }; + + bool isMultDivOp() { return (!strcmp(op, "*")) || (!strcmp(op, "/")); }; + + bool isStructOp() { return (!strcmp(op, ".")) || (!strcmp(op, "->")); }; + + // required methods that I can't seem to get to inherit - void dump( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void printonly( int indent=0, FILE *fp = stderr ); - char *stringRep(int indent=0 ); + void dump(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void printonly(int indent = 0, FILE *fp = stderr); + + char *stringRep(int indent = 0); + + chillAST_node *constantFold(); + + chillAST_node *clone(); + + void replaceChild(chillAST_node *old, chillAST_node *newchild); - chillAST_node* constantFold(); - chillAST_node* clone(); - void replaceChild( chillAST_node *old, chillAST_node *newchild ) ; - void gatherArrayRefs( std::vector &refs, bool writtento ); // chillAST_BinaryOperator - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void gatherArrayRefs(std::vector &refs, bool writtento); // chillAST_BinaryOperator + void gatherScalarRefs(std::vector &refs, bool writtento); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherVarDecls(std::vector &decls); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherVarUsage( std::vector &decls ); - void gatherDeclRefExprs( std::vector&refs ); - void gatherVarLHSUsage( std::vector &decls ); - void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here - void loseLoopWithLoopVar( char *var ){}; // binop can't have loop as child? + void gatherScalarVarDecls(std::vector &decls); - void gatherStatements( std::vector &statements ); // + void gatherArrayVarDecls(std::vector &decls); - bool isSameAs( chillAST_node *other ); + void gatherVarUsage(std::vector &decls); -}; + void gatherDeclRefExprs(std::vector &refs); + void gatherVarLHSUsage(std::vector &decls); + void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here + void loseLoopWithLoopVar(char *var) {}; // binop can't have loop as child? + void gatherStatements(std::vector &statements); // + bool isSameAs(chillAST_node *other); +}; -class chillAST_ArraySubscriptExpr: public chillAST_node { +class chillAST_ArraySubscriptExpr : public chillAST_node { public: // variables that are special for this type of node chillAST_node *base; // always a decl ref expr? No, for multidimensional array, is another ASE @@ -891,472 +1087,559 @@ public: bool imreadfrom; // WARNING: ONLY used when both writtento and readfrom are true x += 1 and so on chillAST_VarDecl *basedecl; // the vardecl that this refers to void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! - + // constructors - chillAST_ArraySubscriptExpr(); - chillAST_ArraySubscriptExpr( chillAST_node *bas, chillAST_node *indx, chillAST_node *p, void *unique); - chillAST_ArraySubscriptExpr( chillAST_node *bas, chillAST_node *indx, bool writtento, chillAST_node *p, void *unique); - - chillAST_ArraySubscriptExpr( chillAST_VarDecl *v, std::vector indeces, chillAST_node *p); - + chillAST_ArraySubscriptExpr(); + + chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, chillAST_node *p, void *unique); + + chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, bool writtento, chillAST_node *p, void *unique); + + chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector indeces, chillAST_node *p); + // other methods particular to this type of node - bool operator!=( const chillAST_ArraySubscriptExpr& ) ; - bool operator==( const chillAST_ArraySubscriptExpr& ) ; + bool operator!=(const chillAST_ArraySubscriptExpr &); + + bool operator==(const chillAST_ArraySubscriptExpr &); + chillAST_VarDecl *multibase(); // method for finding the basedecl - chillAST_node *multibase2() { return base->multibase2(); } + chillAST_node *multibase2() { return base->multibase2(); } chillAST_node *getIndex(int dim); - void gatherIndeces( std::vector< chillAST_node * > &ind ); - void replaceChild( chillAST_node *old, chillAST_node *newchild ); // will examine index + void gatherIndeces(std::vector &ind); + + void replaceChild(chillAST_node *old, chillAST_node *newchild); // will examine index // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void printonly( int indent=0, FILE *fp = stderr ); - void print( int indent=0, FILE *fp = stderr ) const; // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - char *stringRep(int indent=0 ); - - chillAST_node* constantFold(); - chillAST_node* clone(); - chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below - 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 - - const char* getUnderlyingType() { - //fprintf(stderr, "ASE getUnderlyingType() base of type %s\n", base->getTypeString()); base->print(); printf("\n"); fflush(stderr); - return base->getUnderlyingType(); }; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void printonly(int indent = 0, FILE *fp = stderr); + + void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + char *stringRep(int indent = 0); + + chillAST_node *constantFold(); + + chillAST_node *clone(); + + chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below + void gatherArrayRefs(std::vector &refs, bool writtento); + + void gatherScalarRefs(std::vector &refs, bool writtento); - virtual chillAST_VarDecl* getUnderlyingVarDecl() { return base->getUnderlyingVarDecl(); }; + 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 + + const char *getUnderlyingType() { + //fprintf(stderr, "ASE getUnderlyingType() base of type %s\n", base->getTypeString()); base->print(); printf("\n"); fflush(stderr); + return base->getUnderlyingType(); + }; + virtual chillAST_VarDecl *getUnderlyingVarDecl() { return base->getUnderlyingVarDecl(); }; -class chillAST_MemberExpr: public chillAST_node { +}; + + +class chillAST_MemberExpr : public chillAST_node { public: // variables that are special for this type of node chillAST_node *base; // always a decl ref expr? No, can be Array Subscript Expr - char *member; - char *printstring; + char *member; + char *printstring; chillAST_VarDecl *basedecl; // the vardecl that this refers to void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! - CHILL_MEMBER_EXP_TYPE exptype; - + CHILL_MEMBER_EXP_TYPE exptype; + // constructors - chillAST_MemberExpr(); - chillAST_MemberExpr( chillAST_node *bas, const char *mem, chillAST_node *p, void *unique, CHILL_MEMBER_EXP_TYPE t=CHILL_MEMBER_EXP_DOT); - + chillAST_MemberExpr(); + + chillAST_MemberExpr(chillAST_node *bas, const char *mem, chillAST_node *p, void *unique, + CHILL_MEMBER_EXP_TYPE t = CHILL_MEMBER_EXP_DOT); + // other methods particular to this type of node - bool operator!=( const chillAST_MemberExpr& ) ; - bool operator==( const chillAST_MemberExpr& ) ; - + bool operator!=(const chillAST_MemberExpr &); + + bool operator==(const chillAST_MemberExpr &); + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void printonly( int indent=0, FILE *fp = stderr ); - void print( int indent=0, FILE *fp = stderr ) const; // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - char *stringRep( int indent = 0); - - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void printonly(int indent = 0, FILE *fp = stderr); + + void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + char *stringRep(int indent = 0); + + 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 gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherScalarVarDecls(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 + void gatherArrayVarDecls(std::vector &decls); - chillAST_VarDecl* getUnderlyingVarDecl(); + void gatherVarUsage(std::vector &decls); - void replaceChild( chillAST_node *old, chillAST_node *newchild ); + void gatherDeclRefExprs(std::vector &refs); - void setType( CHILL_MEMBER_EXP_TYPE t ) { exptype = t; }; - CHILL_MEMBER_EXP_TYPE getType( CHILL_MEMBER_EXP_TYPE t ) { return exptype; }; + void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - chillAST_VarDecl* multibase(); // this one will return the member decl - chillAST_node* multibase2(); // this one will return the member expression -}; + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here + chillAST_VarDecl *getUnderlyingVarDecl(); + void replaceChild(chillAST_node *old, chillAST_node *newchild); + void setType(CHILL_MEMBER_EXP_TYPE t) { exptype = t; }; -class chillAST_IntegerLiteral: public chillAST_node { + CHILL_MEMBER_EXP_TYPE getType(CHILL_MEMBER_EXP_TYPE t) { return exptype; }; + + chillAST_VarDecl *multibase(); // this one will return the member decl + chillAST_node *multibase2(); // this one will return the member expression +}; + + +class chillAST_IntegerLiteral : public chillAST_node { public: // variables that are special for this type of node int value; - + // constructors - chillAST_IntegerLiteral(int val, chillAST_node *p = NULL); - + chillAST_IntegerLiteral(int val, chillAST_node *p = NULL); + // other methods particular to this type of node - int evalAsInt() { return value; } + int evalAsInt() { return value; } // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool w ){}; // does nothing - void gatherScalarRefs( std::vector &refs, bool writtento ){}; // does nothing + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); - void gatherVarDecls ( std::vector &decls ){}; // does nothing - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + chillAST_node *clone(); - void gatherScalarVarDecls( std::vector &decls ){}; // does nothing - void gatherArrayVarDecls ( std::vector &decls ){}; // does nothing + void gatherArrayRefs(std::vector &refs, bool w) {}; // does nothing + void gatherScalarRefs(std::vector &refs, bool writtento) {}; // does nothing - void gatherVarUsage( std::vector &decls ) {}; // does nothing - void gatherDeclRefExprs( std::vector&refs ) {}; // does nothing - void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {}; - bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here + void gatherVarDecls(std::vector &decls) {}; // does nothing + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below -}; + 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) {}; // does nothing + void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {}; -class chillAST_FloatingLiteral: public chillAST_node { + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here + + chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below +}; + + +class chillAST_FloatingLiteral : public chillAST_node { public: // variables that are special for this type of node float value; double doublevalue; - int float0double1; + int float0double1; char *allthedigits; // if not NULL, use this as printable representation int precision; // float == 1, double == 2, ??? // constructors - chillAST_FloatingLiteral( float val, chillAST_node *p); - chillAST_FloatingLiteral( double val, chillAST_node *p); - chillAST_FloatingLiteral( float val, int pre, chillAST_node *p); - chillAST_FloatingLiteral( double val, int pre, chillAST_node *p); - chillAST_FloatingLiteral( float val, const char *printable, chillAST_node *p); - chillAST_FloatingLiteral( float val, int pre, const char *printable, chillAST_node *p); - chillAST_FloatingLiteral( chillAST_FloatingLiteral *old ); - + chillAST_FloatingLiteral(float val, chillAST_node *p); + + chillAST_FloatingLiteral(double val, chillAST_node *p); + + chillAST_FloatingLiteral(float val, int pre, chillAST_node *p); + + chillAST_FloatingLiteral(double val, int pre, chillAST_node *p); + + chillAST_FloatingLiteral(float val, const char *printable, chillAST_node *p); + + chillAST_FloatingLiteral(float val, int pre, const char *printable, chillAST_node *p); + + chillAST_FloatingLiteral(chillAST_FloatingLiteral *old); + // other methods particular to this type of node - void setPrecision( int precis ) { precision = precis; }; - int getPrecision() { return precision; } - + void setPrecision(int precis) { precision = precis; }; + + int getPrecision() { return precision; } + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool w ){}; // does nothing - void gatherScalarRefs( std::vector &refs, bool writtento ){}; // does nothing + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); - void gatherVarDecls ( std::vector &decls ){}; // does nothing - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + chillAST_node *clone(); - void gatherScalarVarDecls( std::vector &decls ){}; // does nothing ; - void gatherArrayVarDecls ( std::vector &decls ){}; // does nothing ; + void gatherArrayRefs(std::vector &refs, bool w) {}; // does nothing + void gatherScalarRefs(std::vector &refs, bool writtento) {}; // does nothing - void gatherVarUsage( std::vector &decls ) {}; // does nothing - void gatherDeclRefExprs( std::vector&refs ){}; // does nothing - void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl){}; - bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here - chillAST_node *findref(){return this;};// find the SINGLE constant or data reference at this node or below + void gatherVarDecls(std::vector &decls) {}; // does nothing + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - bool isSameAs( chillAST_node *other ); -}; + 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) {}; // does nothing + void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {}; + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here + chillAST_node *findref() { return this; };// find the SINGLE constant or data reference at this node or below + + bool isSameAs(chillAST_node *other); +}; -class chillAST_UnaryOperator: public chillAST_node { +class chillAST_UnaryOperator : public chillAST_node { public: // variables that are special for this type of node char *op; // TODO enum bool prefix; // or post chillAST_node *subexpr; - + // constructors - chillAST_UnaryOperator( const char *oper, bool pre, chillAST_node *sub, chillAST_node *p ); - + chillAST_UnaryOperator(const char *oper, bool pre, chillAST_node *sub, chillAST_node *p); + // other methods particular to this type of node - bool isAssignmentOp() { - return( (!strcmp(op, "++")) || - (!strcmp(op, "--")) ); // are there more ??? TODO + bool isAssignmentOp() { + return ((!strcmp(op, "++")) || + (!strcmp(op, "--"))); // are there more ??? TODO } - + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + chillAST_node *clone(); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); - void gatherArrayRefs( std::vector &refs, bool writtento ); // chillAST_UnaryOperator + void gatherVarDecls(std::vector &decls); - void gatherVarLHSUsage( std::vector &decls ); + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(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 + void gatherScalarVarDecls(std::vector &decls); - int evalAsInt(); - bool isSameAs( chillAST_node *other ); + 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 + + int evalAsInt(); + + bool isSameAs(chillAST_node *other); +}; -class chillAST_ImplicitCastExpr: public chillAST_node { +class chillAST_ImplicitCastExpr : public chillAST_node { public: // variables that are special for this type of node chillAST_node *subexpr; - + // constructors - chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *p); - + chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *p); + // other methods particular to this type of node - bool isNotLeaf() { return true; }; - bool isLeaf() { return false; }; - + bool isNotLeaf() { return true; }; + + bool isLeaf() { return false; }; + // required methods that I can't seem to get to inherit - void replaceChild( chillAST_node *old, chillAST_node *newchild ); - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void printonly( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ) { print( indent, fp); }; // print ast in chill_ast.cc - 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 replaceChild(chillAST_node *old, chillAST_node *newchild); + + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void printonly(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr) { print(indent, fp); }; // print ast in chill_ast.cc + 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 + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here chillAST_VarDecl *multibase(); // just recurse on subexpr -}; - +}; -class chillAST_CStyleCastExpr: public chillAST_node { +class chillAST_CStyleCastExpr : public chillAST_node { public: // variables that are special for this type of node - char * towhat; + char *towhat; chillAST_node *subexpr; + // constructors - chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *p=NULL); - + chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *p = NULL); + // 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 ); - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void replaceChild(chillAST_node *old, chillAST_node *newchild); + + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); + + chillAST_node *clone(); + + void gatherArrayRefs(std::vector &refs, bool writtento); - void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); + void gatherScalarRefs(std::vector &refs, bool writtento); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherVarDecls(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 + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; -}; + void gatherScalarVarDecls(std::vector &decls); + void gatherArrayVarDecls(std::vector &decls); -class chillAST_CStyleAddressOf: public chillAST_node { + 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 + +}; + + +class chillAST_CStyleAddressOf : public chillAST_node { public: // variables that are special for this type of node chillAST_node *subexpr; + // constructors - chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *p=NULL); - + chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *p = NULL); + // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + 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 gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherScalarVarDecls(std::vector &decls); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherArrayVarDecls(std::vector &decls); + + void gatherVarUsage(std::vector &decls); + + void gatherDeclRefExprs(std::vector &refs); - 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 + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here - -}; + +}; -class chillAST_CudaMalloc:public chillAST_node { +class chillAST_CudaMalloc : public chillAST_node { public: // variables that are special for this type of node chillAST_node *devPtr; // Pointer to allocated device memory chillAST_node *sizeinbytes; // constructors - chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p=NULL); - + chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p = NULL); + // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + chillAST_node *clone(); - 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 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 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 + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here -}; +}; -class chillAST_CudaFree:public chillAST_node { +class chillAST_CudaFree : public chillAST_node { public: // variables that are special for this type of node - chillAST_VarDecl *variable; + chillAST_VarDecl *variable; // constructors - chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p=NULL); - + chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p = NULL); + // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + chillAST_node *clone(); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherArrayRefs(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 ){ return false; }; // no loops under here + 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 -class chillAST_Malloc:public chillAST_node { // malloc( sizeof(int) * 2048 ); +}; + + +class chillAST_Malloc : public chillAST_node { // malloc( sizeof(int) * 2048 ); public: // variables that are special for this type of node char *thing; // to void if this is null , sizeof(thing) if it is not chillAST_node *sizeexpr; // bytes // constructors - chillAST_Malloc(chillAST_node *size, chillAST_node *p=NULL); - chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p=NULL); // malloc (sizeof(int) *1024) + chillAST_Malloc(chillAST_node *size, chillAST_node *p = NULL); + + chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p = NULL); // malloc (sizeof(int) *1024) // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + chillAST_node *clone(); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherArrayRefs(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 ){ return false; }; // no loops under here + 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); -class chillAST_Free:public chillAST_node { -public: - + 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 + +}; -}; +class chillAST_Free : public chillAST_node { +public: +}; -class chillAST_CudaMemcpy:public chillAST_node { +class chillAST_CudaMemcpy : public chillAST_node { public: // variables that are special for this type of node chillAST_VarDecl *dest; // Pointer to allocated device memory @@ -1365,301 +1648,356 @@ public: char *cudaMemcpyKind; // could use the actual enum // constructors - chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *size, char *kind, chillAST_node *p=NULL); - + chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *size, char *kind, + chillAST_node *p = NULL); + // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); + + chillAST_node *clone(); + + void gatherArrayRefs(std::vector &refs, bool writtento); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherScalarRefs(std::vector &refs, bool writtento); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + 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 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 + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here -}; +}; -class chillAST_CudaSyncthreads:public chillAST_node { +class chillAST_CudaSyncthreads : public chillAST_node { public: // variables that are special for this type of node // constructors - chillAST_CudaSyncthreads(chillAST_node *p=NULL); - + chillAST_CudaSyncthreads(chillAST_node *p = NULL); + // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc //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 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 gatherScalarVarDecls(std::vector &decls) {}; // does nothing + void gatherArrayVarDecls(std::vector &decls) {}; // does nothing - void gatherVarUsage( 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 { +class chillAST_ReturnStmt : public chillAST_node { public: // variables that are special for this type of node chillAST_node *returnvalue; - + // constructors - chillAST_ReturnStmt( chillAST_node *retval, chillAST_node *p ); - + chillAST_ReturnStmt(chillAST_node *retval, chillAST_node *p); + // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + chillAST_node *constantFold(); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + chillAST_node *clone(); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherVarDecls(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 + 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); -class chillAST_CallExpr: public chillAST_node { // a function call + //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here + +}; + + +class chillAST_CallExpr : public chillAST_node { // a function call public: // variables that are special for this type of node chillAST_node *callee; // the function declaration (what about builtins?) int numargs; - std::vector args; + std::vector args; chillAST_VarDecl *grid; chillAST_VarDecl *block; // constructors - chillAST_CallExpr(chillAST_node *function, chillAST_node *p ); - void addArg( chillAST_node *newarg ); - + chillAST_CallExpr(chillAST_node *function, chillAST_node *p); + + void addArg(chillAST_node *newarg); + // other methods particular to this type of node // TODO get/set grid, block - + // required methods that I can't seem to get to inherit - chillAST_node* constantFold(); - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + chillAST_node *constantFold(); + + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + void gatherArrayRefs(std::vector &refs, bool writtento); + + void gatherScalarRefs(std::vector &refs, bool writtento); + + void gatherVarDecls(std::vector &decls); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherScalarVarDecls(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 - chillAST_node* clone(); -}; + 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 + chillAST_node *clone(); +}; -class chillAST_ParenExpr: public chillAST_node { + +class chillAST_ParenExpr : public chillAST_node { public: // variables that are special for this type of node chillAST_node *subexpr; - + // constructors - chillAST_ParenExpr( chillAST_node *sub, chillAST_node *p=NULL ); - + chillAST_ParenExpr(chillAST_node *sub, chillAST_node *p = NULL); + // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + 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 gatherVarDecls(std::vector &decls); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(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 + void gatherScalarVarDecls(std::vector &decls); -}; + void gatherArrayVarDecls(std::vector &decls); + void gatherVarUsage(std::vector &decls); -class chillAST_Sizeof: public chillAST_node { + 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 + +}; + + +class chillAST_Sizeof : public chillAST_node { public: // variables that are special for this type of node - char *thing; - + char *thing; + // constructors - chillAST_Sizeof( char *t, chillAST_node *p = NULL ); - + chillAST_Sizeof(char *t, chillAST_node *p = NULL); + // other methods particular to this type of node - - + + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc - chillAST_node* constantFold(); - chillAST_node* clone(); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc + 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 gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherVarDeclsMore(std::vector &decls) { gatherVarDecls(decls); }; - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); + void gatherScalarVarDecls(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 + void gatherArrayVarDecls(std::vector &decls); -}; + void gatherVarUsage(std::vector &decls); + void gatherDeclRefExprs(std::vector &refs); + void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {}; -class chillAST_NoOp: public chillAST_node { + bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, + bool forcesync = false) { return false; }; // no loops under here + +}; + + +class chillAST_NoOp : public chillAST_node { public: - chillAST_NoOp( chillAST_node *p = NULL ); // { parent = p; }; + chillAST_NoOp(chillAST_node *p = NULL); // { parent = p; }; // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ) {}; // print CODE in chill_ast.cc - void dump( int indent=0, FILE *fp = stderr ) {}; // print ast in chill_ast.cc - chillAST_node* constantFold() {}; - chillAST_node* clone() { return new chillAST_NoOp( parent ); }; // ?? + void print(int indent = 0, FILE *fp = stderr) {}; // print CODE in chill_ast.cc + void dump(int indent = 0, FILE *fp = stderr) {}; // print ast in chill_ast.cc + chillAST_node *constantFold() {}; - void gatherArrayRefs( std::vector &refs, bool writtento ) {}; - void gatherScalarRefs( std::vector &refs, bool writtento ) {}; + chillAST_node *clone() { return new chillAST_NoOp(parent); }; // ?? - void gatherVarDecls ( std::vector &decls ){}; - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + void gatherArrayRefs(std::vector &refs, bool writtento) {}; - void gatherScalarVarDecls( std::vector &decls ){}; - void gatherArrayVarDecls ( std::vector &decls ){}; + 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 ){ return false; };//no loops under here -}; + 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) {}; -class chillAST_IfStmt: public chillAST_node { + 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 +}; + + +class chillAST_IfStmt : public chillAST_node { public: // 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, chillAST_node *p); - + + chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p); + // other methods particular to this type of node chillAST_node *getCond() { return cond; }; + chillAST_node *getThen() { return thenpart; }; + chillAST_node *getElse() { return elsepart; }; - void setCond( chillAST_node *b ) { cond = b; if (cond) cond->parent = this; }; - void setThen( chillAST_node *b ) { thenpart = b; if (thenpart) thenpart->parent = this; }; - void setElse( chillAST_node *b ) { elsepart = b; if (elsepart) elsepart->parent = this; }; - + void setCond(chillAST_node *b) { + cond = b; + if (cond) cond->parent = this; + }; + + void setThen(chillAST_node *b) { + thenpart = b; + if (thenpart) thenpart->parent = this; + }; + + void setElse(chillAST_node *b) { + elsepart = b; + if (elsepart) elsepart->parent = this; + }; + // required methods that I can't seem to get to inherit - void dump( int indent=0, FILE *fp = stderr ); - void print( int indent=0, FILE *fp = stderr ); + void dump(int indent = 0, FILE *fp = stderr); - chillAST_node* constantFold(); - chillAST_node* clone(); + void print(int indent = 0, FILE *fp = stderr); - void gatherVarDecls ( std::vector &decls ); - void gatherVarDeclsMore ( std::vector &decls ) { gatherVarDecls(decls); } ; + chillAST_node *constantFold(); - void gatherScalarVarDecls( std::vector &decls ); - void gatherArrayVarDecls ( std::vector &decls ); - void gatherArrayRefs( std::vector &refs, bool writtento ); - void gatherScalarRefs( std::vector &refs, bool writtento ) ; + chillAST_node *clone(); - 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 gatherVarDecls(std::vector &decls); - void gatherStatements( std::vector &statements ); - -}; + 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 { + +class chillAST_something : public chillAST_node { public: // variables that are special for this type of node - + // constructors - chillAST_something(); - + chillAST_something(); + // other methods particular to this type of node - + // required methods that I can't seem to get to inherit - void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc + void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc //void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc -}; - - - - - +}; #endif -- cgit v1.2.3-70-g09d2