diff options
Diffstat (limited to 'include/chillAST')
-rw-r--r-- | include/chillAST/chillAST_def.hh | 158 | ||||
-rw-r--r-- | include/chillAST/chillAST_node.hh | 222 | ||||
-rw-r--r-- | include/chillAST/chillASTs.hh | 532 |
3 files changed, 481 insertions, 431 deletions
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh index 0e5832e..289b835 100644 --- a/include/chillAST/chillAST_def.hh +++ b/include/chillAST/chillAST_def.hh @@ -3,6 +3,7 @@ #ifndef _CHILLAST_DEF_H_ #define _CHILLAST_DEF_H_ +#include "chilldebug.h" #define CHILL_INDENT_AMOUNT 2 @@ -15,76 +16,76 @@ #include <ir_enums.hh> // for IR_CONDITION_* -#define CHILLAST_NODETYPE_FORSTMT CHILLAST_NODETYPE_LOOP -#define CHILLAST_NODETYPE_TRANSLATIONUNIT CHILLAST_NODETYPE_SOURCEFILE - -enum CHILL_ASTNODE_TYPE { - CHILLAST_NODETYPE_UNKNOWN = 0, - CHILLAST_NODETYPE_SOURCEFILE, - CHILLAST_NODETYPE_TYPEDEFDECL, - CHILLAST_NODETYPE_VARDECL, - // CHILLAST_NODETYPE_PARMVARDECL, not used any more - CHILLAST_NODETYPE_FUNCTIONDECL, - CHILLAST_NODETYPE_RECORDDECL, // struct or union (or class) - CHILLAST_NODETYPE_MACRODEFINITION, - CHILLAST_NODETYPE_COMPOUNDSTMT, - CHILLAST_NODETYPE_LOOP, // AKA ForStmt - CHILLAST_NODETYPE_TERNARYOPERATOR, - CHILLAST_NODETYPE_BINARYOPERATOR, - CHILLAST_NODETYPE_UNARYOPERATOR, - CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR, - CHILLAST_NODETYPE_MEMBEREXPR, // structs/unions - CHILLAST_NODETYPE_DECLREFEXPR, - CHILLAST_NODETYPE_INTEGERLITERAL, - CHILLAST_NODETYPE_FLOATINGLITERAL, - CHILLAST_NODETYPE_IMPLICITCASTEXPR, - CHILLAST_NODETYPE_RETURNSTMT, - CHILLAST_NODETYPE_CALLEXPR, - CHILLAST_NODETYPE_DECLSTMT, - CHILLAST_NODETYPE_PARENEXPR, - CHILLAST_NODETYPE_CSTYLECASTEXPR, - CHILLAST_NODETYPE_CSTYLEADDRESSOF, - CHILLAST_NODETYPE_IFSTMT, - CHILLAST_NODETYPE_SIZEOF, - CHILLAST_NODETYPE_MALLOC, - CHILLAST_NODETYPE_FREE, - CHILLAST_NODETYPE_PREPROCESSING, // comments, #define, #include, whatever else works - CHILLAST_NODETYPE_NOOP, // NO OP +#define CHILLAST_NODE_FORSTMT CHILLAST_NODE_LOOP +#define CHILLAST_NODE_TRANSLATIONUNIT CHILLAST_NODE_SOURCEFILE + +enum CHILLAST_NODE_TYPE { + CHILLAST_NODE_UNKNOWN = 0, + CHILLAST_NODE_SOURCEFILE, + CHILLAST_NODE_TYPEDEFDECL, + CHILLAST_NODE_VARDECL, + // CHILLAST_NODE_PARMVARDECL, not used any more + CHILLAST_NODE_FUNCTIONDECL, + CHILLAST_NODE_RECORDDECL, // struct or union (or class) + CHILLAST_NODE_MACRODEFINITION, + CHILLAST_NODE_COMPOUNDSTMT, + CHILLAST_NODE_LOOP, // AKA ForStmt + CHILLAST_NODE_TERNARYOPERATOR, + CHILLAST_NODE_BINARYOPERATOR, + CHILLAST_NODE_UNARYOPERATOR, + CHILLAST_NODE_ARRAYSUBSCRIPTEXPR, + CHILLAST_NODE_MEMBEREXPR, // structs/unions + CHILLAST_NODE_DECLREFEXPR, + CHILLAST_NODE_INTEGERLITERAL, + CHILLAST_NODE_FLOATINGLITERAL, + CHILLAST_NODE_IMPLICITCASTEXPR, + CHILLAST_NODE_RETURNSTMT, + CHILLAST_NODE_CALLEXPR, + CHILLAST_NODE_DECLSTMT, + CHILLAST_NODE_PARENEXPR, + CHILLAST_NODE_CSTYLECASTEXPR, + CHILLAST_NODE_CSTYLEADDRESSOF, + CHILLAST_NODE_IFSTMT, + CHILLAST_NODE_SIZEOF, + CHILLAST_NODE_MALLOC, + CHILLAST_NODE_FREE, + CHILLAST_NODE_PREPROCESSING, // comments, #define, #include, whatever else works + CHILLAST_NODE_NOOP, // NO OP // CUDA specific - CHILLAST_NODETYPE_CUDAMALLOC, - CHILLAST_NODETYPE_CUDAFREE, - CHILLAST_NODETYPE_CUDAMEMCPY, - CHILLAST_NODETYPE_CUDAKERNELCALL, - CHILLAST_NODETYPE_CUDASYNCTHREADS, - CHILLAST_NODETYPE_NULL // explicit non-statement + CHILLAST_NODE_CUDAMALLOC, + CHILLAST_NODE_CUDAFREE, + CHILLAST_NODE_CUDAMEMCPY, + CHILLAST_NODE_CUDAKERNELCALL, + CHILLAST_NODE_CUDASYNCTHREADS, + CHILLAST_NODE_NULL // explicit non-statement // TODO }; -enum CHILL_FUNCTION_TYPE { - CHILL_FUNCTION_CPU = 0, - CHILL_FUNCTION_GPU +enum CHILLAST_FUNCTION_TYPE { + CHILLAST_FUNCTION_CPU = 0, + CHILLAST_FUNCTION_GPU }; -enum CHILL_MEMBER_EXP_TYPE { - CHILL_MEMBER_EXP_DOT = 0, - CHILL_MEMBER_EXP_ARROW +enum CHILLAST_MEMBER_EXP_TYPE { + CHILLAST_MEMBER_EXP_DOT = 0, + CHILLAST_MEMBER_EXP_ARROW }; -enum CHILL_PREPROCESSING_TYPE { - CHILL_PREPROCESSING_TYPEUNKNOWN = 0, - CHILL_PREPROCESSING_COMMENT, - CHILL_PREPROCESSING_POUNDDEFINE, - CHILL_PREPROCESSING_POUNDINCLUDE, - CHILL_PREPROCESSING_PRAGMA // unused so far +enum CHILLAST_PREPROCESSING_TYPE { + CHILLAST_PREPROCESSING_TYPEUNKNOWN = 0, + CHILLAST_PREPROCESSING_COMMENT, + CHILLAST_PREPROCESSING_POUNDDEFINE, + CHILLAST_PREPROCESSING_POUNDINCLUDE, + CHILLAST_PREPROCESSING_PRAGMA // unused so far }; -enum CHILL_PREPROCESSING_POSITION { // when tied to another statement - CHILL_PREPROCESSING_POSITIONUNKNOWN = 0, - CHILL_PREPROCESSING_LINEBEFORE, // previous line - CHILL_PREPROCESSING_LINEAFTER, // next line - CHILL_PREPROCESSING_TOTHERIGHT, // for this kind of comment, on same line - CHILL_PREPROCESSING_IMMEDIATELYBEFORE // on same line +enum CHILLAST_PREPROCESSING_POSITION { // when tied to another statement + CHILLAST_PREPROCESSING_POSITIONUNKNOWN = 0, + CHILLAST_PREPROCESSING_LINEBEFORE, // previous line + CHILLAST_PREPROCESSING_LINEAFTER, // next line + CHILLAST_PREPROCESSING_TOTHERIGHT, // for this kind of comment, on same line + CHILLAST_PREPROCESSING_IMMEDIATELYBEFORE // on same line }; char *parseUnderlyingType(char *sometype); @@ -95,15 +96,21 @@ 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! +//! change "1024UL" to "1024" +char *ulhack(char *brackets); +//! remove __restrict__ , MODIFIES the argument! +char *restricthack(char *typeinfo); -extern const char *Chill_AST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST +// TODO phase out this one unnecessary as we can write a virtual function that does this +extern const char *ChillAST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST // fwd declarations -class chillAST_node; // the generic node. specific types derive from this -class chillAST_NULL; // empty -class chillAST_SourceFile; // ast for an entire source file (translationunit) +//! the generic node, who specific types are derived from +class chillAST_Node; +//! empty node +class chillAST_NULL; +//! ast for an entire source file (translationunit) +class chillAST_SourceFile; class chillAST_TypedefDecl; @@ -112,14 +119,18 @@ class chillAST_VarDecl; //class chillAST_ParmVarDecl; class chillAST_FunctionDecl; -class chillAST_RecordDecl; // structs and unions (and classes?) +//! structs and unions (and classes?) +class chillAST_RecordDecl; class chillAST_MacroDefinition; -class chillAST_CompoundStmt; // just a bunch of other statements -class chillAST_ForStmt; // AKA a LOOP -class chillAST_TernaryOperator; +//! A sequence of statements +class chillAST_CompoundStmt; +//! a For LOOP +class chillAST_ForStmt; +class chillAST_UnaryOperator; class chillAST_BinaryOperator; +class chillAST_TernaryOperator; class chillAST_ArraySubscriptExpr; @@ -131,8 +142,6 @@ class chillAST_IntegerLiteral; class chillAST_FloatingLiteral; -class chillAST_UnaryOperator; - class chillAST_ImplicitCastExpr; class chillAST_CStyleCastExpr; @@ -165,10 +174,11 @@ class chillAST_CudaSyncthreads; class chillAST_Preprocessing; +typedef std::vector<chillAST_Node *> chillAST_NodeList; typedef std::vector<chillAST_VarDecl *> chillAST_SymbolTable; // typedef typedef std::vector<chillAST_TypedefDecl *> chillAST_TypedefTable; // typedef -bool symbolTableHasVariableNamed(chillAST_SymbolTable *table, const char *name); // fwd decl +chillAST_VarDecl *symbolTableFindName(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 @@ -176,7 +186,7 @@ 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_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 @@ -187,7 +197,7 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va 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 bc3facb..f0afe17 100644 --- a/include/chillAST/chillAST_node.hh +++ b/include/chillAST/chillAST_node.hh @@ -5,91 +5,102 @@ #include "chillAST_def.hh" -// an actual chill ast. -// 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) +//! generic node of the actual chillAST, a multiway tree node. +class chillAST_Node { public: + //! this Node's parent + chillAST_Node *parent; + //! this node's children + chillAST_NodeList children; + //! whether it is from a source file, when false it is from included files + bool isFromSourceFile; + //! the name of file this node from + char *filename; + //! for compiler internals, formerly a comment + char *metacomment; + std::vector<chillAST_Preprocessing *> preprocessinginfo; - static int chill_scalar_counter; // for manufactured scalars - static int chill_array_counter; // for manufactured arrays - static int chill_pointer_counter; // for manufactured arrays - - - CHILL_ASTNODE_TYPE asttype; + //! for manufactured scalars + static int chill_scalar_counter; + //! for manufactured arrays + static int chill_array_counter; + //! for manufactured pointer + static int chill_pointer_counter; + //! the type of this current node + virtual CHILLAST_NODE_TYPE getType() {return CHILLAST_NODE_UNKNOWN;}; - bool isSourceFile() { return (asttype == CHILLAST_NODETYPE_SOURCEFILE); }; + bool isSourceFile() { return (getType() == CHILLAST_NODE_SOURCEFILE); }; - bool isTypeDefDecl() { return (asttype == CHILLAST_NODETYPE_TYPEDEFDECL); }; + bool isTypeDefDecl() { return (getType() == CHILLAST_NODE_TYPEDEFDECL); }; - bool isVarDecl() { return (asttype == CHILLAST_NODETYPE_VARDECL); }; + bool isVarDecl() { return (getType() == CHILLAST_NODE_VARDECL); }; - bool isFunctionDecl() { return (asttype == CHILLAST_NODETYPE_FUNCTIONDECL); }; + bool isFunctionDecl() { return (getType() == CHILLAST_NODE_FUNCTIONDECL); }; - bool isRecordDecl() { return (asttype == CHILLAST_NODETYPE_RECORDDECL); }; + bool isRecordDecl() { return (getType() == CHILLAST_NODE_RECORDDECL); }; - bool isMacroDefinition() { return (asttype == CHILLAST_NODETYPE_MACRODEFINITION); }; + bool isMacroDefinition() { return (getType() == CHILLAST_NODE_MACRODEFINITION); }; - bool isCompoundStmt() { return (asttype == CHILLAST_NODETYPE_COMPOUNDSTMT); }; + bool isCompoundStmt() { return (getType() == CHILLAST_NODE_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 isLoop() { return (getType() == CHILLAST_NODE_LOOP); }; // AKA ForStmt + bool isForStmt() { return (getType() == CHILLAST_NODE_LOOP); }; // AKA Loop + bool isIfStmt() { return (getType() == CHILLAST_NODE_IFSTMT); }; - bool isTernaryOperator() { return (asttype == CHILLAST_NODETYPE_TERNARYOPERATOR); }; + bool isTernaryOperator() { return (getType() == CHILLAST_NODE_TERNARYOPERATOR); }; - bool isBinaryOperator() { return (asttype == CHILLAST_NODETYPE_BINARYOPERATOR); }; + bool isBinaryOperator() { return (getType() == CHILLAST_NODE_BINARYOPERATOR); }; - bool isUnaryOperator() { return (asttype == CHILLAST_NODETYPE_UNARYOPERATOR); }; + bool isUnaryOperator() { return (getType() == CHILLAST_NODE_UNARYOPERATOR); }; - bool isArraySubscriptExpr() { return (asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR); }; + bool isArraySubscriptExpr() { return (getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR); }; - bool isMemberExpr() { return (asttype == CHILLAST_NODETYPE_MEMBEREXPR); }; + bool isMemberExpr() { return (getType() == CHILLAST_NODE_MEMBEREXPR); }; - bool isDeclRefExpr() { return (asttype == CHILLAST_NODETYPE_DECLREFEXPR); }; + bool isDeclRefExpr() { return (getType() == CHILLAST_NODE_DECLREFEXPR); }; - bool isIntegerLiteral() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL); }; + bool isIntegerLiteral() { return (getType() == CHILLAST_NODE_INTEGERLITERAL); }; - bool isFloatingLiteral() { return (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); }; + bool isFloatingLiteral() { return (getType() == CHILLAST_NODE_FLOATINGLITERAL); }; - bool isImplicitCastExpr() { return (asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR); }; + bool isImplicitCastExpr() { return (getType() == CHILLAST_NODE_IMPLICITCASTEXPR); }; - bool isReturnStmt() { return (asttype == CHILLAST_NODETYPE_RETURNSTMT); }; + bool isReturnStmt() { return (getType() == CHILLAST_NODE_RETURNSTMT); }; - bool isCallExpr() { return (asttype == CHILLAST_NODETYPE_CALLEXPR); }; + bool isCallExpr() { return (getType() == CHILLAST_NODE_CALLEXPR); }; - bool isParenExpr() { return (asttype == CHILLAST_NODETYPE_PARENEXPR); }; + bool isParenExpr() { return (getType() == CHILLAST_NODE_PARENEXPR); }; - bool isSizeof() { return (asttype == CHILLAST_NODETYPE_SIZEOF); }; + bool isSizeof() { return (getType() == CHILLAST_NODE_SIZEOF); }; - bool isMalloc() { return (asttype == CHILLAST_NODETYPE_MALLOC); }; + bool isMalloc() { return (getType() == CHILLAST_NODE_MALLOC); }; - bool isFree() { return (asttype == CHILLAST_NODETYPE_FREE); }; + bool isFree() { return (getType() == CHILLAST_NODE_FREE); }; - bool isPreprocessing() { return (asttype == CHILLAST_NODETYPE_PREPROCESSING); }; + bool isPreprocessing() { return (getType() == CHILLAST_NODE_PREPROCESSING); }; - bool isNoOp() { return (asttype == CHILLAST_NODETYPE_NOOP); }; + bool isNoOp() { return (getType() == CHILLAST_NODE_NOOP); }; - bool isNull() { return (asttype == CHILLAST_NODETYPE_NULL); }; + bool isNull() { return (getType() == CHILLAST_NODE_NULL); }; - bool isCStyleCastExpr() { return (asttype == CHILLAST_NODETYPE_CSTYLECASTEXPR); }; + bool isCStyleCastExpr() { return (getType() == CHILLAST_NODE_CSTYLECASTEXPR); }; - bool isCStyleAddressOf() { return (asttype == CHILLAST_NODETYPE_CSTYLEADDRESSOF); }; + bool isCStyleAddressOf() { return (getType() == CHILLAST_NODE_CSTYLEADDRESSOF); }; - bool isCudaMalloc() { return (asttype == CHILLAST_NODETYPE_CUDAMALLOC); }; + bool isCudaMalloc() { return (getType() == CHILLAST_NODE_CUDAMALLOC); }; - bool isCudaFree() { return (asttype == CHILLAST_NODETYPE_CUDAFREE); }; + bool isCudaFree() { return (getType() == CHILLAST_NODE_CUDAFREE); }; - bool isCudaMemcpy() { return (asttype == CHILLAST_NODETYPE_CUDAMEMCPY); }; + bool isCudaMemcpy() { return (getType() == CHILLAST_NODE_CUDAMEMCPY); }; - bool isCudaKERNELCALL() { return (asttype == CHILLAST_NODETYPE_CUDAKERNELCALL); }; + bool isCudaKERNELCALL() { return (getType() == CHILLAST_NODE_CUDAKERNELCALL); }; - bool isCudaSYNCTHREADS() { return (asttype == CHILLAST_NODETYPE_CUDASYNCTHREADS); }; + bool isCudaSYNCTHREADS() { return (getType() == CHILLAST_NODE_CUDASYNCTHREADS); }; - bool isDeclStmt() { return (asttype == CHILLAST_NODETYPE_DECLSTMT); }; // doesn't exist + bool isDeclStmt() { return (getType() == CHILLAST_NODE_DECLSTMT); }; // doesn't exist bool isConstant() { - return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL) || (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); + return (getType() == CHILLAST_NODE_INTEGERLITERAL) || (getType() == CHILLAST_NODE_FLOATINGLITERAL); } @@ -126,28 +137,22 @@ public: // void addDecl( chillAST_VarDecl *vd); // recursive, adds to first symbol table it can find // TODO decide how to hide some data - chillAST_node *parent; - bool isFromSourceFile; // false = #included - char *filename; // file this node is from int getNumChildren() { return children.size(); }; - std::vector<chillAST_node *> children; - std::vector<chillAST_node *>& getChildren() { return children; }; // not usually useful - void setChildren(std::vector<chillAST_node *> &c) { children = c; }; // does not set parent. probably should - chillAST_node *getChild(int which) { return children[which]; }; + chillAST_NodeList& getChildren() { return children; }; // not usually useful + void setChildren(chillAST_NodeList &c) { children = c; }; // does not set parent. probably should + chillAST_Node *getChild(int which) { return children[which]; }; - void setChild(int which, chillAST_node *n) { + void setChild(int which, chillAST_Node *n) { children[which] = n; children[which]->parent = this; }; - char *metacomment; // for compiler internals, formerly a comment void setMetaComment(const char *c) { metacomment = strdup(c); }; - std::vector<chillAST_Preprocessing *> preprocessinginfo; - virtual void addChild(chillAST_node *c) { + virtual void addChild(chillAST_Node *c) { c->parent = this; // check to see if it's already there for (int i = 0; i < children.size(); i++) { @@ -159,7 +164,13 @@ public: children.push_back(c); }; // not usually useful - virtual void insertChild(int i, chillAST_node *node) { + virtual void addChildren(const chillAST_NodeList &c){ + for (int i =0;i<c.size();++i){ + addChild(c[i]); + } + } + + virtual void insertChild(int i, chillAST_Node *node) { //fprintf(stderr, "%s inserting child of type %s at location %d\n", getTypeString(), node->getTypeString(), i); node->parent = this; children.insert(children.begin() + i, node); @@ -169,15 +180,15 @@ public: children.erase(children.begin() + i); }; - int findChild(chillAST_node *c) { + int findChild(chillAST_Node *c) { for (int i = 0; i < children.size(); i++) { if (children[i] == c) return i; } return -1; } - virtual void replaceChild(chillAST_node *old, chillAST_node *newchild) { - CHILL_DEBUG_PRINT("(%s) forgot to implement replaceChild() ... using generic\n", Chill_AST_Node_Names[asttype]); + virtual void replaceChild(chillAST_Node *old, chillAST_Node *newchild) { + CHILL_DEBUG_PRINT("(%s) forgot to implement replaceChild() ... using generic\n", getTypeString()); CHILL_DEBUG_PRINT("%d children\n", children.size()); for (int i = 0; i < children.size(); i++) { if (children[i] == old) { @@ -216,42 +227,43 @@ public: * @param var */ virtual void loseLoopWithLoopVar(char *var) { - std::vector<chillAST_node *> dupe = children; // simple enough? + std::vector<chillAST_Node *> dupe = children; // simple enough? for (int i = 0; i < dupe.size(); i++) { // recurse on all children dupe[i]->loseLoopWithLoopVar(var); } } virtual int evalAsInt() { - CHILL_ERROR("(%s) can't be evaluated as an integer??\n", Chill_AST_Node_Names[asttype]); + CHILL_ERROR("(%s) can't be evaluated as an integer??\n", getTypeString()); print(); exit(-1); } virtual const char *getUnderlyingType() { - CHILL_ERROR("(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]); + CHILL_ERROR("(%s) forgot to implement getUnderlyingType()\n", getTypeString()); dump(); print(); exit(-1); }; virtual chillAST_VarDecl *getUnderlyingVarDecl() { - CHILL_ERROR("(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]); + CHILL_ERROR("(%s) forgot to implement getUnderlyingVarDecl()\n", getTypeString()); dump(); print(); exit(-1); }; - 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]); + //! find the SINGLE constant or data reference at this node or below + virtual chillAST_Node *findref() { + CHILL_ERROR("(%s) forgot to implement findref()\n", getTypeString()); dump(); print(); exit(-1); }; virtual void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) { - CHILL_ERROR("(%s) forgot to implement gatherArrayRefs()\n", Chill_AST_Node_Names[asttype]); + CHILL_ERROR("(%s) forgot to implement gatherArrayRefs()\n", getTypeString()); dump(); print(); exit(-1); @@ -259,7 +271,7 @@ public: // TODO we MIGHT want the VarDecl // NOTHING IMPLEMENTS THIS? ??? virtual void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) { - CHILL_ERROR("(%s) forgot to implement gatherScalarRefs()\n", Chill_AST_Node_Names[asttype]); + CHILL_ERROR("(%s) forgot to implement gatherScalarRefs()\n", getTypeString()); dump(); print(); exit(-1); @@ -289,81 +301,81 @@ public: } //! recursive walk parent links, avoiding loops - chillAST_node *findContainingNonLoop() { + 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->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<chillAST_DeclRefExpr *> &refs) { // both scalar and arrays - fprintf(stderr, "(%s) forgot to implement gatherDeclRefExpr()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement gatherDeclRefExpr()\n", getTypeString()); }; virtual void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls) { - fprintf(stderr, "(%s) forgot to implement gatherVarUsage()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement gatherVarUsage()\n", getTypeString()); }; virtual void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls) { - fprintf(stderr, "(%s) forgot to implement gatherVarLHSUsage()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement gatherVarLHSUsage()\n", getTypeString()); }; //! ACTUAL Declaration virtual void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) { - fprintf(stderr, "(%s) forgot to implement gatherVarDecls()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement gatherVarDecls()\n", getTypeString()); }; virtual void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { // even if the decl itself is not in the ast. - fprintf(stderr, "(%s) forgot to implement gatherVarDeclsMore()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement gatherVarDeclsMore()\n", getTypeString()); }; virtual void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) { // ACTUAL Declaration - fprintf(stderr, "(%s) forgot to implement gatherScalarVarDecls()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement gatherScalarVarDecls()\n", getTypeString()); }; virtual void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls) { // ACTUAL Declaration - fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement gatherArrayVarDecls()\n", getTypeString()); }; 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", getTypeString()); } virtual void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { - fprintf(stderr, "(%s) forgot to implement replaceVarDecls()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement replaceVarDecls()\n", getTypeString()); }; //! 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]); + fprintf(stderr, "(%s) forgot to implement findLoopIndexesToReplace()\n", getTypeString()); return false; } - virtual chillAST_node *constantFold() { // hacky. TODO. make nice - CHILL_ERROR("(%s) forgot to implement constantFold()\n", Chill_AST_Node_Names[asttype]); + virtual chillAST_Node *constantFold() { // hacky. TODO. make nice + CHILL_ERROR("(%s) forgot to implement constantFold()\n", getTypeString()); exit(-1);; }; - virtual chillAST_node *clone() { // makes a deep COPY (?) - CHILL_ERROR("(%s) forgot to implement clone()\n", Chill_AST_Node_Names[asttype]); + virtual chillAST_Node *clone() { // makes a deep COPY (?) + CHILL_ERROR("(%s) forgot to implement clone()\n", getTypeString()); exit(-1);; }; //! 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]); + CHILL_ERROR("(%s) forgot to implement dump()\n", getTypeString()); };// print ast // TODO We might want to print the code a bit differently, This can be only a generic dump @@ -372,21 +384,21 @@ public: fflush(fp); fprintf(fp, "\n"); chillindent(indent, fp); - fprintf(fp, "(%s) forgot to implement print()\n", Chill_AST_Node_Names[asttype]); + fprintf(fp, "(%s) forgot to implement print()\n", getTypeString()); }; 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]); + fprintf(fp, "(%s) forgot to implement printName()\n", getTypeString()); };// print CODE //! The AST's print version virtual char *stringRep(int indent = 0) { fflush(stdout); // TODO chillindent(indent, fp); - CHILL_ERROR("(%s) forgot to implement stringRep()\n", Chill_AST_Node_Names[asttype]); + CHILL_ERROR("(%s) forgot to implement stringRep()\n", getTypeString()); exit(-1); } @@ -394,7 +406,7 @@ public: virtual void printonly(int indent = 0, FILE *fp = stderr) { print(indent, fp); }; //virtual void printString( std::string &s ) { - // fprintf(stderr,"(%s) forgot to implement printString()\n" ,Chill_AST_Node_Names[asttype]); + // fprintf(stderr,"(%s) forgot to implement printString()\n" ,getTypeString()); //} @@ -434,7 +446,7 @@ public: } - // generic for chillAST_node with children + // generic for chillAST_Node with children virtual void find_deepest_loops(std::vector<chillAST_ForStmt *> &loops) { // returns DEEPEST nesting of loops std::vector<chillAST_ForStmt *> deepest; // deepest below here @@ -461,13 +473,11 @@ public: } - const char *getTypeString() { return Chill_AST_Node_Names[asttype]; }; - - int getType() { return asttype; }; + const char *getTypeString() { return ChillAST_Node_Names[getType()]; }; - void setParent(chillAST_node *p) { parent = p; }; + void setParent(chillAST_Node *p) { parent = p; }; - chillAST_node *getParent() { return parent; }; + chillAST_Node *getParent() { return parent; }; chillAST_SourceFile *getSourceFile() { if (isSourceFile()) return ((chillAST_SourceFile *) this); @@ -480,7 +490,7 @@ public: exit(-1); } - virtual chillAST_node *findDatatype(char *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; @@ -515,21 +525,21 @@ public: return; } - virtual chillAST_node *getEnclosingStatement(int level = 0); + virtual chillAST_Node *getEnclosingStatement(int level = 0); virtual chillAST_VarDecl *multibase() { - fprintf(stderr, "(%s) forgot to implement multibase()\n", Chill_AST_Node_Names[asttype]); + fprintf(stderr, "(%s) forgot to implement multibase()\n", getTypeString()); 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", getTypeString()); exit(-1); } - virtual void gatherStatements(std::vector<chillAST_node *> &statements) { - fprintf(stderr, "(%s) forgot to implement gatherStatements()\n", Chill_AST_Node_Names[asttype]); + virtual void gatherStatements(std::vector<chillAST_Node *> &statements) { + fprintf(stderr, "(%s) forgot to implement gatherStatements()\n", getTypeString()); dump(); fflush(stdout); print(); @@ -537,8 +547,8 @@ public: } - virtual bool isSameAs(chillAST_node *other) { // for tree comparison - fprintf(stderr, "(%s) forgot to implement isSameAs()\n", Chill_AST_Node_Names[asttype]); + virtual bool isSameAs(chillAST_Node *other) { // for tree comparison + fprintf(stderr, "(%s) forgot to implement isSameAs()\n", getTypeString()); dump(); fflush(stdout); print(); diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index c7d13dd..fd7ebe4 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -6,11 +6,11 @@ #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) { + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_NULL;} + chillAST_NULL(chillAST_Node *p = NULL) { parent = p; - asttype = CHILLAST_NODETYPE_NULL; }; void print(int indent = 0, FILE *fp = stderr) { @@ -27,16 +27,17 @@ public: }; -class chillAST_Preprocessing : public chillAST_node { +class chillAST_Preprocessing : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_PREPROCESSING;} // variables that are special for this type of node - CHILL_PREPROCESSING_POSITION position; - CHILL_PREPROCESSING_TYPE pptype; + CHILLAST_PREPROCESSING_POSITION position; + CHILLAST_PREPROCESSING_TYPE pptype; char *blurb; // constructors chillAST_Preprocessing(); // not sure what this is good for - chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos, CHILL_PREPROCESSING_TYPE t, char *text); + chillAST_Preprocessing(CHILLAST_PREPROCESSING_POSITION pos, CHILLAST_PREPROCESSING_TYPE t, char *text); // other methods particular to this type of node @@ -47,14 +48,15 @@ public: //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; char *structname; // get rid of this? public: - char *newtype; // the new type name ?? + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_TYPEDEFDECL;} + char *newtype; // the new type name ?? char *underlyingtype; // float, int, "struct bubba" ? char *arraypart; // string like "[1234][56]" ?? @@ -90,28 +92,27 @@ public: //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, chillAST_Node *p); - chillAST_TypedefDecl(char *t, const char *nt, char *a, chillAST_node *par); + chillAST_TypedefDecl(char *t, const char *nt, char *a, chillAST_Node *par); 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 printString( std::string &s ); }; -class chillAST_VarDecl : public chillAST_node { +class chillAST_VarDecl : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_VARDECL;} 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 @@ -158,26 +159,26 @@ public: bool knowAllDimensions() { return knownArraySizes; }; - chillAST_node *init; + chillAST_Node *init; - void setInit(chillAST_node *i) { + void setInit(chillAST_Node *i) { init = i; i->setParent(this); }; bool hasInit() { return init != NULL; }; - chillAST_node *getInit() { return init; }; + 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, chillAST_Node *p); - chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, 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_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); + chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_Node *par); void dump(int indent = 0, FILE *fp = stderr); @@ -209,40 +210,41 @@ public: virtual chillAST_VarDecl *getUnderlyingVarDecl() { return this; }; - chillAST_node *constantFold(); + chillAST_Node *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); }; -class chillAST_DeclRefExpr : public chillAST_node { +class chillAST_DeclRefExpr : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_DECLREFEXPR;} // variables that are special for this type of node char *declarationType; char *declarationName; - chillAST_node *decl; // the declaration of this variable or function ... uhoh + 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 *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 *p); - chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_node *dec, 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_VarDecl *vd, chillAST_Node *p = NULL); - chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, 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 - chillAST_node *getDecl() { return decl; }; + chillAST_Node *getDecl() { return decl; }; chillAST_VarDecl *getVarDecl() { if (!decl) return NULL; // should never happen @@ -261,9 +263,9 @@ public: void dump(int indent = 0, FILE *fp = stderr); // print ast char *stringRep(int indent = 0); - chillAST_node *constantFold(); + chillAST_Node *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {}; // do nothing void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento); @@ -287,10 +289,10 @@ public: 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 + 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"); + CHILL_DEBUG_PRINT("DeclRefExpr getUnderLyingType()\n"); return decl->getUnderlyingType(); }; @@ -298,12 +300,13 @@ public: chillAST_VarDecl *multibase(); - chillAST_node *multibase2() { return (chillAST_node *) multibase(); } + chillAST_Node *multibase2() { return (chillAST_Node *) multibase(); } }; -class chillAST_CompoundStmt : public chillAST_node { +class chillAST_CompoundStmt : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_COMPOUNDSTMT;} // variables that are special for this type of node chillAST_SymbolTable *symbol_table; // symbols defined inside this compound statement chillAST_TypedefTable *typedef_table; @@ -312,7 +315,7 @@ public: bool hasTypeDefTable() { return true; }; - chillAST_node *findDatatype(char *t) { + 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++) { @@ -344,15 +347,15 @@ public: // required methods - void replaceChild(chillAST_node *old, chillAST_node *newchild); + 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls); @@ -376,11 +379,11 @@ public: void loseLoopWithLoopVar(char *var); // special case this for not for debugging - void gatherStatements(std::vector<chillAST_node *> &statements); + void gatherStatements(std::vector<chillAST_Node *> &statements); }; -class chillAST_RecordDecl : public chillAST_node { // declaration of the shape of a struct or union +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; @@ -390,11 +393,12 @@ private: std::vector<chillAST_VarDecl *> subparts; public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_RECORDDECL;} chillAST_RecordDecl(); - chillAST_RecordDecl(const char *nam, chillAST_node *p); + chillAST_RecordDecl(const char *nam, chillAST_Node *p); - chillAST_RecordDecl(const char *nam, const char *orig, chillAST_node *p); + chillAST_RecordDecl(const char *nam, const char *orig, chillAST_Node *p); void setName(const char *newname) { name = strdup(newname); }; @@ -431,15 +435,16 @@ public: }; -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 + CHILLAST_FUNCTION_TYPE function_type; // CHILLAST_FUNCTION_CPU or CHILLAST_FUNCTION_GPU bool externfunc; // function is external bool builtin; // function is a builtin bool forwarddecl; public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_FUNCTIONDECL;} char *returnType; char *functionName; @@ -471,23 +476,23 @@ public: void setForward() { forwarddecl = true; }; // designate function as fwd declaration bool isForward() { return forwarddecl; }; // report whether function is external - bool isFunctionCPU() { return (function_type == CHILL_FUNCTION_CPU); }; + bool isFunctionCPU() { return (function_type == CHILLAST_FUNCTION_CPU); }; - bool isFunctionGPU() { return (function_type == CHILL_FUNCTION_GPU); }; + bool isFunctionGPU() { return (function_type == CHILLAST_FUNCTION_GPU); }; - void setFunctionCPU() { function_type = CHILL_FUNCTION_CPU; }; + void setFunctionCPU() { function_type = CHILLAST_FUNCTION_CPU; }; - void setFunctionGPU() { function_type = CHILL_FUNCTION_GPU; }; + void setFunctionGPU() { function_type = CHILLAST_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(); // { asttype = CHILLAST_NODE_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); + chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_Node *p, void *unique); void addParameter(chillAST_VarDecl *p); @@ -500,10 +505,10 @@ public: 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); + void setBody(chillAST_Node *bod); chillAST_CompoundStmt *getBody() { return (body); } @@ -531,9 +536,9 @@ public: //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false); - chillAST_node *constantFold(); + chillAST_Node *constantFold(); - chillAST_node *findDatatype(char *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 @@ -581,7 +586,7 @@ public: typedef_table = addTypedefToTable(typedef_table, tdd); } - void replaceChild(chillAST_node *old, chillAST_node *newchild) { + void replaceChild(chillAST_Node *old, chillAST_Node *newchild) { body->replaceChild(old, newchild); } }; // end FunctionDecl @@ -589,8 +594,9 @@ public: -class chillAST_SourceFile : public chillAST_node { +class chillAST_SourceFile : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_SOURCEFILE;} // constructors chillAST_SourceFile(); // defined in chill_ast.cc @@ -633,7 +639,7 @@ public: //fprintf(stderr, "now global typedef table has %d entries\n", global_typedef_table->size()); } - chillAST_node *findDatatype(char *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++) { @@ -642,7 +648,7 @@ public: //fprintf(stderr, "comparing to %s\n", tdd->getStructName()); if (tdd->nameis(t)) { //fprintf(stderr, "found it\n"); - return (chillAST_node *) tdd; + return (chillAST_Node *) tdd; } } return NULL; @@ -653,7 +659,7 @@ public: chillAST_MacroDefinition *findMacro(const char *name); // TODO ignores arguments chillAST_FunctionDecl *findFunction(const char *name); // TODO ignores arguments - chillAST_node *findCall(const char *name); + chillAST_Node *findCall(const char *name); void addMacro(chillAST_MacroDefinition *md) { macrodefinitions.push_back(md); @@ -674,16 +680,17 @@ 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_Node *body; // rhs always a compound statement? chillAST_SymbolTable *symbol_table; public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_MACRODEFINITION;} char *macroName; char *rhsString; @@ -699,21 +706,21 @@ public: chillAST_MacroDefinition(); - chillAST_MacroDefinition(const char *name, chillAST_node *par); + chillAST_MacroDefinition(const char *name, chillAST_Node *par); - chillAST_MacroDefinition(const char *name, const char *rhs, 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 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); + void setBody(chillAST_Node *bod); - chillAST_node *getBody() { return (body); } + 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 @@ -731,7 +738,7 @@ public: } - chillAST_node *clone(); + chillAST_Node *clone(); // none of these make sense for macros void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls) {}; @@ -752,16 +759,17 @@ public: bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) {}; - chillAST_node *constantFold() {}; + chillAST_Node *constantFold() {}; }; -class chillAST_ForStmt : public chillAST_node { +class chillAST_ForStmt : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_FORSTMT;} // variables that are special for this type of node - chillAST_node *init; - chillAST_node *cond; - chillAST_node *incr; - chillAST_node *body; // always a compoundstmt? + chillAST_Node *init; + chillAST_Node *cond; + chillAST_Node *incr; + chillAST_Node *body; // always a compoundstmt? 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 @@ -770,25 +778,25 @@ public: // 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(); - chillAST_node *getInit() { return init; }; + chillAST_Node *getInit() { return init; }; - chillAST_node *getCond() { return cond; }; + chillAST_Node *getCond() { return cond; }; - chillAST_node *getInc() { return incr; }; + chillAST_Node *getInc() { return incr; }; - chillAST_node * - getBody() { //fprintf(stderr, "chillAST_ForStmt::getBody(), returning a chillAST_node of type %s\n", body->getTypeString()); + 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) { + void setBody(chillAST_Node *b) { body = b; b->parent = this; }; @@ -803,9 +811,9 @@ public: 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls); @@ -862,7 +870,7 @@ public: void loseLoopWithLoopVar(char *var); // chillAST_ForStmt - void replaceChild(chillAST_node *old, chillAST_node *newchild); + void replaceChild(chillAST_Node *old, chillAST_Node *newchild); chillAST_SymbolTable *addVariableToSymbolTable(chillAST_VarDecl *vd) { // chillAST_ForStmt method //fprintf(stderr, "\nchillAST_ForStmt addVariableToSymbolTable( %s )\n", vd->varname); @@ -871,7 +879,7 @@ public: return symbol_table; } - void gatherStatements(std::vector<chillAST_node *> &statements); + void gatherStatements(std::vector<chillAST_Node *> &statements); bool lowerBound(int &l); @@ -880,20 +888,21 @@ public: }; -class chillAST_TernaryOperator : public chillAST_node { +class chillAST_TernaryOperator : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_TERNARYOPERATOR;} // 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; + 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; }; @@ -902,23 +911,23 @@ public: char *getOp() { return op; }; // dangerous. could get changed! - chillAST_node *getCond() { return condition; }; + chillAST_Node *getCond() { return condition; }; - chillAST_node *getRHS() { return rhs; }; + chillAST_Node *getRHS() { return rhs; }; - chillAST_node *getLHS() { return lhs; }; + chillAST_Node *getLHS() { return lhs; }; - void setCond(chillAST_node *newc) { + void setCond(chillAST_Node *newc) { condition = newc; newc->setParent(this); } - void setLHS(chillAST_node *newlhs) { + void setLHS(chillAST_Node *newlhs) { lhs = newlhs; newlhs->setParent(this); } - void setRHS(chillAST_node *newrhs) { + void setRHS(chillAST_Node *newrhs) { rhs = newrhs; newrhs->setParent(this); } @@ -929,11 +938,11 @@ public: 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(); + chillAST_Node *clone(); - void replaceChild(chillAST_node *old, chillAST_node *newchild); + void replaceChild(chillAST_Node *old, chillAST_Node *newchild); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -961,18 +970,19 @@ public: }; -class chillAST_BinaryOperator : public chillAST_node { +class chillAST_BinaryOperator : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_BINARYOPERATOR;} // variables that are special for this type of node char *op; // TODO need enum - chillAST_node *lhs; - chillAST_node *rhs; + 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(); @@ -983,16 +993,16 @@ public: bool isLeaf() { return false; }; - chillAST_node *getRHS() { return rhs; }; + chillAST_Node *getRHS() { return rhs; }; - chillAST_node *getLHS() { return lhs; }; + chillAST_Node *getLHS() { return lhs; }; - void setLHS(chillAST_node *newlhs) { + void setLHS(chillAST_Node *newlhs) { lhs = newlhs; newlhs->setParent(this); } - void setRHS(chillAST_node *newrhs) { + void setRHS(chillAST_Node *newrhs) { rhs = newrhs; newrhs->setParent(this); } @@ -1042,11 +1052,11 @@ public: char *stringRep(int indent = 0); - chillAST_node *constantFold(); + chillAST_Node *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); - void replaceChild(chillAST_node *old, chillAST_node *newchild); + void replaceChild(chillAST_Node *old, chillAST_Node *newchild); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); // chillAST_BinaryOperator void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento); @@ -1071,18 +1081,19 @@ public: bool forcesync = false) { return false; }; // no loops under here void loseLoopWithLoopVar(char *var) {}; // binop can't have loop as child? - void gatherStatements(std::vector<chillAST_node *> &statements); // + void gatherStatements(std::vector<chillAST_Node *> &statements); // - bool isSameAs(chillAST_node *other); + bool isSameAs(chillAST_Node *other); }; -class chillAST_ArraySubscriptExpr : public chillAST_node { +class chillAST_ArraySubscriptExpr : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_ARRAYSUBSCRIPTEXPR;} // variables that are special for this type of node - chillAST_node *base; // always a decl ref expr? No, for multidimensional array, is another ASE - chillAST_node *index; + chillAST_Node *base; // always a decl ref expr? No, for multidimensional array, is another ASE + chillAST_Node *index; bool imwrittento; 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 @@ -1091,11 +1102,11 @@ public: // constructors chillAST_ArraySubscriptExpr(); - chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, chillAST_node *p, void *unique); + 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_Node *bas, chillAST_Node *indx, bool writtento, chillAST_Node *p, void *unique); - chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_node *> indeces, chillAST_node *p); + chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_Node *> indeces, chillAST_Node *p); // other methods particular to this type of node bool operator!=(const chillAST_ArraySubscriptExpr &); @@ -1103,13 +1114,13 @@ public: 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); + chillAST_Node *getIndex(int dim); - void gatherIndeces(std::vector<chillAST_node *> &ind); + void gatherIndeces(std::vector<chillAST_Node *> &ind); - void replaceChild(chillAST_node *old, chillAST_node *newchild); // will examine index + 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 @@ -1119,11 +1130,11 @@ public: void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc char *stringRep(int indent = 0); - chillAST_node *constantFold(); + chillAST_Node *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); - chillAST_node *findref() { return this; }// find the SINGLE constant or data reference at this node or below + chillAST_Node *findref() { return this; }// find the SINGLE constant or data reference at this node or below void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento); @@ -1155,24 +1166,25 @@ public: }; -class chillAST_MemberExpr : public chillAST_node { +class chillAST_MemberExpr : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_MEMBEREXPR;} // variables that are special for this type of node - chillAST_node *base; // always a decl ref expr? No, can be Array Subscript Expr + chillAST_Node *base; // always a decl ref expr? No, can be Array Subscript Expr 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; + CHILLAST_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_Node *bas, const char *mem, chillAST_Node *p, void *unique, + CHILLAST_MEMBER_EXP_TYPE t = CHILLAST_MEMBER_EXP_DOT); // other methods particular to this type of node bool operator!=(const chillAST_MemberExpr &); @@ -1187,9 +1199,9 @@ public: void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc char *stringRep(int indent = 0); - chillAST_node *constantFold(); + chillAST_Node *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1214,24 +1226,25 @@ public: chillAST_VarDecl *getUnderlyingVarDecl(); - void replaceChild(chillAST_node *old, chillAST_node *newchild); + void replaceChild(chillAST_Node *old, chillAST_Node *newchild); - void setType(CHILL_MEMBER_EXP_TYPE t) { exptype = t; }; + void setType(CHILLAST_MEMBER_EXP_TYPE t) { exptype = t; }; - CHILL_MEMBER_EXP_TYPE getType(CHILL_MEMBER_EXP_TYPE t) { return exptype; }; + CHILLAST_MEMBER_EXP_TYPE getType(CHILLAST_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 + chillAST_Node *multibase2(); // this one will return the member expression }; -class chillAST_IntegerLiteral : public chillAST_node { +class chillAST_IntegerLiteral : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_INTEGERLITERAL;} // 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; } @@ -1239,9 +1252,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {}; // does nothing void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {}; // does nothing @@ -1259,12 +1272,13 @@ public: 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 + chillAST_Node *findref() { return this; }// find the SINGLE constant or data reference at this node or below }; -class chillAST_FloatingLiteral : public chillAST_node { +class chillAST_FloatingLiteral : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_FLOATINGLITERAL;} // variables that are special for this type of node float value; double doublevalue; @@ -1274,17 +1288,17 @@ public: int precision; // float == 1, double == 2, ??? // constructors - chillAST_FloatingLiteral(float val, chillAST_node *p); + chillAST_FloatingLiteral(float val, chillAST_Node *p); - chillAST_FloatingLiteral(double val, chillAST_node *p); + chillAST_FloatingLiteral(double val, chillAST_Node *p); - chillAST_FloatingLiteral(float val, int pre, chillAST_node *p); + chillAST_FloatingLiteral(float val, int pre, chillAST_Node *p); - chillAST_FloatingLiteral(double 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, const char *printable, chillAST_Node *p); - chillAST_FloatingLiteral(float val, int pre, const char *printable, chillAST_node *p); + chillAST_FloatingLiteral(float val, int pre, const char *printable, chillAST_Node *p); chillAST_FloatingLiteral(chillAST_FloatingLiteral *old); @@ -1296,9 +1310,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {}; // does nothing void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {}; // does nothing @@ -1315,21 +1329,22 @@ public: 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 + chillAST_Node *findref() { return this; };// find the SINGLE constant or data reference at this node or below - bool isSameAs(chillAST_node *other); + bool isSameAs(chillAST_Node *other); }; -class chillAST_UnaryOperator : public chillAST_node { +class chillAST_UnaryOperator : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_UNARYOPERATOR;} // variables that are special for this type of node char *op; // TODO enum bool prefix; // or post - chillAST_node *subexpr; + 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() { @@ -1340,9 +1355,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls); @@ -1368,18 +1383,19 @@ public: int evalAsInt(); - bool isSameAs(chillAST_node *other); + bool isSameAs(chillAST_Node *other); }; -class chillAST_ImplicitCastExpr : public chillAST_node { +class chillAST_ImplicitCastExpr : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_IMPLICITCASTEXPR;} // variables that are special for this type of node - chillAST_node *subexpr; + 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; }; @@ -1387,14 +1403,14 @@ public: bool isLeaf() { return false; }; // required methods that I can't seem to get to inherit - void replaceChild(chillAST_node *old, chillAST_node *newchild); + 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1420,26 +1436,27 @@ public: }; -class chillAST_CStyleCastExpr : public chillAST_node { +class chillAST_CStyleCastExpr : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_CSTYLECASTEXPR;} // variables that are special for this type of node char *towhat; - chillAST_node *subexpr; + 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 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1461,18 +1478,19 @@ public: bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here - chillAST_node *findref() { return subexpr; };// find the SINGLE constant or data reference at this node or below + chillAST_Node *findref() { return subexpr; };// find the SINGLE constant or data reference at this node or below }; -class chillAST_CStyleAddressOf : public chillAST_node { +class chillAST_CStyleAddressOf : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_CSTYLEADDRESSOF;} // variables that are special for this type of node - chillAST_node *subexpr; + 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 @@ -1480,9 +1498,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1508,14 +1526,15 @@ public: }; -class chillAST_CudaMalloc : public chillAST_node { +class chillAST_CudaMalloc : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_CUDAMALLOC;} // variables that are special for this type of node - chillAST_node *devPtr; // Pointer to allocated device memory - chillAST_node *sizeinbytes; + 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 @@ -1523,9 +1542,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1549,13 +1568,14 @@ public: }; -class chillAST_CudaFree : public chillAST_node { +class chillAST_CudaFree : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_CUDAFREE;} // variables that are special for this type of node 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 @@ -1563,9 +1583,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1589,16 +1609,17 @@ public: }; -class chillAST_Malloc : public chillAST_node { // malloc( sizeof(int) * 2048 ); +class chillAST_Malloc : public chillAST_Node { // malloc( sizeof(int) * 2048 ); public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_MALLOC;} // 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 + chillAST_Node *sizeexpr; // bytes // constructors - chillAST_Malloc(chillAST_node *size, chillAST_node *p = NULL); + 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(char *thething, chillAST_Node *numthings, chillAST_Node *p = NULL); // malloc (sizeof(int) *1024) // other methods particular to this type of node @@ -1606,9 +1627,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1632,24 +1653,25 @@ public: }; -class chillAST_Free : public chillAST_node { +class chillAST_Free : public chillAST_Node { public: - + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_FREE;} }; -class chillAST_CudaMemcpy : public chillAST_node { +class chillAST_CudaMemcpy : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_CUDAMEMCPY;} // variables that are special for this type of node chillAST_VarDecl *dest; // Pointer to allocated device memory chillAST_VarDecl *src; - chillAST_node *size; + chillAST_Node *size; 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 @@ -1657,9 +1679,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1683,12 +1705,13 @@ public: }; -class chillAST_CudaSyncthreads : public chillAST_node { +class chillAST_CudaSyncthreads : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_CUDASYNCTHREADS;} // variables that are special for this type of node // constructors - chillAST_CudaSyncthreads(chillAST_node *p = NULL); + chillAST_CudaSyncthreads(chillAST_Node *p = NULL); // other methods particular to this type of node @@ -1696,8 +1719,8 @@ public: // 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(); + //chillAST_Node* constantFold() {}; + //chillAST_Node* clone(); //void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ){}; //void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ; @@ -1715,13 +1738,14 @@ public: }; -class chillAST_ReturnStmt : public chillAST_node { +class chillAST_ReturnStmt : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_RETURNSTMT;} // variables that are special for this type of node - chillAST_node *returnvalue; + 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 @@ -1729,9 +1753,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls); @@ -1752,25 +1776,26 @@ public: }; -class chillAST_CallExpr : public chillAST_node { // a function call +class chillAST_CallExpr : public chillAST_Node { // a function call public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_CALLEXPR;} // variables that are special for this type of node - chillAST_node *callee; // the function declaration (what about builtins?) + chillAST_Node *callee; // the function declaration (what about builtins?) int numargs; - std::vector<class chillAST_node *> args; + std::vector<class chillAST_Node *> args; chillAST_VarDecl *grid; chillAST_VarDecl *block; // constructors - chillAST_CallExpr(chillAST_node *function, chillAST_node *p); + chillAST_CallExpr(chillAST_Node *function, chillAST_Node *p); - void addArg(chillAST_node *newarg); + 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(); + 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 @@ -1794,17 +1819,18 @@ public: bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false) { return false; }; // no loops under here - chillAST_node *clone(); + chillAST_Node *clone(); }; -class chillAST_ParenExpr : public chillAST_node { +class chillAST_ParenExpr : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_PARENEXPR;} // variables that are special for this type of node - chillAST_node *subexpr; + 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 @@ -1812,9 +1838,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1840,13 +1866,14 @@ public: }; -class chillAST_Sizeof : public chillAST_node { +class chillAST_Sizeof : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_SIZEOF;} // variables that are special for this type of node 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 @@ -1854,9 +1881,9 @@ public: // 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 *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); @@ -1882,16 +1909,17 @@ public: }; -class chillAST_NoOp : public chillAST_node { +class chillAST_NoOp : public chillAST_Node { public: - chillAST_NoOp(chillAST_node *p = NULL); // { parent = p; }; + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_NOOP;} + 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 *constantFold() {}; - chillAST_node *clone() { return new chillAST_NoOp(parent); }; // ?? + chillAST_Node *clone() { return new chillAST_NoOp(parent); }; // ?? void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {}; @@ -1916,37 +1944,38 @@ public: }; -class chillAST_IfStmt : public chillAST_node { +class chillAST_IfStmt : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_IFSTMT;} // variables that are special for this type of node - chillAST_node *cond; - chillAST_node *thenpart; - chillAST_node *elsepart; + 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 *getCond() { return cond; }; - chillAST_node *getThen() { return thenpart; }; + chillAST_Node *getThen() { return thenpart; }; - chillAST_node *getElse() { return elsepart; }; + chillAST_Node *getElse() { return elsepart; }; - void setCond(chillAST_node *b) { + void setCond(chillAST_Node *b) { cond = b; if (cond) cond->parent = this; }; - void setThen(chillAST_node *b) { + void setThen(chillAST_Node *b) { thenpart = b; if (thenpart) thenpart->parent = this; }; - void setElse(chillAST_node *b) { + void setElse(chillAST_Node *b) { elsepart = b; if (elsepart) elsepart->parent = this; }; @@ -1956,9 +1985,9 @@ public: void print(int indent = 0, FILE *fp = stderr); - chillAST_node *constantFold(); + chillAST_Node *constantFold(); - chillAST_node *clone(); + chillAST_Node *clone(); void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls); @@ -1979,13 +2008,14 @@ public: //void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync = false); - void gatherStatements(std::vector<chillAST_node *> &statements); + void gatherStatements(std::vector<chillAST_Node *> &statements); }; -class chillAST_something : public chillAST_node { +class chillAST_something : public chillAST_Node { public: + virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_UNKNOWN;} // variables that are special for this type of node // constructors |