diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-23 16:30:09 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-23 16:30:09 -0600 |
commit | 2f96d12dd05213276875d56fec361ff99ec9bd76 (patch) | |
tree | bd3a03c166198f75d529994b35870caf59be58da | |
parent | 699861922d5349ffa98b518f34016b2be2ca368d (diff) | |
download | chill-2f96d12dd05213276875d56fec361ff99ec9bd76.tar.gz chill-2f96d12dd05213276875d56fec361ff99ec9bd76.tar.bz2 chill-2f96d12dd05213276875d56fec361ff99ec9bd76.zip |
staging
-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 | ||||
-rwxr-xr-x | include/ir_clang.hh | 24 | ||||
-rw-r--r-- | include/loop.hh | 2 | ||||
-rw-r--r-- | include/stencil.hh | 10 | ||||
-rwxr-xr-x | lib/chillcg/include/code_gen/CG_chillRepr.h | 16 | ||||
-rwxr-xr-x | lib/chillcg/src/CG_chillBuilder.cc | 198 | ||||
-rwxr-xr-x | lib/chillcg/src/CG_chillRepr.cc | 2 | ||||
-rw-r--r-- | src/chillASTs.cc | 709 | ||||
-rwxr-xr-x | src/ir_clang.cc | 479 | ||||
-rw-r--r-- | src/omegatools.cc | 4 |
12 files changed, 1150 insertions, 1206 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 diff --git a/include/ir_clang.hh b/include/ir_clang.hh index 9148eb3..1237d25 100755 --- a/include/ir_clang.hh +++ b/include/ir_clang.hh @@ -149,7 +149,7 @@ struct IR_chillScalarRef : public IR_ScalarRef { dre = NULL; //bop = ins; // do we need this? if (pos == OP_LEFT) { - chillAST_node *lhs = ins->lhs; + chillAST_Node *lhs = ins->lhs; if (lhs->isDeclRefExpr()) { chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) lhs; dre = DRE; @@ -161,7 +161,7 @@ struct IR_chillScalarRef : public IR_ScalarRef { exit(-1); } } else { - chillAST_node *rhs = ins->rhs; + chillAST_Node *rhs = ins->rhs; if (rhs->isDeclRefExpr()) { chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) rhs; dre = DRE; @@ -265,9 +265,9 @@ struct IR_chillLoop : public IR_Loop { chillAST_DeclRefExpr *chillindex; // the loop index variable (I) // was DeclRefExpr chillAST_ForStmt *chillforstmt; - chillAST_node *chilllowerbound; - chillAST_node *chillupperbound; - chillAST_node *chillbody; // presumably a compound statement, but not guaranteeed + chillAST_Node *chilllowerbound; + chillAST_Node *chillupperbound; + chillAST_Node *chillbody; // presumably a compound statement, but not guaranteeed IR_CONDITION_TYPE conditionoperator; IR_chillLoop(const IR_Code *ir, clang::ForStmt *tf); @@ -309,18 +309,18 @@ private: public: // Block is a basic block?? (no, just a chunk of code ) - std::vector<chillAST_node *> statements; + std::vector<chillAST_Node *> statements; IR_chillBlock(const IR_chillBlock *CB) { // clone existing IR_chillBlock ir_ = CB->ir_; for (int i = 0; i < CB->statements.size(); i++) statements.push_back(CB->statements[i]); } - IR_chillBlock(const IR_Code *ir, std::vector<chillAST_node *> ast) : statements(ast) { + IR_chillBlock(const IR_Code *ir, std::vector<chillAST_Node *> ast) : statements(ast) { ir_ = ir; } - IR_chillBlock(const IR_Code *ir, chillAST_node *ast = NULL) { // : cs_(NULL), bDecl_(NULL) { + IR_chillBlock(const IR_Code *ir, chillAST_Node *ast = NULL) { // : cs_(NULL), bDecl_(NULL) { ir_ = ir; if (ast != NULL) statements.push_back(ast); @@ -336,11 +336,11 @@ public: IR_Control *clone() const; //StmtList getStmtList() const; - std::vector<chillAST_node *> getStmtList() const; + std::vector<chillAST_Node *> getStmtList() const; int numstatements() { return statements.size(); }; - void addStatement(chillAST_node *s); + void addStatement(chillAST_Node *s); void dump() const; }; @@ -434,7 +434,7 @@ public: aClangCompiler *ClangCompiler; // this is the thing we really just want one of - void setCurrentFunction(chillAST_node *F) { chillFD = (chillAST_FunctionDecl *) F; }; + void setCurrentFunction(chillAST_Node *F) { chillFD = (chillAST_FunctionDecl *) F; }; chillAST_FunctionDecl *getCurrentFunction() { return chillFD; }; @@ -457,7 +457,7 @@ protected: char *procedurename; - chillAST_node *entire_file_AST; + chillAST_Node *entire_file_AST; chillAST_FunctionDecl *chillfunc; // the function we're currenly modifying std::vector<chillAST_VarDecl> entire_file_symbol_table; diff --git a/include/loop.hh b/include/loop.hh index 72295b6..5af9975 100644 --- a/include/loop.hh +++ b/include/loop.hh @@ -118,7 +118,7 @@ public: ~Loop(); omega::CG_outputRepr *getCode(int effort = 3) const; // TODO was 1 - //chillAST_node* getCode(int effort, std::set<int> stmts) const; + //chillAST_Node* getCode(int effort, std::set<int> stmts) const; void stencilASEPadded(int stmt_num); diff --git a/include/stencil.hh b/include/stencil.hh index 15bd94f..09471e8 100644 --- a/include/stencil.hh +++ b/include/stencil.hh @@ -16,7 +16,7 @@ // *extern Loop *myloop; // ??? -//void stencil( chillAST_node *topstatement, class stencilInfo &SI ); // stencilInfo was originally a struct, and this was the way it got filled in. TODO remove +//void stencil( chillAST_Node *topstatement, class stencilInfo &SI ); // stencilInfo was originally a struct, and this was the way it got filled in. TODO remove class stencilInfo { @@ -34,15 +34,15 @@ public: std::vector<std::vector<int> > offsets; // k+1, j-47, i+0 etc - std::vector<std::vector<chillAST_node *> > coefficients; // the coefficients of for each element, NOT IN ANY SET ORDER - chillAST_node *find_coefficient(int i, int j, int k); // hardcoded 3 dimensions TODO + std::vector<std::vector<chillAST_Node *> > coefficients; // the coefficients of for each element, NOT IN ANY SET ORDER + chillAST_Node *find_coefficient(int i, int j, int k); // hardcoded 3 dimensions TODO // constructors stencilInfo(); - stencilInfo(chillAST_node *topstatement); + stencilInfo(chillAST_Node *topstatement); - void walktree(chillAST_node *node, std::vector<chillAST_node *> &coeffstohere); + void walktree(chillAST_Node *node, std::vector<chillAST_Node *> &coeffstohere); void print(FILE *fp = stdout); diff --git a/lib/chillcg/include/code_gen/CG_chillRepr.h b/lib/chillcg/include/code_gen/CG_chillRepr.h index 4a0510f..bcc267f 100755 --- a/lib/chillcg/include/code_gen/CG_chillRepr.h +++ b/lib/chillcg/include/code_gen/CG_chillRepr.h @@ -26,7 +26,7 @@ namespace omega { char *type() const { return strdup("chill"); }; // - std::vector<chillAST_node *> chillnodes; // TODO make private + std::vector<chillAST_Node *> chillnodes; // TODO make private void printChillNodes() const { for (int i = 0; i < chillnodes.size(); i++) { chillnodes[i]->print(); @@ -35,15 +35,15 @@ namespace omega { fflush(stdout); }; - CG_chillRepr(std::vector<chillAST_node *> cnodes) { + CG_chillRepr(std::vector<chillAST_Node *> cnodes) { chillnodes = cnodes; } - CG_chillRepr(chillAST_node *chillast) { + CG_chillRepr(chillAST_Node *chillast) { stmtclassname = strdup(chillast->getTypeString()); //fprintf(stderr, "made new chillRepr of class %s\n", stmtclassname); - if (chillast->asttype == CHILLAST_NODETYPE_COMPOUNDSTMT) { - std::vector<chillAST_node *> children = chillast->getChildren(); + if (chillast->getType() == CHILLAST_NODE_COMPOUNDSTMT) { + std::vector<chillAST_Node *> children = chillast->getChildren(); int numchildren = children.size(); for (int i = 0; i < numchildren; i++) { chillnodes.push_back(children[i]); @@ -54,11 +54,11 @@ namespace omega { } } - void addStatement(chillAST_node *s) { chillnodes.push_back(s); }; + void addStatement(chillAST_Node *s) { chillnodes.push_back(s); }; - std::vector<chillAST_node *> getChillCode() const { return chillnodes; }; + std::vector<chillAST_Node *> getChillCode() const { return chillnodes; }; - chillAST_node *GetCode(); + chillAST_Node *GetCode(); ~CG_chillRepr(); diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc index 4593b26..648353a 100755 --- a/lib/chillcg/src/CG_chillBuilder.cc +++ b/lib/chillcg/src/CG_chillBuilder.cc @@ -22,28 +22,28 @@ namespace omega { // substitute at chill AST level // forward declarations - chillAST_node *substituteChill( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubABinaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubUnaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubDeclRefExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubArraySubscriptExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubImplicitCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubCStyleCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubParenExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubCallExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubReturnStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubIfStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubCompoundStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); - chillAST_node *SubMemberExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); + chillAST_Node *substituteChill( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubABinaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubUnaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubDeclRefExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubArraySubscriptExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubImplicitCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubCStyleCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubParenExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubCallExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubReturnStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubIfStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubCompoundStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); + chillAST_Node *SubMemberExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); - // chillAST_node *Sub( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent ); // fwd decl + // chillAST_Node *Sub( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent ); // fwd decl - chillAST_node *substituteChill( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *substituteChill( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { if (n == NULL) { fprintf(stderr, "substituteChill() pointer n == NULL\n"); // DIE int *crash = 0; @@ -59,7 +59,7 @@ namespace omega { //} //fprintf(stderr, "subbing '%s' in statement ", oldvar); n->print(0, stderr); fprintf(stderr, "\n"); - chillAST_node *r = n; + chillAST_Node *r = n; if (n->isBinaryOperator()) {r= SubABinaryOperator(oldvar, newvar, n, parent ); } else if (n->isUnaryOperator()) {r= SubUnaryOperator(oldvar, newvar, n, parent ); } else if (n->isDeclRefExpr()) {r= SubDeclRefExpr(oldvar, newvar, n, parent ); @@ -93,7 +93,7 @@ namespace omega { } - chillAST_node *SubABinaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubABinaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { chillAST_BinaryOperator *b = (chillAST_BinaryOperator *) n; //fprintf(stderr,"SubABinaryOperator() 0x%x subbing old variable %s in \n", b, oldvar); @@ -103,8 +103,8 @@ namespace omega { // b->print(); printf("\n"); fflush(stdout); //} - chillAST_node *lhs = b->lhs; - chillAST_node *rhs = b->rhs; + chillAST_Node *lhs = b->lhs; + chillAST_Node *rhs = b->rhs; //if (!strcmp(b->op, "=") && rhs->isBinaryOperator() ) { // chillAST_BinaryOperator *r = (chillAST_BinaryOperator *) rhs; @@ -123,15 +123,15 @@ namespace omega { - chillAST_node *SubUnaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubUnaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { chillAST_UnaryOperator *u = (chillAST_UnaryOperator *) n; - chillAST_node *sub = u->subexpr; + chillAST_Node *sub = u->subexpr; u->subexpr = substituteChill( oldvar, newvar, sub, u); return u; } - chillAST_node *SubDeclRefExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubDeclRefExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { //fprintf(stderr, "SubDeclRefExpr() subbing statement of type %s\n", n->getTypeString()); chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) n; @@ -153,9 +153,9 @@ namespace omega { // //fprintf(stderr, " in statement of type %s\n",s->getTypeString()); //} - std::vector<chillAST_node*> newnodes = newvar->chillnodes; + std::vector<chillAST_Node*> newnodes = newvar->chillnodes; //fprintf(stderr, "%d nodes in newvar\n", newnodes.size()); - chillAST_node *firstn = newnodes[0]; + chillAST_Node *firstn = newnodes[0]; firstn->parent = parent; return firstn; // it's that simple! @@ -170,7 +170,7 @@ namespace omega { - chillAST_node *SubArraySubscriptExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubArraySubscriptExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { chillAST_ArraySubscriptExpr *ASE = (chillAST_ArraySubscriptExpr *) n; //fprintf(stderr, "subASE ASE 0x%x\n", ASE); @@ -178,8 +178,8 @@ namespace omega { //ASE->print(); printf("\n"); fflush(stdout); - chillAST_node *Base = ASE->base; - chillAST_node *Index = ASE->index; + chillAST_Node *Base = ASE->base; + chillAST_Node *Index = ASE->index; //fprintf(stderr, "Index is of type %s\n", Index->getTypeString()); ASE->base = substituteChill( oldvar, newvar, Base, ASE); // this should not do anything @@ -199,10 +199,10 @@ namespace omega { - chillAST_node *SubImplicitCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubImplicitCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { //fprintf(stderr, "SubImplicitCastExpr subbing statement of type %s at 0x%x parent 0x%x\n", n->getTypeString(), n, parent); chillAST_ImplicitCastExpr *IC = (chillAST_ImplicitCastExpr *) n; - chillAST_node *oldsub = IC->subexpr; + chillAST_Node *oldsub = IC->subexpr; IC->subexpr = substituteChill( oldvar, newvar, oldsub, IC); //if (oldsub != IC->subexpr) { @@ -217,7 +217,7 @@ namespace omega { return IC; } - chillAST_node *SubCStyleCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubCStyleCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { //fprintf(stderr, "SubCStyleCastExpr() subexpr is type "); chillAST_CStyleCastExpr *CSCE = (chillAST_CStyleCastExpr *) n; //fprintf(stderr, "%s\n", CSCE->subexpr->getTypeString()); @@ -226,13 +226,13 @@ namespace omega { } - chillAST_node *SubParenExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubParenExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { chillAST_ParenExpr *PE = (chillAST_ParenExpr *) n; PE->subexpr = substituteChill( oldvar, newvar, PE->subexpr, PE); return PE; } - chillAST_node *SubCallExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubCallExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { chillAST_CallExpr *CE = (chillAST_CallExpr *) n; //fprintf(stderr, "substituting for oldvar %s in ", oldvar ); @@ -247,7 +247,7 @@ namespace omega { - chillAST_node *SubReturnStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubReturnStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { //fprintf(stderr, "SubReturnStmt()\n"); chillAST_ReturnStmt *RS = (chillAST_ReturnStmt *)n; @@ -256,11 +256,11 @@ namespace omega { } - chillAST_node *SubIfStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubIfStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { //fprintf(stderr, "SubIfStmt()\n"); chillAST_IfStmt *IS = (chillAST_IfStmt *)n; //IS->print(0, stderr); fprintf(stderr, "\n\n"); - chillAST_node *sub; + chillAST_Node *sub; if ( sub = IS->getCond() ) IS->setCond( substituteChill(oldvar, newvar, sub, IS)); if ( sub = IS->getThen() ) IS->setThen( substituteChill(oldvar, newvar, sub, IS)); sub = IS->getElse(); //fprintf(stderr, "sub(else) = %p\n", sub); @@ -270,7 +270,7 @@ namespace omega { } - chillAST_node *SubCompoundStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubCompoundStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { //fprintf(stderr, "SubCompoundStmt()\n"); chillAST_CompoundStmt *CS = (chillAST_CompoundStmt *)n; @@ -284,7 +284,7 @@ namespace omega { - chillAST_node *SubMemberExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_node *n, chillAST_node *parent = NULL ) { + chillAST_Node *SubMemberExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) { //fprintf(stderr, "SubMemberExpr( oldvar %s ) \n", oldvar); chillAST_MemberExpr *ME = (chillAST_MemberExpr *)n; @@ -408,7 +408,7 @@ namespace omega { //{ - // std::vector<chillAST_node*> nodes = ((CG_chillRepr *) stmt)->getChillCode(); + // std::vector<chillAST_Node*> nodes = ((CG_chillRepr *) stmt)->getChillCode(); // // // fprintf(stderr, "%d nodes in old code. was:\n", nodes.size()); // for(int i=0; i<nodes.size(); i++) @@ -435,7 +435,7 @@ namespace omega { if (numsubs == 0) { - std::vector<chillAST_node*> nodes = ((CG_chillRepr *) stmt)->getChillCode(); + std::vector<chillAST_Node*> nodes = ((CG_chillRepr *) stmt)->getChillCode(); // //fprintf(stderr, "nosubs old code was:\n"); @@ -491,10 +491,10 @@ namespace omega { //fprintf(stderr, "OK, now to really substitute ...\n"); //CG_outputRepr *newstmt = stmt->clone(); //CG_chillRepr *n = (CG_chillRepr *) newstmt; - //vector<chillAST_node*> newnodes = n->getChillCode(); + //vector<chillAST_Node*> newnodes = n->getChillCode(); CG_chillRepr *old = (CG_chillRepr *) stmt; - std::vector<chillAST_node*> oldnodes = old->getChillCode(); + std::vector<chillAST_Node*> oldnodes = old->getChillCode(); for (int j=0; j<numsubs; j++) { @@ -506,12 +506,12 @@ namespace omega { // find the type of thing we'll be using to replace the old variable CG_chillRepr *CRSub = (CG_chillRepr *)(subs[j]); - std::vector<chillAST_node*> nodes = CRSub->chillnodes; + std::vector<chillAST_Node*> nodes = CRSub->chillnodes; if (1 != nodes.size() ) { // always just one? fprintf(stderr, "CG_chillBuilder::CreateSubstitutedStmt(), replacement is not one statement??\n"); exit(-1); } - chillAST_node *node = nodes[0]; // always just one? + chillAST_Node *node = nodes[0]; // always just one? for (int i=0; i<oldnodes.size(); i++) { //fprintf(stderr, " statement %d ", i); @@ -544,8 +544,8 @@ namespace omega { CG_chillRepr *clhs = (CG_chillRepr *) lhs; CG_chillRepr *crhs = (CG_chillRepr *) rhs; - chillAST_node *lAST = clhs->chillnodes[0]; // always just one? - chillAST_node *rAST = crhs->chillnodes[0]; // always just one? + chillAST_Node *lAST = clhs->chillnodes[0]; // always just one? + chillAST_Node *rAST = crhs->chillnodes[0]; // always just one? chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "=", rAST->clone(), NULL); // clone?? @@ -567,8 +567,8 @@ namespace omega { CG_chillRepr *clhs = (CG_chillRepr *) lhs; CG_chillRepr *crhs = (CG_chillRepr *) rhs; - chillAST_node *lAST = clhs->chillnodes[0]; // always just one? - chillAST_node *rAST = crhs->chillnodes[0]; // always just one? + chillAST_Node *lAST = clhs->chillnodes[0]; // always just one? + chillAST_Node *rAST = crhs->chillnodes[0]; // always just one? chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "+=", rAST->clone(), NULL); // clone?? @@ -610,7 +610,7 @@ namespace omega { const char *arrayname = fname.c_str(); CG_chillRepr *CR = (CG_chillRepr *) list[0]; - chillAST_node *cast = CR->GetCode(); + chillAST_Node *cast = CR->GetCode(); //fprintf(stderr, "%s[", arrayname); //cast->print(); printf("] ???\n"); fflush(stdout); @@ -652,7 +652,7 @@ namespace omega { else op = '<'; // TODO >, check number of args etc - chillAST_node *ternary = lessthanmacro( ((CG_chillRepr*) list[0])->chillnodes[0], + chillAST_Node *ternary = lessthanmacro( ((CG_chillRepr*) list[0])->chillnodes[0], ((CG_chillRepr*) list[1])->chillnodes[0]); //fprintf(stderr, "just made ternary "); @@ -675,7 +675,7 @@ namespace omega { //fprintf(stderr, "fname '%s'\n", name); chillAST_SourceFile *src = toplevel; // todo don't be dumb - chillAST_node *def = src->findCall(name); + chillAST_Node *def = src->findCall(name); if (!def) { // can't find it fprintf(stderr, "CG_chillBuilder::CreateInvoke( %s ), can't find a function or macro by that name\n", name); exit(-1); @@ -705,11 +705,11 @@ namespace omega { } - // chillAST_CallExpr::chillAST_CallExpr(chillAST_node *function, chillAST_node *p ); + // chillAST_CallExpr::chillAST_CallExpr(chillAST_Node *function, chillAST_Node *p ); // todo addarg() //int numargs; - //std::vector<class chillAST_node*> args; + //std::vector<class chillAST_Node*> args; fprintf(stderr, "Code generation: invoke function io_call not implemented\n"); return NULL; } @@ -774,12 +774,12 @@ namespace omega { return StmtListAppend(true_stmtList, false_stmtList); } - std::vector<chillAST_node*> vectorcode = static_cast<CG_chillRepr*>(guardList)->getChillCode(); + std::vector<chillAST_Node*> vectorcode = static_cast<CG_chillRepr*>(guardList)->getChillCode(); if (vectorcode.size() != 1 ) { fprintf(stderr, "CG_chillBuilder.cc IfStmt conditional is multiple statements?\n"); exit(-1); } - chillAST_node *conditional = vectorcode[0]; + chillAST_Node *conditional = vectorcode[0]; chillAST_CompoundStmt *then_part = NULL; chillAST_CompoundStmt *else_part = NULL; @@ -835,9 +835,9 @@ namespace omega { //static_cast<CG_chillRepr*>(step )->printChillNodes(); // index should be a DeclRefExpr - std::vector<chillAST_node*> nodes = static_cast<CG_chillRepr*>(index)->getChillCode(); + std::vector<chillAST_Node*> nodes = static_cast<CG_chillRepr*>(index)->getChillCode(); //fprintf(stderr, "%d index nodes\n", nodes.size()); - chillAST_node *indexnode = nodes[0]; + chillAST_Node *indexnode = nodes[0]; if (!streq("DeclRefExpr", indexnode->getTypeString())) { fprintf(stderr, "CG_chillBuilder::CreateInductive index is not a DeclRefExpr\n"); if (indexnode->isIntegerLiteral()) fprintf(stderr, "isIntegerLiteral()\n"); @@ -851,17 +851,17 @@ namespace omega { nodes = static_cast<CG_chillRepr*>(lower)->getChillCode(); //fprintf(stderr, "%d lower nodes\n", nodes.size()); - chillAST_node *lowernode = nodes[0]; + chillAST_Node *lowernode = nodes[0]; //fprintf(stderr, "lower node is %s\n", lowernode->getTypeString()); nodes = static_cast<CG_chillRepr*>(upper)->getChillCode(); //fprintf(stderr, "%d upper nodes\n", nodes.size()); - chillAST_node *uppernode = nodes[0]; + chillAST_Node *uppernode = nodes[0]; //fprintf(stderr, "upper node is %s\n", uppernode->getTypeString()); nodes = static_cast<CG_chillRepr*>(step)->getChillCode(); //fprintf(stderr, "%d step nodes\n", nodes.size()); - chillAST_node *stepnode = nodes[0]; + chillAST_Node *stepnode = nodes[0]; //fprintf(stderr, "step node is %s\n", stepnode->getTypeString()); // unclear is this will always be the same @@ -877,7 +877,7 @@ namespace omega { return new CG_chillRepr(loop); /* - //vector<chillAST_node*> indexnodes = static_cast<CG_chillRepr*>(index)->getChillCode(); + //vector<chillAST_Node*> indexnodes = static_cast<CG_chillRepr*>(index)->getChillCode(); chillAST_DeclRefExpr *index_decl Expr *lower_bound; // = static_cast<CG_chillRepr*>(lower)->getChillCode(); Expr *upper_bound; // = static_cast<CG_chillRepr*>(upper)->getChillCode(); @@ -966,10 +966,10 @@ namespace omega { } // We assume the for statement is already created (using CreateInductive) - std::vector<chillAST_node*> code = static_cast<CG_chillRepr*>(control)->getChillCode(); + std::vector<chillAST_Node*> code = static_cast<CG_chillRepr*>(control)->getChillCode(); chillAST_ForStmt *forstmt = (chillAST_ForStmt *)(code[0]); - std::vector<chillAST_node*> statements = static_cast<CG_chillRepr*>(stmtList)->getChillCode(); + std::vector<chillAST_Node*> statements = static_cast<CG_chillRepr*>(stmtList)->getChillCode(); //static_cast<CG_chillRepr*>(stmtList)->printChillNodes(); printf("\n"); fflush(stdout); chillAST_CompoundStmt *cs = new chillAST_CompoundStmt(); @@ -1027,8 +1027,8 @@ namespace omega { CG_outputRepr* CG_chillBuilder::CreateIdent(const std::string &_s) const { fprintf(stderr, "CG_chillBuilder::CreateIdent( %s )\n", _s.c_str()); - bool already_parameter = symbolTableHasVariableNamed(symtab_, _s.c_str()); - bool already_internal = symbolTableHasVariableNamed(symtab2_, _s.c_str()); + chillAST_VarDecl* already_parameter = symbolTableFindName(symtab_, _s.c_str()); + chillAST_VarDecl* already_internal = symbolTableFindName(symtab2_, _s.c_str()); if ( already_parameter ) { fprintf(stderr, "%s was already a parameter??\n", _s.c_str()); } @@ -1054,7 +1054,7 @@ namespace omega { currentfunction->addVariableToSymbolTable( vd ); // use symtab2_ ?? - chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr( "int", _s.c_str(), (chillAST_node*)vd, NULL ); // parent not available + chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr( "int", _s.c_str(), (chillAST_Node*)vd, NULL ); // parent not available //fprintf(stderr, "made a new chillRepr from "); dre->dump(); fflush(stdout); return new CG_chillRepr( dre ); } @@ -1066,7 +1066,7 @@ namespace omega { chillAST_VarDecl *vd = currentfunction->funcHasVariableNamed( _s.c_str() ); //fprintf(stderr, "vd %p\n", vd); - chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr( "int", _s.c_str(), (chillAST_node*)vd, NULL ); // parent not available + chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr( "int", _s.c_str(), (chillAST_Node*)vd, NULL ); // parent not available return new CG_chillRepr( dre ); } @@ -1085,8 +1085,8 @@ namespace omega { if(rop == NULL) return lop; // ?? else if(lop == NULL) return rop; - chillAST_node *left = ((CG_chillRepr*)lop)->chillnodes[0]; - chillAST_node *right = ((CG_chillRepr*)rop)->chillnodes[0]; + chillAST_Node *left = ((CG_chillRepr*)lop)->chillnodes[0]; + chillAST_Node *right = ((CG_chillRepr*)rop)->chillnodes[0]; chillAST_BinaryOperator *bop = new chillAST_BinaryOperator( left, "+", right, NULL ); // parent not available return new CG_chillRepr( bop ); /* @@ -1131,20 +1131,20 @@ namespace omega { if(clop == NULL) { // this is really a unary operator ??? //fprintf(stderr, "CG_chillBuilder::CreateMinus() unary\n"); - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? chillAST_UnaryOperator *ins = new chillAST_UnaryOperator("-", true, rAST->clone(), NULL); // clone? - delete crop; // ?? note: the chillRepr, not the chillAST_node + delete crop; // ?? note: the chillRepr, not the chillAST_Node return new CG_chillRepr(ins); } else { //fprintf(stderr, "binary\n"); - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? //lAST->print(); printf(" - "); //rAST->print(); printf("\n"); fflush(stdout); chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "-", rAST->clone(), NULL); // clone?? - delete clop; delete crop; // ?? note: the chillReprs, not the chillAST_nodes + delete clop; delete crop; // ?? note: the chillReprs, not the chillAST_Nodes return new CG_chillRepr(bop); } } @@ -1169,8 +1169,8 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? fprintf(stderr, "building "); lAST->print(0, stderr); @@ -1209,8 +1209,8 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? //fprintf(stderr, "building "); //lAST->print(0, stderr); @@ -1231,8 +1231,8 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? //fprintf(stderr, "building "); //lAST->print(0, stderr); @@ -1256,8 +1256,8 @@ namespace omega { CG_chillRepr *l = (CG_chillRepr *) lop; CG_chillRepr *r = (CG_chillRepr *) rop; - chillAST_node *lhs = l->GetCode(); - chillAST_node *rhs = r->GetCode(); + chillAST_Node *lhs = l->GetCode(); + chillAST_Node *rhs = r->GetCode(); chillAST_BinaryOperator *BO = new chillAST_BinaryOperator(lhs, "%", rhs ); return new CG_chillRepr(BO); @@ -1307,8 +1307,8 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? //fprintf(stderr, "building "); //lAST->print(0, stderr); @@ -1351,8 +1351,8 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? //fprintf(stderr, "building "); //lAST->print(0, stderr); @@ -1377,8 +1377,8 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? //fprintf(stderr, "building "); //lAST->print(0, stderr); @@ -1404,8 +1404,8 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? //fprintf(stderr, "building "); //lAST->print(0, stderr); @@ -1429,8 +1429,8 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_node *lAST = clop->chillnodes[0]; // always just one? - chillAST_node *rAST = crop->chillnodes[0]; // always just one? + chillAST_Node *lAST = clop->chillnodes[0]; // always just one? + chillAST_Node *rAST = crop->chillnodes[0]; // always just one? //fprintf(stderr, "left is %s, right is %s\n", lAST->getTypeString(), rAST->getTypeString()); if ( !rAST->isVarDecl()) { @@ -1459,7 +1459,7 @@ namespace omega { fprintf(stderr, "CG_chillBuilder::CreateDotExpression(), can't create base\n"); exit(-1); } - chillAST_MemberExpr *memexpr = new chillAST_MemberExpr( DRE, rvd->varname, NULL, NULL, CHILL_MEMBER_EXP_DOT ); + chillAST_MemberExpr *memexpr = new chillAST_MemberExpr( DRE, rvd->varname, NULL, NULL, CHILLAST_MEMBER_EXP_DOT ); //delete lop; delete rop; // ?? @@ -1544,16 +1544,16 @@ namespace omega { CG_outputRepr* CG_chillBuilder::CreateArrayRefExpression(CG_outputRepr*left, CG_outputRepr*right) const{ - chillAST_node *l = ((CG_chillRepr *)left)->GetCode(); - chillAST_node *r = ((CG_chillRepr *)right)->GetCode(); + chillAST_Node *l = ((CG_chillRepr *)left)->GetCode(); + chillAST_Node *r = ((CG_chillRepr *)right)->GetCode(); - chillAST_node *base = NULL; + chillAST_Node *base = NULL; if (l->isDeclRefExpr()) base = l; if (l->isMemberExpr()) base = l; if (l->isVarDecl()) { // ?? // make a declRefExpr that uses VarDecl l - base = (chillAST_node *) new chillAST_DeclRefExpr( (chillAST_VarDecl *)l ); + base = (chillAST_Node *) new chillAST_DeclRefExpr( (chillAST_VarDecl *)l ); } if (!base) { @@ -1702,7 +1702,7 @@ namespace omega { fprintf(stderr, "CG_chillBuilder::CreateClassInstance( %s )\n", name.c_str()); CG_chillRepr *CD = (CG_chillRepr *)class_def; - chillAST_node *n = CD->GetCode(); + chillAST_Node *n = CD->GetCode(); //fprintf(stderr, "class def is of type %s\n", n->getTypeString()); //n->print(); printf("\n"); fflush(stdout); @@ -1765,7 +1765,7 @@ namespace omega { chillAST_VarDecl* sub = NULL; CG_chillRepr *CR = (CG_chillRepr *)classtype; - chillAST_node *classnode = CR->GetCode(); + chillAST_Node *classnode = CR->GetCode(); //fprintf(stderr, "classnode is %s\n", classnode->getTypeString()); classnode->print(); printf("\n"); fflush(stdout); if (! ( classnode->isTypeDefDecl() || classnode->isRecordDecl() )) { @@ -1776,7 +1776,7 @@ namespace omega { CG_chillRepr *CI = (CG_chillRepr *)instance; - chillAST_node *in = CI->GetCode(); + chillAST_Node *in = CI->GetCode(); //fprintf(stderr, "instance is %s\n", in->getTypeString()); //in->print(); printf("\n"); fflush(stdout); diff --git a/lib/chillcg/src/CG_chillRepr.cc b/lib/chillcg/src/CG_chillRepr.cc index 0fd72a5..a47ecbc 100755 --- a/lib/chillcg/src/CG_chillRepr.cc +++ b/lib/chillcg/src/CG_chillRepr.cc @@ -30,7 +30,7 @@ namespace omega { //} - chillAST_node * CG_chillRepr::GetCode() { + chillAST_Node * CG_chillRepr::GetCode() { //fprintf(stderr, "CG_chillRepr::GetCode() this %p size %d\n", this, chillnodes.size()); if (0 == chillnodes.size()) return NULL; // error? diff --git a/src/chillASTs.cc b/src/chillASTs.cc index c73eb98..5b8e1e8 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -6,11 +6,11 @@ using namespace std; -int chillAST_node::chill_scalar_counter = 0; -int chillAST_node::chill_array_counter = 1; +int chillAST_Node::chill_scalar_counter = 0; +int chillAST_Node::chill_array_counter = 1; -const char *Chill_AST_Node_Names[] = { +const char *ChillAST_Node_Names[] = { "Unknown AST node type", "SourceFile", "TypedefDecl", @@ -54,24 +54,30 @@ const char *Chill_AST_Node_Names[] = { char *parseUnderlyingType(char *sometype) { int len = strlen(sometype); - //fprintf(stderr, "parseUnderlyingType( %s )\n", sometype); + CHILL_DEBUG_PRINT("parseUnderlyingType( %s )\n", sometype); char *underlying = strdup(sometype); char *p; char *start = underlying; // ugly. we want to turn "float *" into "float" but "struct abc *" into struct abc. - // there are probably many more cases. have an approved list? TODO - if (strstr(underlying, "struct ")) start += 7; // (length("struct ")) - //fprintf(stderr, "sometype '%s' start '%s'\n", sometype, start); - if (p = index(start, ' ')) *p = '\0'; // end at first space leak - if (p = index(start, '[')) *p = '\0'; // leak - if (p = index(start, '*')) *p = '\0'; // leak + // there are probably many more cases. have an approved list? + p = &underlying[len - 1]; + + while (p > underlying) + if (*p == ' ' || *p == '*') + --p; + else if (*p == ']') + // TODO This can be improved by using a stack + while (*p != '[') --p; + else break; + + *p = '\0'; return underlying; } void printSymbolTable(chillAST_SymbolTable *st) { - //printf("%d entries\n", st->size()); + CHILL_DEBUG_PRINT("%d entries\n", st->size()); if (!st) return; for (int i = 0; i < st->size(); i++) { printf("%d ", i); @@ -83,7 +89,7 @@ void printSymbolTable(chillAST_SymbolTable *st) { } void printSymbolTableMoreInfo(chillAST_SymbolTable *st) { - //printf("%d entries\n", st->size()); + CHILL_DEBUG_PRINT("%d entries\n", st->size()); if (!st) return; for (int i = 0; i < st->size(); i++) { printf("%d ", i); @@ -94,140 +100,104 @@ void printSymbolTableMoreInfo(chillAST_SymbolTable *st) { fflush(stdout); } +char *splitVariableName(char *name) { + char *cdot = strstr(name, "."); + char *carrow = strstr(name, "->"); // initial 'c' for const - can't change those -bool symbolTableHasVariableNamed(chillAST_SymbolTable *table, const char *name) { - if (!table) return false; // ?? - int numvars = table->size(); - for (int i = 0; i < numvars; i++) { - chillAST_VarDecl *vd = (*table)[i]; - if (!strcmp(name, vd->varname)) return true; // need to check type? + int pos = INT16_MAX, pend; + + if (cdot) pend = pos = (int) (cdot - name); + if (carrow) { + pos = min(pos, (int) (carrow - name)); + pend = pos + 1; } - return false; -} + if (pos == INT16_MAX) + return NULL; -chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, - const char *name) { // fwd decl TODO too many similar named functions - if (!table) return NULL; // ?? + name[pos] = '\0'; + return &name[pend + 1]; - // see if name has a dot or arrow (->) indicating that it is a structure/class - const char *cdot = strstr(name, "."); - const char *carrow = strstr(name, "->"); // initial 'c' for const - can't change those +} - char *varname; - char *subpart = NULL; +chillAST_VarDecl *symbolTableFindName(chillAST_SymbolTable *table, const char *name) { + if (!table) return NULL; + int numvars = table->size(); + for (int i = 0; i < numvars; i++) { + chillAST_VarDecl *vd = (*table)[i]; + if (!strcmp(name, vd->varname)) return vd; + } + return NULL; +} - if (cdot || carrow) { - fprintf(stderr, "symbolTableFindVariableNamed(), name '%s' looks like a struct\n", name); +chillAST_VarDecl *variableDeclFindSubpart(chillAST_VarDecl *decl, const char *name) { + char *varname = strdup(name), *subpart; - // so, look for the first part in the symbol table. - // warning, this could be looking for a->b.c.d->e.f->g - varname = strdup(name); + subpart = splitVariableName(varname); - char *dot = strstr(varname, "."); - char *arrow = strstr(varname, "->"); - if (dot != NULL && arrow != NULL) { // dot AND arrow, - fprintf(stderr, "chillast.cc symbolTableFindVariableNamed(), name '%s' has both dot and arrow? TODO\n"); - exit(-1); - } else if (dot != NULL && !arrow) { // just dot(s). dot points to the first one - //fprintf(stderr, "name '%s' has dot(s)\n", varname); - *dot = '\0'; // end string at the dot - subpart = &(dot[1]); - fprintf(stderr, "will now look for a struct/class named %s that has member %s\n", varname, subpart); - - } else if (arrow != NULL && !dot) { // just arrow(s) arrow points to the first one - //fprintf(stderr, "name '%s' has arrow(s)\n", varname); - *arrow = '\0'; // end string at the arrow - subpart = &(arrow[2]); - fprintf(stderr, "will now look for a struct/class named %s that has member %s\n", varname, subpart); - } else { // impossible - fprintf(stderr, - "chillast.cc symbolTableFindVariableNamed(), varname '%s', looks like a struct, but I can't figure it out\n", - varname); - exit(-1); + if (decl->isAStruct()) { + CHILL_DEBUG_PRINT("Finding %s in a struct of type %s\n", varname, decl->getTypeString()); + if (decl->isVarDecl()) { + chillAST_RecordDecl *rd = decl->getStructDef(); + if (rd) { + chillAST_VarDecl *sp = rd->findSubpart(varname); + if (sp) CHILL_DEBUG_PRINT("found a struct member named %s\n", varname); + else + CHILL_DEBUG_PRINT("DIDN'T FIND a struct member named %s\n", varname); + if (!subpart) + return sp; + return variableDeclFindSubpart(sp,subpart); // return the subpart?? + } else { + CHILL_ERROR("no recordDecl\n"); + exit(-1); + } + } else { + CHILL_ERROR("NOT a VarDecl???\n"); // impossible } } else { - varname = strdup(name); + fprintf(stderr, "false alarm. %s is a variable, but doesn't have subparts\n", varname); + return NULL; } +} - int numvars = table->size(); - for (int i = 0; i < numvars; i++) { - chillAST_VarDecl *vd = (*table)[i]; - if (!strcmp(varname, vd->varname)) { - fprintf(stderr, "found variable named %s\n", varname); - - if (!subpart) return vd; // need to check type? - - // OK, we have a variable, which looks like a struct/class, and a subpart that is some member names - //fprintf(stderr, "but I don't know how to check if it has member %s\n", subpart); - - char *dot = strstr(subpart, "."); - char *arrow = strstr(subpart, "->"); - - if (!dot && !arrow) { // whew, only one level of struct - //fprintf(stderr, "whew, only one level of struct\n"); - - // make sure this variable definition is a struct - if (vd->isAStruct()) { - //fprintf(stderr, "%s is a struct of type %s\n", varname, vd->getTypeString()); - if (vd->isVarDecl()) { - chillAST_RecordDecl *rd = vd->getStructDef(); - if (rd) { - //fprintf(stderr, "has a recordDecl\n"); - - chillAST_VarDecl *sp = rd->findSubpart(subpart); - if (sp) fprintf(stderr, "found a struct member named %s\n", subpart); - else fprintf(stderr, "DIDN'T FIND a struct member named %s\n", subpart); - return sp; // return the subpart?? - } else { - fprintf(stderr, "no recordDecl\n"); - exit(-1); - } - } else { - fprintf(stderr, "NOT a VarDecl???\n"); // impossible - } - } else { - fprintf(stderr, "false alarm. %s is a variable, but doesn't have subparts\n", varname); - return NULL; // false alarm. a variable of the correct name exists, but is not a struct - } - } +chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, + const char *name) { // fwd decl TODO too many similar named functions + if (!table) return NULL; // ?? - fprintf(stderr, - "chillast.cc symbolTableFindVariableNamed(), name '%s' can't figure out multiple levels of struct yet!\n"); + char *varname = strdup(name), *subpart; - exit(-1); - } - } - return NULL; -} + subpart = splitVariableName(varname); + chillAST_VarDecl *vd = symbolTableFindName(table, varname); -char *ulhack(char *brackets) // remove UL from numbers, MODIFIES the argument! + if (!subpart) + return vd; + return variableDeclFindSubpart(vd,subpart); +} + +//! remove UL from numbers, MODIFIES the argument! +char *ulhack(char *brackets) { - //fprintf(stderr, "ulhack( \"%s\" -> ", brackets); - // another hack. remove "UL" from integers + CHILL_DEBUG_PRINT("ulhack( \"%s\" -> ", brackets); int len = strlen(brackets); for (int i = 0; i < len - 2; i++) { if (isdigit(brackets[i])) { - if (brackets[i + 1] == 'U' && brackets[i + 2] == 'L') { - // remove + if (brackets[i + 1] == 'U' && brackets[i + 2] == 'L') { // remove for (int j = i + 3; j < len; j++) brackets[j - 2] = brackets[j]; len -= 2; brackets[len] = '\0'; } } } - //fprintf(stderr, "\"%s\" )\n", brackets); + CHILL_DEBUG_PRINT("%s", brackets); return brackets; } -char *restricthack(char *typeinfo) // remove __restrict__ , MODIFIES the argument! +//! remove __restrict__ , MODIFIES the argument! +char *restricthack(char *typeinfo) { - //if (!isRestrict( typeinfo )) return typeinfo; - - // there is a "__restrict__ " somewhere embedded. remove it. - // duplicate work + CHILL_DEBUG_PRINT("restricthack( \"%s\" -> ", typeinfo); std::string r("__restrict__"); std::string t(typeinfo); size_t index = t.find(r); @@ -238,16 +208,15 @@ char *restricthack(char *typeinfo) // remove __restrict__ , MODIFIES the argumen char *after = c + 12; if (*after == ' ') after++; - //fprintf(stderr, "after = '%s'\n", after); - while (*after != '\0') *c++ = *after++; *c = '\0'; + CHILL_DEBUG_PRINT("%s", typeinfo); return typeinfo; } - +// TODO DOC char *parseArrayParts(char *sometype) { int len = strlen(sometype); char *arraypart = (char *) calloc(1 + strlen(sometype), sizeof(char));// leak @@ -266,7 +235,7 @@ char *parseArrayParts(char *sometype) { ulhack(arraypart); restricthack(arraypart); - //fprintf(stderr, "parseArrayParts( %s ) => %s\n", sometype, arraypart); + CHILL_DEBUG_PRINT("parseArrayParts( %s ) => %s\n", sometype, arraypart); return arraypart; } @@ -305,7 +274,7 @@ bool streq(const char *a, const char *b) { return !strcmp(a, b); }; // slightly void chillindent(int howfar, FILE *fp) { for (int i = 0; i < howfar; i++) fprintf(fp, " "); } -chillAST_VarDecl *chillAST_node::findVariableNamed(const char *name) { // generic, recursive +chillAST_VarDecl *chillAST_Node::findVariableNamed(const char *name) { // generic, recursive fprintf(stderr, "nodetype %s findVariableNamed( %s )\n", getTypeString(), name); if (hasSymbolTable()) { // look in my symbol table if I have one fprintf(stderr, "%s has a symbol table\n", getTypeString()); @@ -327,7 +296,7 @@ chillAST_VarDecl *chillAST_node::findVariableNamed(const char *name) { // generi } -chillAST_RecordDecl *chillAST_node::findRecordDeclNamed(const char *name) { // recursive +chillAST_RecordDecl *chillAST_Node::findRecordDeclNamed(const char *name) { // recursive fprintf(stderr, "%s::findRecordDeclNamed( %s )\n", getTypeString(), name); // look in children int numchildren = children.size(); @@ -350,27 +319,27 @@ chillAST_RecordDecl *chillAST_node::findRecordDeclNamed(const char *name) { // r } -void chillAST_node::printPreprocBEFORE(int indent, FILE *fp) { +void chillAST_Node::printPreprocBEFORE(int indent, FILE *fp) { int numstmts = preprocessinginfo.size(); //if (0 != numstmts) { - // fprintf(fp, "chillAST_node::printPreprocBEFORE() %d statements\n", numstmts); + // fprintf(fp, "chillAST_Node::printPreprocBEFORE() %d statements\n", numstmts); //} for (int i = 0; i < numstmts; i++) { //fprintf(fp, "stmt %d %d\n", i, preprocessinginfo[i]->position); - if (preprocessinginfo[i]->position == CHILL_PREPROCESSING_LINEBEFORE || - preprocessinginfo[i]->position == CHILL_PREPROCESSING_IMMEDIATELYBEFORE) { + if (preprocessinginfo[i]->position == CHILLAST_PREPROCESSING_LINEBEFORE || + preprocessinginfo[i]->position == CHILLAST_PREPROCESSING_IMMEDIATELYBEFORE) { //fprintf(stderr, "before %d\n", preprocessinginfo[i]->position); preprocessinginfo[i]->print(indent, fp); } } } -void chillAST_node::printPreprocAFTER(int indent, FILE *fp) { +void chillAST_Node::printPreprocAFTER(int indent, FILE *fp) { for (int i = 0; i < preprocessinginfo.size(); i++) { - if (preprocessinginfo[i]->position == CHILL_PREPROCESSING_LINEAFTER || - preprocessinginfo[i]->position == CHILL_PREPROCESSING_TOTHERIGHT) { + if (preprocessinginfo[i]->position == CHILLAST_PREPROCESSING_LINEAFTER || + preprocessinginfo[i]->position == CHILLAST_PREPROCESSING_TOTHERIGHT) { //fprintf(stderr, "after %d\n", preprocessinginfo[i]->position); preprocessinginfo[i]->print(indent, fp); } @@ -378,9 +347,8 @@ void chillAST_node::printPreprocAFTER(int indent, FILE *fp) { } -chillAST_SourceFile::chillAST_SourceFile::chillAST_SourceFile() { +chillAST_SourceFile::chillAST_SourceFile() { SourceFileName = strdup("No Source File"); - asttype = CHILLAST_NODETYPE_SOURCEFILE; parent = NULL; // top node metacomment = NULL; global_symbol_table = NULL; @@ -393,7 +361,6 @@ chillAST_SourceFile::chillAST_SourceFile::chillAST_SourceFile() { chillAST_SourceFile::chillAST_SourceFile(const char *filename) { SourceFileName = strdup(filename); - asttype = CHILLAST_NODETYPE_SOURCEFILE; parent = NULL; // top node metacomment = NULL; global_symbol_table = NULL; @@ -539,9 +506,9 @@ chillAST_FunctionDecl *chillAST_SourceFile::findFunction(const char *name) { } -chillAST_node *chillAST_SourceFile::findCall(const char *name) { +chillAST_Node *chillAST_SourceFile::findCall(const char *name) { chillAST_MacroDefinition *macro = findMacro(name); - if (macro) return (chillAST_node *) macro; + if (macro) return (chillAST_Node *) macro; chillAST_FunctionDecl *func = findFunction(name); return func; } @@ -579,7 +546,6 @@ chillAST_VarDecl *chillAST_SourceFile::findVariableNamed(const char *name) { chillAST_TypedefDecl::chillAST_TypedefDecl() { underlyingtype = newtype = arraypart = NULL; - asttype = CHILLAST_NODETYPE_TYPEDEFDECL; parent = NULL; metacomment = NULL; isStruct = isUnion = false; @@ -590,12 +556,11 @@ chillAST_TypedefDecl::chillAST_TypedefDecl() { }; -chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt, chillAST_node *par) { +chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt, chillAST_Node *par) { //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s, newtype %s )\n", t, nt); underlyingtype = strdup(t); newtype = strdup(nt); arraypart = NULL; - asttype = CHILLAST_NODETYPE_TYPEDEFDECL; parent = NULL; metacomment = NULL; isStruct = isUnion = false; @@ -606,7 +571,7 @@ chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt, chillAST_nod }; -chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chillAST_node *par) { +chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chillAST_Node *par) { underlyingtype = strdup(t); //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s )\n", underlyingtype); newtype = strdup(a); // the new named type ?? @@ -614,7 +579,6 @@ chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chil arraypart = strdup(p); // array (p)art? // splitarraypart(); // TODO - asttype = CHILLAST_NODETYPE_TYPEDEFDECL; parent = par; metacomment = NULL; isStruct = isUnion = false; @@ -699,7 +663,6 @@ chillAST_RecordDecl *chillAST_TypedefDecl::getStructDef() { chillAST_RecordDecl::chillAST_RecordDecl() { - asttype = CHILLAST_NODETYPE_RECORDDECL; name = strdup("unknown"); // ?? originalname = NULL; // ?? isStruct = isUnion = false; @@ -708,9 +671,8 @@ chillAST_RecordDecl::chillAST_RecordDecl() { filename = NULL; } -chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, chillAST_node *p) { +chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, chillAST_Node *p) { //fprintf(stderr, "chillAST_RecordDecl::chillAST_RecordDecl()\n"); - asttype = CHILLAST_NODETYPE_RECORDDECL; parent = p; if (nam) name = strdup(nam); else name = strdup("unknown"); // ?? @@ -720,9 +682,8 @@ chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, chillAST_node *p) { filename = NULL; } -chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, const char *orig, chillAST_node *p) { +chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, const char *orig, chillAST_Node *p) { fprintf(stderr, "chillAST_RecordDecl::chillAST_RecordDecl( %s, ( AKA %s ) )\n", nam, orig); - asttype = CHILLAST_NODETYPE_RECORDDECL; parent = p; if (p) p->addChild(this); @@ -833,7 +794,6 @@ void chillAST_RecordDecl::dump(int indent, FILE *fp) { chillAST_FunctionDecl::chillAST_FunctionDecl() { functionName = strdup("YouScrewedUp"); - asttype = CHILLAST_NODETYPE_FUNCTIONDECL; forwarddecl = externfunc = builtin = false; uniquePtr = (void *) NULL; this->setFunctionCPU(); @@ -847,14 +807,13 @@ chillAST_FunctionDecl::chillAST_FunctionDecl() { }; -chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *par) { +chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_Node *par) { returnType = strdup(rt); functionName = strdup(fname); this->setFunctionCPU(); //fprintf(stderr, "functionName %s\n", functionName); forwarddecl = externfunc = builtin = false; - asttype = CHILLAST_NODETYPE_FUNCTIONDECL; parent = par; metacomment = NULL; if (par) par->getSourceFile()->addFunc(this); @@ -866,7 +825,7 @@ chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, }; -chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *par, void *unique) { +chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_Node *par, void *unique) { CHILL_DEBUG_PRINT("chillAST_FunctionDecl::chillAST_FunctionDecl with unique %p\n", unique); returnType = strdup(rt); functionName = strdup(fname); @@ -875,7 +834,6 @@ chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, forwarddecl = externfunc = builtin = false; body = new chillAST_CompoundStmt(); - asttype = CHILLAST_NODETYPE_FUNCTIONDECL; uniquePtr = unique; // a quick way to check equivalence. DO NOT ACCESS THROUGH THIS parent = par; metacomment = NULL; @@ -891,7 +849,7 @@ void chillAST_FunctionDecl::addParameter(chillAST_VarDecl *p) { CHILL_DEBUG_PRINT("%s chillAST_FunctionDecl::addParameter( 0x%x param %s) total of %d parameters\n", functionName, p, p->varname, 1 + parameters.size()); - if (symbolTableHasVariableNamed(¶meters, p->varname)) { // NOT recursive. just in FunctionDecl + if (symbolTableFindName(¶meters, p->varname)) { // NOT recursive. just in FunctionDecl CHILL_DEBUG_PRINT("chillAST_FunctionDecl::addParameter( %s ), parameter already exists?\n", p->varname); // exit(-1); // ?? return; // error? @@ -971,7 +929,7 @@ chillAST_VarDecl *chillAST_FunctionDecl::funcHasVariableNamed(const char *name) } -void chillAST_FunctionDecl::setBody(chillAST_node *bod) { +void chillAST_FunctionDecl::setBody(chillAST_Node *bod) { //fprintf(stderr, "%s chillAST_FunctionDecl::setBody( 0x%x ) total of %d children\n", functionName, bod, 1+children.size()); if (bod->isCompoundStmt()) body = (chillAST_CompoundStmt *) bod; else { @@ -984,7 +942,7 @@ void chillAST_FunctionDecl::setBody(chillAST_node *bod) { } -void chillAST_FunctionDecl::insertChild(int i, chillAST_node *node) { +void chillAST_FunctionDecl::insertChild(int i, chillAST_Node *node) { fprintf(stderr, "chillAST_FunctionDecl::insertChild() "); node->print(0, stderr); fprintf(stderr, "\n\n"); @@ -1004,7 +962,7 @@ void chillAST_FunctionDecl::insertChild(int i, chillAST_node *node) { } } -void chillAST_FunctionDecl::addChild(chillAST_node *node) { +void chillAST_FunctionDecl::addChild(chillAST_Node *node) { CHILL_DEBUG_BEGIN node->print(0, stderr); fprintf(stderr, "\n\n"); @@ -1045,7 +1003,7 @@ void chillAST_FunctionDecl::print(int indent, FILE *fp) { if (externfunc) fprintf(fp, "extern "); - if (function_type == CHILL_FUNCTION_GPU) fprintf(fp, "__global__ "); + if (function_type == CHILLAST_FUNCTION_GPU) fprintf(fp, "__global__ "); fprintf(fp, "%s %s", returnType, functionName); printParameterTypes(fp); @@ -1227,7 +1185,7 @@ void chillAST_FunctionDecl::cleanUpVarDecls() { //fprintf(stderr, "deleting %d vardecls\n", deletethese.size()); for (int i = 0; i < deletethese.size(); i++) { //fprintf(stderr, "deleting varDecl %s\n", deletethese[i]->varname); - chillAST_node *par = deletethese[i]->parent; + chillAST_Node *par = deletethese[i]->parent; par->removeChild(par->findChild(deletethese[i])); } @@ -1264,7 +1222,7 @@ bool chillAST_FunctionDecl::findLoopIndexesToReplace(chillAST_SymbolTable *symta } -chillAST_node *chillAST_FunctionDecl::constantFold() { +chillAST_Node *chillAST_FunctionDecl::constantFold() { //fprintf(stderr, "chillAST_FunctionDecl::constantFold()\n"); // parameters can't have constants? int numparameters = parameters.size(); @@ -1279,7 +1237,6 @@ chillAST_node *chillAST_FunctionDecl::constantFold() { chillAST_MacroDefinition::chillAST_MacroDefinition() { macroName = strdup("UNDEFINEDMACRO"); rhsString = NULL; - asttype = CHILLAST_NODETYPE_MACRODEFINITION; parent = NULL; metacomment = NULL; symbol_table = NULL; @@ -1289,10 +1246,9 @@ chillAST_MacroDefinition::chillAST_MacroDefinition() { }; -chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_node *par) { +chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_Node *par) { macroName = strdup(mname); rhsString = NULL; - asttype = CHILLAST_NODETYPE_MACRODEFINITION; parent = par; metacomment = NULL; symbol_table = NULL; @@ -1308,10 +1264,9 @@ chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_n }; -chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char *rhs, chillAST_node *par) { +chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char *rhs, chillAST_Node *par) { macroName = strdup(mname); rhsString = strdup(rhs); - asttype = CHILLAST_NODETYPE_MACRODEFINITION; parent = par; metacomment = NULL; symbol_table = NULL; @@ -1326,7 +1281,7 @@ chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char }; -chillAST_node *chillAST_MacroDefinition::clone() { +chillAST_Node *chillAST_MacroDefinition::clone() { // TODO ?? cloning a macro makes no sense return this; @@ -1342,7 +1297,7 @@ chillAST_node *chillAST_MacroDefinition::clone() { } -void chillAST_MacroDefinition::setBody(chillAST_node *bod) { +void chillAST_MacroDefinition::setBody(chillAST_Node *bod) { fprintf(stderr, "%s chillAST_MacroDefinition::setBody( 0x%x )\n", macroName, bod); body = bod; fprintf(stderr, "body is:\n"); @@ -1373,11 +1328,11 @@ chillAST_VarDecl *chillAST_MacroDefinition::hasParameterNamed(const char *name) } -void chillAST_MacroDefinition::insertChild(int i, chillAST_node *node) { +void chillAST_MacroDefinition::insertChild(int i, chillAST_Node *node) { body->insertChild(i, node); } -void chillAST_MacroDefinition::addChild(chillAST_node *node) { +void chillAST_MacroDefinition::addChild(chillAST_Node *node) { body->addChild(node); node->parent = this; // this, or body?? } @@ -1425,7 +1380,6 @@ chillAST_ForStmt::chillAST_ForStmt() { init = cond = incr = NULL; body = new chillAST_CompoundStmt(); - asttype = CHILLAST_NODETYPE_LOOP; // breaking with tradition, this was CHILL_AST_FORSTMT conditionoperator = IR_COND_UNKNOWN; parent = NULL; metacomment = NULL; @@ -1435,8 +1389,8 @@ chillAST_ForStmt::chillAST_ForStmt() { } -chillAST_ForStmt::chillAST_ForStmt(chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, - chillAST_node *par) { +chillAST_ForStmt::chillAST_ForStmt(chillAST_Node *ini, chillAST_Node *con, chillAST_Node *inc, chillAST_Node *bod, + chillAST_Node *par) { parent = par; metacomment = NULL; init = ini; @@ -1451,8 +1405,6 @@ chillAST_ForStmt::chillAST_ForStmt(chillAST_node *ini, chillAST_node *con, chill if (body) body->setParent(this); // not sure this should be legal - asttype = CHILLAST_NODETYPE_LOOP; // breaking with tradition, this was CHILL_AST_FORSTMT - if (!cond->isBinaryOperator()) { fprintf(stderr, "ForStmt conditional is of type %s. Expecting a BinaryOperator\n", cond->getTypeString()); exit(-1); @@ -1583,10 +1535,10 @@ void chillAST_ForStmt::print(int indent, FILE *fp) { // A forstmt with compounds inside compounds ??? // this should probably all go away - chillAST_node *b = body; + chillAST_Node *b = body; //fprintf(fp, "b children %d\n", b->getNumChildren()); //fprintf(fp, "body child 0 of type %s\n", b->children[0]->getTypeString()); - //fprintf(stderr, "forstmt body type %s\n", Chill_AST_Node_Names[b->asttype] ); + //fprintf(stderr, "forstmt body type %s\n", Chill_AST_Node_Names[b->getType()] ); // deal with a tree of compound statements, in an ugly way. leave the ugliness while (1 == b->getNumChildren() && b->children[0]->isCompoundStmt()) { b = b->children[0]; @@ -1607,7 +1559,7 @@ void chillAST_ForStmt::print(int indent, FILE *fp) { b->print(indent + 1, fp); // I think this can't happen any more. body is always a compound statement - if (b->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) { // a single assignment statement + if (b->getType() == CHILLAST_NODE_BINARYOPERATOR) { // a single assignment statement fprintf(fp, ";\n"); } @@ -1636,7 +1588,7 @@ void chillAST_ForStmt::dump(int indent, FILE *fp) { fprintf(fp, ")\n"); } -chillAST_node *chillAST_ForStmt::constantFold() { +chillAST_Node *chillAST_ForStmt::constantFold() { init = init->constantFold(); cond = cond->constantFold(); incr = incr->constantFold(); @@ -1645,7 +1597,7 @@ chillAST_node *chillAST_ForStmt::constantFold() { } -chillAST_node *chillAST_ForStmt::clone() { +chillAST_Node *chillAST_ForStmt::clone() { chillAST_ForStmt *fs = new chillAST_ForStmt(init->clone(), cond->clone(), incr->clone(), body->clone(), parent); fs->isFromSourceFile = isFromSourceFile; if (filename) fs->filename = strdup(filename); @@ -1708,7 +1660,7 @@ void chillAST_ForStmt::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { body->gatherVarUsage(decls); } -void chillAST_ForStmt::gatherStatements(std::vector<chillAST_node *> &statements) { +void chillAST_ForStmt::gatherStatements(std::vector<chillAST_Node *> &statements) { // for completeness, should do all 4. Maybe someday //init->gatherStatements( statements ); @@ -1743,7 +1695,7 @@ void chillAST_ForStmt::addSyncs() { if (parent->isCompoundStmt()) { //fprintf(stderr, "ForStmt parent is CompoundStmt 0x%x\n", parent); - vector<chillAST_node *> chillin = parent->getChildren(); + vector<chillAST_Node *> chillin = parent->getChildren(); int numc = chillin.size(); //fprintf(stderr, "ForStmt parent is CompoundStmt 0x%x with %d children\n", parent, numc); for (int i = 0; i < numc; i++) { @@ -1869,7 +1821,7 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo // find parent of the ForStmt? // find parent^n of the ForStmt that is not a Forstmt? // find parent^n of the Forstmt that is a FunctionDecl? - chillAST_node *contain = findContainingNonLoop(); + chillAST_Node *contain = findContainingNonLoop(); if (contain == NULL) { fprintf(stderr, "nothing but loops all the way up?\n"); exit(0); @@ -1880,7 +1832,7 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo contain->insertChild(0, newguy); // ugly order TODO contain->addVariableToSymbolTable(newguy); // adds to first enclosing symbolTable - if (!symbolTableHasVariableNamed(contain->getSymbolTable(), vname)) { + if (!symbolTableFindName(contain->getSymbolTable(), vname)) { fprintf(stderr, "container doesn't have a var names %s afterwards???\n", vname); exit(-1); } @@ -1932,7 +1884,7 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo return force; } -void chillAST_ForStmt::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_ForStmt::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr, "chillAST_ForStmt::replaceChild() REALLY CALLING BODY->ReplaceCHILD\n"); body->replaceChild(old, newchild); } @@ -2053,7 +2005,7 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) { fprintf(stderr, "chill_ast.cc multiple loop variables confuses me\n"); exit(-1); } - chillAST_node *newstmt = body; + chillAST_Node *newstmt = body; // ACTUALLY, if I am being replaced, and my loop conditional is a min (Ternary), then wrap my loop body in an if statement if (cond->isBinaryOperator()) { // what else could it be? @@ -2067,14 +2019,14 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) { C->print(); printf("\n"); fflush(stdout); - chillAST_node *l = C->lhs; + chillAST_Node *l = C->lhs; if (l->isParenExpr()) l = ((chillAST_ParenExpr *) l)->subexpr; - chillAST_node *r = C->rhs; + chillAST_Node *r = C->rhs; if (r->isParenExpr()) r = ((chillAST_ParenExpr *) r)->subexpr; //fprintf(stderr, "lhs is %s rhs is %s\n", l->getTypeString(), r->getTypeString()); - chillAST_node *ifcondrhs = NULL; + chillAST_Node *ifcondrhs = NULL; if (!(l->isConstant())) ifcondrhs = l; else if (!(r->isConstant())) ifcondrhs = r; else { @@ -2110,14 +2062,13 @@ chillAST_BinaryOperator::chillAST_BinaryOperator() { CHILL_DEBUG_PRINT("no parent\n"); lhs = rhs = NULL; op = NULL; - asttype = CHILLAST_NODETYPE_BINARYOPERATOR; isFromSourceFile = true; // default filename = NULL; } -chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_node *l, const char *oper, chillAST_node *r, - chillAST_node *par) { +chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_Node *l, const char *oper, chillAST_Node *r, + chillAST_Node *par) { //fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator( l %p %s r %p, parent %p) this %p\n", l, oper, r, par, this); CHILL_DEBUG_PRINT("( l %s r )\n", oper); @@ -2132,7 +2083,6 @@ chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_node *l, const char *o if (lhs) lhs->setParent(this); if (rhs) rhs->setParent(this); // may only have part of the lhs and rhs when binop is created op = strdup(oper); - asttype = CHILLAST_NODETYPE_BINARYOPERATOR; // if this writes to lhs and lhs type has an 'imwrittento' concept, set that up if (isAssignmentOp()) { @@ -2278,14 +2228,14 @@ void chillAST_BinaryOperator::printonly(int indent, FILE *fp) { } -class chillAST_node *chillAST_BinaryOperator::constantFold() { +class chillAST_Node *chillAST_BinaryOperator::constantFold() { //fprintf(stderr, "\nchillAST_BinaryOperator::constantFold() "); //print(0,stderr); fprintf(stderr, "\n"); lhs = lhs->constantFold(); rhs = rhs->constantFold(); - chillAST_node *returnval = this; + chillAST_Node *returnval = this; if (lhs->isConstant() && rhs->isConstant()) { //fprintf(stderr, "binop folding constants\n"); print(0,stderr); fprintf(stderr, "\n"); @@ -2340,11 +2290,11 @@ class chillAST_node *chillAST_BinaryOperator::constantFold() { } -class chillAST_node *chillAST_BinaryOperator::clone() { +class chillAST_Node *chillAST_BinaryOperator::clone() { //fprintf(stderr, "chillAST_BinaryOperator::clone() "); print(); printf("\n"); fflush(stdout); - chillAST_node *l = lhs->clone(); - chillAST_node *r = rhs->clone(); + chillAST_Node *l = lhs->clone(); + chillAST_Node *r = rhs->clone(); chillAST_BinaryOperator *bo = new chillAST_BinaryOperator(l, op, r, parent); l->setParent(bo); r->setParent(bo); @@ -2389,7 +2339,7 @@ void chillAST_BinaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr } -void chillAST_BinaryOperator::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_BinaryOperator::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr, "\nbinop::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs); // will pointers match?? @@ -2443,7 +2393,7 @@ void chillAST_BinaryOperator::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> } -void chillAST_BinaryOperator::gatherStatements(std::vector<chillAST_node *> &statements) { +void chillAST_BinaryOperator::gatherStatements(std::vector<chillAST_Node *> &statements) { // what's legit? if (isAssignmentOp()) { @@ -2477,7 +2427,7 @@ void chillAST_BinaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAS } -bool chillAST_BinaryOperator::isSameAs(chillAST_node *other) { +bool chillAST_BinaryOperator::isSameAs(chillAST_Node *other) { if (!other->isBinaryOperator()) return false; chillAST_BinaryOperator *o = (chillAST_BinaryOperator *) other; if (strcmp(op, o->op)) return false; // different operators @@ -2488,13 +2438,12 @@ bool chillAST_BinaryOperator::isSameAs(chillAST_node *other) { chillAST_TernaryOperator::chillAST_TernaryOperator() { op = strdup("?"); // the only one so far condition = lhs = rhs = NULL; - asttype = CHILLAST_NODETYPE_TERNARYOPERATOR; isFromSourceFile = true; // default filename = NULL; } -chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_node *c, chillAST_node *l, - chillAST_node *r, chillAST_node *par) { +chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_Node *c, chillAST_Node *l, + chillAST_Node *r, chillAST_Node *par) { op = strdup(oper); condition = c; @@ -2503,7 +2452,6 @@ chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_no lhs->setParent(this); rhs = r; rhs->setParent(this); - asttype = CHILLAST_NODETYPE_TERNARYOPERATOR; isFromSourceFile = true; // default filename = NULL; } @@ -2532,7 +2480,7 @@ void chillAST_TernaryOperator::print(int indent, FILE *fp) { fflush(fp); } -void chillAST_TernaryOperator::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_TernaryOperator::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr, "\nbinop::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs); // will pointers match?? @@ -2601,12 +2549,12 @@ void chillAST_TernaryOperator::printonly(int indent, FILE *fp) { } -class chillAST_node *chillAST_TernaryOperator::constantFold() { +class chillAST_Node *chillAST_TernaryOperator::constantFold() { condition = condition->constantFold(); lhs = lhs->constantFold(); rhs = rhs->constantFold(); - chillAST_node *returnval = this; + chillAST_Node *returnval = this; if (condition->isConstant()) { //fprintf(stderr, "ternop folding constants\n"); @@ -2660,10 +2608,10 @@ class chillAST_node *chillAST_TernaryOperator::constantFold() { return returnval; } -class chillAST_node *chillAST_TernaryOperator::clone() { - chillAST_node *c = condition->clone(); - chillAST_node *l = lhs->clone(); - chillAST_node *r = rhs->clone(); +class chillAST_Node *chillAST_TernaryOperator::clone() { + chillAST_Node *c = condition->clone(); + chillAST_Node *l = lhs->clone(); + chillAST_Node *r = rhs->clone(); chillAST_TernaryOperator *to = new chillAST_TernaryOperator(op, l, r, parent); c->setParent(to); l->setParent(to); @@ -2688,7 +2636,6 @@ void chillAST_TernaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() { //fprintf(stderr, "\n%p chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 0\n", this); - asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR; base = index = NULL; basedecl = NULL; //fprintf(stderr, "setting basedecl NULL for ASE %p\n", this); imwrittento = false; // ?? @@ -2702,12 +2649,11 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() { } -chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, chillAST_node *par, +chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, chillAST_Node *par, void *unique) { //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 1\n"); //fprintf(stderr, "ASE index %p ", indx); indx->print(0,stderr); fprintf(stderr, "\n"); - asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR; bas->setParent(this); if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong else base = bas; @@ -2733,12 +2679,11 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chi } -chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, bool writtento, - chillAST_node *par, void *unique) { +chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, bool writtento, + chillAST_Node *par, void *unique) { //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 2 parent %p\n", par ); //fprintf(stderr, "ASE %p index %p ", this, indx); indx->print(0,stderr); fprintf(stderr, "\n"); - asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR; bas->setParent(this); if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong else base = bas; @@ -2773,11 +2718,10 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chi } -chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_node *> indeces, - chillAST_node *par) { +chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_Node *> indeces, + chillAST_Node *par) { //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 4\n"); //fprintf(stderr,"chillAST_ArraySubscriptExpr( chillAST_VarDecl *v, std::vector<int> indeces)\n"); - asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR; parent = par; //if (parent == NULL) { // fprintf(stderr, "dammit. ASE %p has no parent\n", this); @@ -2807,7 +2751,7 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, st chillAST_ArraySubscriptExpr *rent = this; // parent for subnodes // these are on the top level ASE that we're creating here - base = (chillAST_node *) DRE; + base = (chillAST_Node *) DRE; index = indeces[numindeces - 1]; base->setParent(this); @@ -2830,9 +2774,9 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, st } -chillAST_node *chillAST_node::getEnclosingStatement(int level) { // TODO do for subclasses? +chillAST_Node *chillAST_Node::getEnclosingStatement(int level) { // TODO do for subclasses? - //fprintf(stderr, "chillAST_node::getEnclosingStatement( level %d ) node type %s\n", level, getTypeString()); + //fprintf(stderr, "chillAST_Node::getEnclosingStatement( level %d ) node type %s\n", level, getTypeString()); //print(); printf("\n"); fflush(stdout); // so far, user will ONLY call this directly on an array subscript expression @@ -2863,7 +2807,7 @@ chillAST_node *chillAST_node::getEnclosingStatement(int level) { // TODO do for } -void chillAST_ArraySubscriptExpr::gatherIndeces(std::vector<chillAST_node *> &ind) { +void chillAST_ArraySubscriptExpr::gatherIndeces(std::vector<chillAST_Node *> &ind) { if (base->isArraySubscriptExpr()) ((chillAST_ArraySubscriptExpr *) base)->gatherIndeces(ind); ind.push_back(index); } @@ -2950,7 +2894,7 @@ void chillAST_ArraySubscriptExpr::print(int indent, FILE *fp) const { chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { // return the VARDECL of the thing the subscript is an index into - //this should probably be a chillAST_node function instead of having all these ifs + //this should probably be a chillAST_Node function instead of having all these ifs //print(); printf("\n"); fflush(stdout); //base->print(); printf("\n"); fflush(stdout); //fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() base of type %s\n", base->getTypeString()); @@ -2960,21 +2904,21 @@ chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { // this will be used to SET basedecl //basedecl = NULL; // do this so we don't confuse ourselves looking at uninitialized basedecl - chillAST_node *b = base; + chillAST_Node *b = base; //fprintf(stderr, "base is of type %s\n", b->getTypeString()); if (!b) return NULL; // just in case ?? - if (base->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding + if (base->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding b = ((chillAST_ImplicitCastExpr *) b)->subexpr; } - if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { // multidimensional array! + if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { // multidimensional array! // recurse return ((chillAST_ArraySubscriptExpr *) b)->multibase(); } - if (b->asttype == CHILLAST_NODETYPE_DECLREFEXPR) return (((chillAST_DeclRefExpr *) b)->getVarDecl()); + if (b->getType() == CHILLAST_NODE_DECLREFEXPR) return (((chillAST_DeclRefExpr *) b)->getVarDecl()); if (b->isBinaryOperator()) { @@ -2986,8 +2930,8 @@ chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { exit(-1); } - chillAST_node *l = BO->lhs; - chillAST_node *r = BO->rhs; + chillAST_Node *l = BO->lhs; + chillAST_Node *r = BO->rhs; printf("L %s\nR %s\n", l->getTypeString(), r->getTypeString()); exit(-1); @@ -3000,7 +2944,7 @@ chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { chillAST_MemberExpr *ME = (chillAST_MemberExpr *) b; //fprintf(stderr, "multibase() Member Expression "); ME->print(); printf("\n"); fflush(stdout); - chillAST_node *n = ME->base; // WRONG want the MEMBER + chillAST_Node *n = ME->base; // WRONG want the MEMBER //fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() Member Expression base of type %s\n", n->getTypeString()); //fprintf(stderr, "base is "); ME->base->dump(); @@ -3057,17 +3001,17 @@ chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { } -chillAST_node *chillAST_ArraySubscriptExpr::getIndex(int dim) { +chillAST_Node *chillAST_ArraySubscriptExpr::getIndex(int dim) { //fprintf(stderr, "chillAST_ArraySubscriptExpr::getIndex( %d )\n", dim); - chillAST_node *b = base; + chillAST_Node *b = base; int depth = 0; - std::vector<chillAST_node *> ind; - chillAST_node *curindex = index; + std::vector<chillAST_Node *> ind; + chillAST_Node *curindex = index; for (;;) { - if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) b = ((chillAST_ImplicitCastExpr *) b)->subexpr; - else if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { + if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) b = ((chillAST_ImplicitCastExpr *) b)->subexpr; + else if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { //fprintf(stderr, "base "); b->print(); fprintf(stderr, "\n"); //fprintf(stderr, "index "); curindex->print(); fprintf(stderr, "\n"); ind.push_back(curindex); @@ -3090,16 +3034,16 @@ chillAST_node *chillAST_ArraySubscriptExpr::getIndex(int dim) { if (dim == 0) return index; // single dimension fprintf(stderr, "DIM NOT 0\n"); // multidimension - chillAST_node *b = base; - if (base->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding + chillAST_Node *b = base; + if (base->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding b = ((chillAST_ImplicitCastExpr*)b)->subexpr; } - if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding + if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding b = ((chillAST_ImplicitCastExpr*)b)->subexpr; } b->print(); printf("\n"); fflush(stdout); - if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { + if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { return ((chillAST_ArraySubscriptExpr *)b)->getIndex(dim-1); } @@ -3109,14 +3053,14 @@ chillAST_node *chillAST_ArraySubscriptExpr::getIndex(int dim) { } -class chillAST_node *chillAST_ArraySubscriptExpr::constantFold() { +class chillAST_Node *chillAST_ArraySubscriptExpr::constantFold() { //fprintf(stderr, "chillAST_ArraySubscriptExpr::constantFold()\n"); base = base->constantFold(); index = index->constantFold(); return this; } -class chillAST_node *chillAST_ArraySubscriptExpr::clone() { +class chillAST_Node *chillAST_ArraySubscriptExpr::clone() { //fprintf(stderr,"chillAST_ArraySubscriptExpr::clone() old imwrittento %d\n", imwrittento); //fprintf(stderr, "cloning ASE %p ", this); print(0,stderr); printf(" with parent %p\n", parent); fflush(stdout); //fprintf(stderr, "base %p base->parent %p index %p index->parent %p\n", base, base->parent, index, index->parent); @@ -3128,11 +3072,11 @@ class chillAST_node *chillAST_ArraySubscriptExpr::clone() { //fprintf(stderr, "old decl "); vd->print(); printf("\n");fflush(stdout); //fprintf(stderr, "old decl "); vd->dump(); printf("\n");fflush(stdout); } - chillAST_node *b = base->clone(); + chillAST_Node *b = base->clone(); //fprintf(stderr, "new base "); b->print(); printf("\n"); fflush(stdout); //fprintf(stderr, "new base "); b->dump(); printf("\n"); fflush(stdout); - chillAST_node *i = index->clone(); + chillAST_Node *i = index->clone(); //fprintf(stderr, "new index "); i->print(); printf("\n"); fflush(stdout); @@ -3223,7 +3167,7 @@ void chillAST_ArraySubscriptExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chi } -void chillAST_ArraySubscriptExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_ArraySubscriptExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr,"chillAST_ArraySubscriptExpr::replaceChild()\n"); // arraysubscriptexpression doesn t really have children (should it?) @@ -3275,19 +3219,17 @@ bool chillAST_ArraySubscriptExpr::operator==(const chillAST_ArraySubscriptExpr & chillAST_MemberExpr::chillAST_MemberExpr() { - asttype = CHILLAST_NODETYPE_MEMBEREXPR; base = NULL; member = NULL; parent = NULL; metacomment = NULL; - exptype = CHILL_MEMBER_EXP_DOT; + exptype = CHILLAST_MEMBER_EXP_DOT; isFromSourceFile = true; // default filename = NULL; } -chillAST_MemberExpr::chillAST_MemberExpr(chillAST_node *bas, const char *mem, chillAST_node *p, void *unique, - CHILL_MEMBER_EXP_TYPE t) { - asttype = CHILLAST_NODETYPE_MEMBEREXPR; +chillAST_MemberExpr::chillAST_MemberExpr(chillAST_Node *bas, const char *mem, chillAST_Node *p, void *unique, + CHILLAST_MEMBER_EXP_TYPE t) { base = bas; if (base) base->setParent(this); if (mem) member = strdup(mem); @@ -3328,7 +3270,7 @@ void chillAST_MemberExpr::dump(int indent, FILE *fp) { base->dump(indent + 1, fp); chillindent(indent + 1, fp); - if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->"); + if (exptype == CHILLAST_MEMBER_EXP_ARROW) fprintf(fp, "->"); else fprintf(fp, "."); fprintf(fp, "%s\n", member); @@ -3344,7 +3286,7 @@ void chillAST_MemberExpr::print(int indent, FILE *fp) { chillindent(indent, fp); fprintf(fp, "(NULL)"); } - if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->"); + if (exptype == CHILLAST_MEMBER_EXP_ARROW) fprintf(fp, "->"); else fprintf(fp, "."); if (member) fprintf(fp, "%s", member); else fprintf(fp, "(NULL)"); @@ -3354,7 +3296,7 @@ void chillAST_MemberExpr::print(int indent, FILE *fp) { void chillAST_MemberExpr::printonly(int indent, FILE *fp) { base->print(indent, fp); - if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->"); + if (exptype == CHILLAST_MEMBER_EXP_ARROW) fprintf(fp, "->"); else fprintf(fp, "."); fprintf(fp, "%s", member); fflush(fp); @@ -3365,7 +3307,7 @@ char *chillAST_MemberExpr::stringRep(int indent) { // char pointer to what we'd if (base->isDeclRefExpr()) { // chillAST_VarDecl *vd = (chillAST_VarDecl *) ((chillAST_DeclRefExpr *) base)->decl; char *leak = (char *) malloc(128); - if (exptype == CHILL_MEMBER_EXP_ARROW) sprintf(leak, "%s->%s", vd->varname, member); + if (exptype == CHILLAST_MEMBER_EXP_ARROW) sprintf(leak, "%s->%s", vd->varname, member); else sprintf(leak, "%s.%s", vd->varname, member); printstring = leak; return leak; @@ -3378,14 +3320,14 @@ char *chillAST_MemberExpr::stringRep(int indent) { // char pointer to what we'd } -class chillAST_node *chillAST_MemberExpr::constantFold() { +class chillAST_Node *chillAST_MemberExpr::constantFold() { base = base->constantFold(); //member = member->constantFold(); return this; } -class chillAST_node *chillAST_MemberExpr::clone() { - chillAST_node *b = base->clone(); +class chillAST_Node *chillAST_MemberExpr::clone() { + chillAST_Node *b = base->clone(); char *m = strdup(member); // ?? chillAST_MemberExpr *ME = new chillAST_MemberExpr(b, m, parent, uniquePtr /* ?? */ ); ME->isFromSourceFile = isFromSourceFile; @@ -3444,7 +3386,7 @@ bool chillAST_MemberExpr::operator==(const chillAST_MemberExpr &other) { } -void chillAST_MemberExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_MemberExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //printf("\nMemberExpr::replaceChild( )\n"); //printf("old: "); //old->print(); @@ -3461,7 +3403,7 @@ void chillAST_MemberExpr::replaceChild(chillAST_node *old, chillAST_node *newchi } } -chillAST_node *chillAST_MemberExpr::multibase2() { /*fprintf(stderr, "ME MB2\n" );*/ return (chillAST_node *) this; } +chillAST_Node *chillAST_MemberExpr::multibase2() { /*fprintf(stderr, "ME MB2\n" );*/ return (chillAST_Node *) this; } chillAST_VarDecl *chillAST_MemberExpr::getUnderlyingVarDecl() { fprintf(stderr, "chillAST_MemberExpr:getUnderlyingVarDecl()\n"); @@ -3521,7 +3463,6 @@ chillAST_VarDecl *chillAST_MemberExpr::multibase() { chillAST_DeclRefExpr::chillAST_DeclRefExpr() { - asttype = CHILLAST_NODETYPE_DECLREFEXPR; declarationType = strdup("UNKNOWN"); declarationName = strdup("NONE"); decl = NULL; @@ -3531,8 +3472,7 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr() { filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *varname, chillAST_node *par) { - asttype = CHILLAST_NODETYPE_DECLREFEXPR; +chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *varname, chillAST_Node *par) { declarationType = strdup("UNKNOWN"); declarationName = strdup(varname); decl = NULL; @@ -3541,9 +3481,8 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *varname, chillAST_node *p filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_node *par) { +chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_Node *par) { //fprintf(stderr, "DRE::DRE 0x%x %s %s\n", this, vartype, varname ); - asttype = CHILLAST_NODETYPE_DECLREFEXPR; declarationType = strdup(vartype); declarationName = strdup(varname); decl = NULL; @@ -3552,10 +3491,9 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varn filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_node *d, - chillAST_node *par) { +chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_Node *d, + chillAST_Node *par) { //fprintf(stderr, "DRE::DRE2 0x%x %s %s 0x%x\n", this, vartype, varname, d ); - asttype = CHILLAST_NODETYPE_DECLREFEXPR; declarationType = strdup(vartype); declarationName = strdup(varname); decl = d; @@ -3564,10 +3502,9 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varn filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_node *par) { // variable def +chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_Node *par) { // variable def //fprintf(stderr, "DRE::DRE3 (VD) 0x%x %s %s 0x%x\n", this, vd->vartype, vd->varname, vd ); - asttype = CHILLAST_NODETYPE_DECLREFEXPR; declarationType = strdup(vd->vartype); declarationName = strdup(vd->varname); decl = vd; @@ -3577,8 +3514,7 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_node * } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_node *par) { // function def - asttype = CHILLAST_NODETYPE_DECLREFEXPR; +chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_Node *par) { // function def declarationType = strdup(fd->returnType); declarationName = strdup(fd->functionName); decl = fd; @@ -3625,11 +3561,11 @@ void chillAST_DeclRefExpr::dump(int indent, FILE *fp) { fflush(fp); } -class chillAST_node *chillAST_DeclRefExpr::constantFold() { // can never do anything? +class chillAST_Node *chillAST_DeclRefExpr::constantFold() { // can never do anything? return this; } -class chillAST_node *chillAST_DeclRefExpr::clone() { +class chillAST_Node *chillAST_DeclRefExpr::clone() { //fprintf(stderr, "chillAST_DeclRefExpr::clone()\n"); chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(declarationType, declarationName, decl, parent); DRE->isFromSourceFile = isFromSourceFile; @@ -3780,9 +3716,9 @@ void chillAST_VarDecl::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { } -chillAST_node *chillAST_VarDecl::constantFold() { return this; } +chillAST_Node *chillAST_VarDecl::constantFold() { return this; } -chillAST_node *chillAST_VarDecl::clone() { +chillAST_Node *chillAST_VarDecl::clone() { fprintf(stderr, "\nchillAST_VarDecl::clone() cloning vardecl for %s\n", varname); if (isAParameter) fprintf(stderr, "old vardecl IS a parameter\n"); //else fprintf(stderr, "old vardecl IS NOT a parameter\n"); @@ -3875,9 +3811,8 @@ void chillAST_VarDecl::splitarraypart() { } -chillAST_IntegerLiteral::chillAST_IntegerLiteral(int val, chillAST_node *par) { +chillAST_IntegerLiteral::chillAST_IntegerLiteral(int val, chillAST_Node *par) { value = val; - asttype = CHILLAST_NODETYPE_INTEGERLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; @@ -3896,10 +3831,10 @@ void chillAST_IntegerLiteral::dump(int indent, FILE *fp) { } -class chillAST_node *chillAST_IntegerLiteral::constantFold() { return this; } // can never do anything +class chillAST_Node *chillAST_IntegerLiteral::constantFold() { return this; } // can never do anything -class chillAST_node *chillAST_IntegerLiteral::clone() { +class chillAST_Node *chillAST_IntegerLiteral::clone() { chillAST_IntegerLiteral *IL = new chillAST_IntegerLiteral(value, parent); IL->isFromSourceFile = isFromSourceFile; @@ -3908,65 +3843,60 @@ class chillAST_node *chillAST_IntegerLiteral::clone() { } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, chillAST_Node *par) { value = val; precision = 1; float0double1 = 0; // which is live! allthedigits = NULL; - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, chillAST_Node *par) { doublevalue = val; precision = 2; float0double1 = 1; // which is live! allthedigits = NULL; - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, chillAST_Node *par) { value = val; precision = 1; float0double1 = 0; // which is live! precision = precis; // allthedigits = NULL; - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, int precis, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, int precis, chillAST_Node *par) { doublevalue = val; float0double1 = 1; // which is live! precision = precis; // allthedigits = NULL; - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, const char *printthis, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, const char *printthis, chillAST_Node *par) { value = val; float0double1 = 0; // which is live! precision = 1; allthedigits = NULL; if (printthis) allthedigits = strdup(printthis); //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits); - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const char *printthis, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const char *printthis, chillAST_Node *par) { value = val; float0double1 = 0; // which is live! precision = precis; // but value is a float?? TODO @@ -3977,7 +3907,6 @@ chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const allthedigits = strdup(printthis); } //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits); - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; @@ -3987,7 +3916,6 @@ chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const chillAST_FloatingLiteral::chillAST_FloatingLiteral(chillAST_FloatingLiteral *old) { //fprintf(stderr, "chillAST_FloatingLiteral::chillAST_FloatingLiteral( old ) allthedigits %p\n", old->allthedigits); - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; value = old->value; doublevalue = old->doublevalue; float0double1 = old->float0double1; @@ -4050,9 +3978,9 @@ void chillAST_FloatingLiteral::dump(int indent, FILE *fp) { } -chillAST_node *chillAST_FloatingLiteral::constantFold() { return this; }; // NOOP +chillAST_Node *chillAST_FloatingLiteral::constantFold() { return this; }; // NOOP -chillAST_node *chillAST_FloatingLiteral::clone() { +chillAST_Node *chillAST_FloatingLiteral::clone() { //fprintf(stderr, "chillAST_FloatingLiteral::clone() "); //fprintf(stderr, "allthedigits %p \n", allthedigits); chillAST_FloatingLiteral *newone = new chillAST_FloatingLiteral(this); @@ -4063,7 +3991,7 @@ chillAST_node *chillAST_FloatingLiteral::clone() { return newone; } -bool chillAST_FloatingLiteral::isSameAs(chillAST_node *other) { +bool chillAST_FloatingLiteral::isSameAs(chillAST_Node *other) { if (!other->isFloatingLiteral()) return false; chillAST_FloatingLiteral *o = (chillAST_FloatingLiteral *) other; // should we care about single vs double precision? @@ -4075,12 +4003,11 @@ bool chillAST_FloatingLiteral::isSameAs(chillAST_node *other) { } -chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_node *sub, chillAST_node *par) { +chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_Node *sub, chillAST_Node *par) { op = strdup(oper); prefix = pre; subexpr = sub; subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_UNARYOPERATOR; parent = par; isFromSourceFile = true; // default filename = NULL; @@ -4125,12 +4052,12 @@ void chillAST_UnaryOperator::gatherVarLHSUsage(vector<chillAST_VarDecl *> &decls } -chillAST_node *chillAST_UnaryOperator::constantFold() { +chillAST_Node *chillAST_UnaryOperator::constantFold() { //fprintf(stderr, "chillAST_UnaryOperator::constantFold() "); //print(); fprintf(stderr, "\n"); subexpr = subexpr->constantFold(); - chillAST_node *returnval = this; + chillAST_Node *returnval = this; if (subexpr->isConstant()) { //fprintf(stderr, "unary op folding constants\n"); //print(0,stderr); fprintf(stderr, "\n"); @@ -4160,7 +4087,7 @@ chillAST_node *chillAST_UnaryOperator::constantFold() { } -class chillAST_node *chillAST_UnaryOperator::clone() { +class chillAST_Node *chillAST_UnaryOperator::clone() { chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, subexpr->clone(), parent); UO->isFromSourceFile = isFromSourceFile; if (filename) UO->filename = strdup(filename); @@ -4208,7 +4135,7 @@ int chillAST_UnaryOperator::evalAsInt() { } -bool chillAST_UnaryOperator::isSameAs(chillAST_node *other) { +bool chillAST_UnaryOperator::isSameAs(chillAST_Node *other) { if (!other->isUnaryOperator()) return false; chillAST_UnaryOperator *o = (chillAST_UnaryOperator *) other; if (strcmp(op, o->op)) return false; // different operators @@ -4216,10 +4143,9 @@ bool chillAST_UnaryOperator::isSameAs(chillAST_node *other) { } -chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *par) { +chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_Node *sub, chillAST_Node *par) { subexpr = sub; subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_IMPLICITCASTEXPR; parent = par; //fprintf(stderr, "ImplicitCastExpr 0x%x has subexpr 0x%x", this, subexpr); //fprintf(stderr, " of type %s\n", subexpr->getTypeString()); @@ -4239,7 +4165,7 @@ void chillAST_ImplicitCastExpr::printonly(int indent, FILE *fp) { fflush(fp); }; -void chillAST_ImplicitCastExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_ImplicitCastExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { if (subexpr == old) { // should be the case for this to get called subexpr = newchild; subexpr->setParent(this); @@ -4251,14 +4177,14 @@ void chillAST_ImplicitCastExpr::replaceChild(chillAST_node *old, chillAST_node * exit(-1); // ?? } -class chillAST_node *chillAST_ImplicitCastExpr::constantFold() { - chillAST_node *child = subexpr->constantFold(); +class chillAST_Node *chillAST_ImplicitCastExpr::constantFold() { + chillAST_Node *child = subexpr->constantFold(); child->setParent(parent); // remove myself !! probably a bad idea. TODO return child; } -class chillAST_node *chillAST_ImplicitCastExpr::clone() { +class chillAST_Node *chillAST_ImplicitCastExpr::clone() { chillAST_ImplicitCastExpr *ICE = new chillAST_ImplicitCastExpr(subexpr->clone(), parent); ICE->isFromSourceFile = isFromSourceFile; if (filename) ICE->filename = strdup(filename); @@ -4299,20 +4225,19 @@ void chillAST_ImplicitCastExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls } -chillAST_CStyleCastExpr::chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *par) { +chillAST_CStyleCastExpr::chillAST_CStyleCastExpr(const char *to, chillAST_Node *sub, chillAST_Node *par) { //fprintf(stderr, "chillAST_CStyleCastExpr::chillAST_CStyleCastExpr( %s, ...)\n", to); towhat = strdup(to); subexpr = sub; if (subexpr) subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_CSTYLECASTEXPR; parent = par; //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub ); isFromSourceFile = true; // default filename = NULL; } -void chillAST_CStyleCastExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_CStyleCastExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { if (subexpr == old) { // should be the case for this to get called subexpr = newchild; subexpr->setParent(this); @@ -4364,13 +4289,13 @@ void chillAST_CStyleCastExpr::dump(int indent, FILE *fp) { fflush(fp); } -class chillAST_node *chillAST_CStyleCastExpr::constantFold() { +class chillAST_Node *chillAST_CStyleCastExpr::constantFold() { subexpr = subexpr->constantFold(); return this; } -class chillAST_node *chillAST_CStyleCastExpr::clone() { +class chillAST_Node *chillAST_CStyleCastExpr::clone() { chillAST_CStyleCastExpr *CSCE = new chillAST_CStyleCastExpr(towhat, subexpr->clone(), parent); CSCE->isFromSourceFile = isFromSourceFile; if (filename) CSCE->filename = strdup(filename); @@ -4411,10 +4336,9 @@ void chillAST_CStyleCastExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) } -chillAST_CStyleAddressOf::chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *par) { +chillAST_CStyleAddressOf::chillAST_CStyleAddressOf(chillAST_Node *sub, chillAST_Node *par) { subexpr = sub; subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_CSTYLEADDRESSOF; parent = par; //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub ); isFromSourceFile = true; // default @@ -4439,12 +4363,12 @@ void chillAST_CStyleAddressOf::dump(int indent, FILE *fp) { fflush(fp); } -class chillAST_node *chillAST_CStyleAddressOf::constantFold() { +class chillAST_Node *chillAST_CStyleAddressOf::constantFold() { subexpr = subexpr->constantFold(); return this; } -class chillAST_node *chillAST_CStyleAddressOf::clone() { +class chillAST_Node *chillAST_CStyleAddressOf::clone() { chillAST_CStyleAddressOf *CSAO = new chillAST_CStyleAddressOf(subexpr->clone(), parent); CSAO->isFromSourceFile = isFromSourceFile; if (filename) CSAO->filename = strdup(filename); @@ -4483,29 +4407,27 @@ void chillAST_CStyleAddressOf::gatherVarUsage(vector<chillAST_VarDecl *> &decls) } -chillAST_Malloc::chillAST_Malloc(chillAST_node *size, chillAST_node *p) { +chillAST_Malloc::chillAST_Malloc(chillAST_Node *size, chillAST_Node *p) { thing = NULL; sizeexpr = size; // probably a multiply like sizeof(int) * 1024 - asttype = CHILLAST_NODETYPE_MALLOC; parent = p; isFromSourceFile = true; // default filename = NULL; }; -chillAST_Malloc::chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p) { +chillAST_Malloc::chillAST_Malloc(char *thething, chillAST_Node *numthings, chillAST_Node *p) { thing = strdup(thething); // "int" or "float" or "struct widget" sizeexpr = numthings; - asttype = CHILLAST_NODETYPE_MALLOC; parent = p; isFromSourceFile = true; // default filename = NULL; }; -chillAST_node *chillAST_Malloc::constantFold() { +chillAST_Node *chillAST_Malloc::constantFold() { sizeexpr->constantFold(); } -chillAST_node *chillAST_Malloc::clone() { +chillAST_Node *chillAST_Malloc::clone() { chillAST_Malloc *M = new chillAST_Malloc(thing, sizeexpr, parent); // the general version M->isFromSourceFile = isFromSourceFile; if (filename) M->filename = strdup(filename); @@ -4561,10 +4483,9 @@ void chillAST_Malloc::dump(int indent, FILE *fp) { }; -chillAST_CudaMalloc::chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p) { +chillAST_CudaMalloc::chillAST_CudaMalloc(chillAST_Node *devmemptr, chillAST_Node *size, chillAST_Node *p) { devPtr = devmemptr; sizeinbytes = size; // probably a multiply like sizeof(int) * 1024 - asttype = CHILLAST_NODETYPE_CUDAMALLOC; parent = p; isFromSourceFile = true; // default filename = NULL; @@ -4590,12 +4511,12 @@ void chillAST_CudaMalloc::dump(int indent, FILE *fp) { fflush(fp); }; -class chillAST_node *chillAST_CudaMalloc::constantFold() { +class chillAST_Node *chillAST_CudaMalloc::constantFold() { devPtr = devPtr->constantFold(); return this; } -class chillAST_node *chillAST_CudaMalloc::clone() { +class chillAST_Node *chillAST_CudaMalloc::clone() { chillAST_CudaMalloc *CM = new chillAST_CudaMalloc(devPtr->clone(), sizeinbytes->clone(), parent); CM->isFromSourceFile = isFromSourceFile; if (filename) CM->filename = strdup(filename); @@ -4636,10 +4557,9 @@ void chillAST_CudaMalloc::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CudaFree::chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p) { +chillAST_CudaFree::chillAST_CudaFree(chillAST_VarDecl *var, chillAST_Node *p) { variable = var; parent = p; - asttype = CHILLAST_NODETYPE_CUDAFREE; isFromSourceFile = true; // default filename = NULL; }; @@ -4656,11 +4576,11 @@ void chillAST_CudaFree::dump(int indent, FILE *fp) { fflush(fp); }; -class chillAST_node *chillAST_CudaFree::constantFold() { +class chillAST_Node *chillAST_CudaFree::constantFold() { return this; } -class chillAST_node *chillAST_CudaFree::clone() { +class chillAST_Node *chillAST_CudaFree::clone() { chillAST_CudaFree *CF = new chillAST_CudaFree(variable, parent); CF->isFromSourceFile = isFromSourceFile; if (filename) CF->filename = strdup(filename); @@ -4691,14 +4611,13 @@ void chillAST_CudaFree::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CudaMemcpy::chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *siz, char *kind, - chillAST_node *par) { +chillAST_CudaMemcpy::chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_Node *siz, char *kind, + chillAST_Node *par) { dest = d; src = s; //fprintf(stderr, "chillAST_CudaMemcpy::chillAST_CudaMemcpy( dest %s, src %s, ...)\n", d->varname, s->varname ); size = siz; cudaMemcpyKind = kind; - asttype = CHILLAST_NODETYPE_CUDAMEMCPY; isFromSourceFile = true; // default filename = NULL; parent = par; @@ -4727,14 +4646,14 @@ void chillAST_CudaMemcpy::dump(int indent, FILE *fp) { fflush(fp); }; -class chillAST_node *chillAST_CudaMemcpy::constantFold() { +class chillAST_Node *chillAST_CudaMemcpy::constantFold() { dest = (chillAST_VarDecl *) dest->constantFold(); src = (chillAST_VarDecl *) src->constantFold(); size = size->constantFold(); return this; } -class chillAST_node *chillAST_CudaMemcpy::clone() { +class chillAST_Node *chillAST_CudaMemcpy::clone() { chillAST_CudaMemcpy *CMCPY = new chillAST_CudaMemcpy((chillAST_VarDecl *) (dest->clone()), (chillAST_VarDecl *) (src->clone()), size->clone(), strdup(cudaMemcpyKind), parent); @@ -4783,8 +4702,7 @@ void chillAST_CudaMemcpy::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CudaSyncthreads::chillAST_CudaSyncthreads(chillAST_node *par) { - asttype = CHILLAST_NODETYPE_CUDASYNCTHREADS; +chillAST_CudaSyncthreads::chillAST_CudaSyncthreads(chillAST_Node *par) { parent = par; isFromSourceFile = true; // default filename = NULL; @@ -4803,8 +4721,7 @@ void chillAST_CudaSyncthreads::dump(int indent, FILE *fp) { } -chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_node *retval, chillAST_node *par) { - asttype = CHILLAST_NODETYPE_RETURNSTMT; +chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_Node *retval, chillAST_Node *par) { returnvalue = retval; if (returnvalue) returnvalue->setParent(this); parent = par; @@ -4839,14 +4756,14 @@ void chillAST_ReturnStmt::dump(int indent, FILE *fp) { } -class chillAST_node *chillAST_ReturnStmt::constantFold() { +class chillAST_Node *chillAST_ReturnStmt::constantFold() { if (returnvalue) returnvalue = returnvalue->constantFold(); return this; } -class chillAST_node *chillAST_ReturnStmt::clone() { - chillAST_node *val = NULL; +class chillAST_Node *chillAST_ReturnStmt::clone() { + chillAST_Node *val = NULL; if (returnvalue) val = returnvalue->clone(); chillAST_ReturnStmt *RS = new chillAST_ReturnStmt(val, parent); RS->isFromSourceFile = isFromSourceFile; @@ -4880,11 +4797,10 @@ void chillAST_ReturnStmt::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CallExpr::chillAST_CallExpr(chillAST_node *c, - chillAST_node *par) { //, int numofargs, chillAST_node **theargs ) { +chillAST_CallExpr::chillAST_CallExpr(chillAST_Node *c, + chillAST_Node *par) { //, int numofargs, chillAST_Node **theargs ) { //fprintf(stderr, "chillAST_CallExpr::chillAST_CallExpr callee type %s\n", c->getTypeString()); - asttype = CHILLAST_NODETYPE_CALLEXPR; callee = c; //callee->setParent( this ); // ?? numargs = 0; @@ -4895,7 +4811,7 @@ chillAST_CallExpr::chillAST_CallExpr(chillAST_node *c, } -void chillAST_CallExpr::addArg(chillAST_node *a) { +void chillAST_CallExpr::addArg(chillAST_Node *a) { args.push_back(a); a->setParent(this); numargs += 1; @@ -5025,7 +4941,7 @@ void chillAST_CallExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_node *chillAST_CallExpr::constantFold() { +chillAST_Node *chillAST_CallExpr::constantFold() { numargs = args.size(); // wrong place for this for (int i = 0; i < numargs; i++) { args[i] = args[i]->constantFold(); @@ -5033,7 +4949,7 @@ chillAST_node *chillAST_CallExpr::constantFold() { return this; } -chillAST_node *chillAST_CallExpr::clone() { +chillAST_Node *chillAST_CallExpr::clone() { //fprintf(stderr, "chillAST_CallExpr::clone()\n"); //print(0, stderr); fprintf(stderr, "\n"); @@ -5055,7 +4971,6 @@ chillAST_VarDecl::chillAST_VarDecl() { init = NULL; numdimensions = 0; arraysizes = NULL; - asttype = CHILLAST_NODETYPE_VARDECL; // parent = NULL; metacomment = NULL; @@ -5073,7 +4988,7 @@ chillAST_VarDecl::chillAST_VarDecl() { }; -chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_node *par) { +chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_Node *par) { //fprintf(stderr, "1chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s, parent %p) %p\n", t, n, a, par, this); fprintf(stderr, "1chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s)\n", t, n, a); vartype = strdup(t); @@ -5091,7 +5006,6 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - asttype = CHILLAST_NODETYPE_VARDECL; parent = par; @@ -5125,7 +5039,7 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam, const char *array, - chillAST_node *par) { + chillAST_Node *par) { // define a variable whose type is a struct! fprintf(stderr, "3chillAST_VarDecl::chillAST_VarDecl( %s %p struct ", nam, this); @@ -5152,7 +5066,6 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - asttype = CHILLAST_NODETYPE_VARDECL; parent = par; knownArraySizes = false; @@ -5183,7 +5096,7 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam }; -chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, const char *a, chillAST_node *par) { +chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, const char *a, chillAST_Node *par) { fprintf(stderr, "4chillAST_VarDecl::chillAST_VarDecl( %s typedef ", n); const char *type = tdd->getStructName(); //fprintf (stderr, "%s, name %s, arraypart %s parent ) %p\n", type, n, a,this); // , par); @@ -5200,7 +5113,6 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, con numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - asttype = CHILLAST_NODETYPE_VARDECL; parent = par; knownArraySizes = false; @@ -5230,7 +5142,7 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, con }; -chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, chillAST_node *par) { +chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, chillAST_Node *par) { CHILL_DEBUG_PRINT("chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart '%s' ) %p\n", t, n, a, this); @@ -5253,7 +5165,6 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, numdimensions = 0; arraysizes = NULL; uniquePtr = ptr; - asttype = CHILLAST_NODETYPE_VARDECL; parent = par; knownArraySizes = false; @@ -5544,7 +5455,6 @@ chillAST_RecordDecl *chillAST_VarDecl::getStructDef() { chillAST_CompoundStmt::chillAST_CompoundStmt() { //fprintf(stderr, "chillAST_CompoundStmt::chillAST_CompoundStmt() %p\n", this); - asttype = CHILLAST_NODETYPE_COMPOUNDSTMT; parent = NULL; symbol_table = new chillAST_SymbolTable; typedef_table = NULL; @@ -5559,10 +5469,10 @@ void chillAST_CompoundStmt::print(int indent, FILE *fp) { //fprintf(stderr, "NUMCHILDREN %d\n", numchildren); sleep(1); for (int i = 0; i < numchildren; i++) { children[i]->print(indent, fp); - if (children[i]->asttype != CHILLAST_NODETYPE_FORSTMT - && children[i]->asttype != CHILLAST_NODETYPE_IFSTMT - && children[i]->asttype != CHILLAST_NODETYPE_COMPOUNDSTMT - //&& children[i]->asttype != CHILLAST_NODETYPE_VARDECL // vardecl does its own ";\n" + if (children[i]->getType() != CHILLAST_NODE_FORSTMT + && children[i]->getType() != CHILLAST_NODE_IFSTMT + && children[i]->getType() != CHILLAST_NODE_COMPOUNDSTMT + //&& children[i]->getType() != CHILLAST_NODE_VARDECL // vardecl does its own ";\n" ) { fprintf(fp, ";\n"); // probably wrong } @@ -5570,9 +5480,9 @@ void chillAST_CompoundStmt::print(int indent, FILE *fp) { fflush(fp); } -void chillAST_CompoundStmt::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_CompoundStmt::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr, "chillAST_CompoundStmt::replaceChild( old %s, new %s)\n", old->getTypeString(), newchild->getTypeString() ); - vector<chillAST_node *> dupe = children; + vector<chillAST_Node *> dupe = children; int numdupe = dupe.size(); int any = 0; @@ -5619,7 +5529,7 @@ void chillAST_CompoundStmt::loseLoopWithLoopVar(char *var) { for (int j=0; j<children.size(); j++) { fprintf(stderr, "j %d/%d ", j, children.size()); fprintf(stderr, "subnode %d 0x%x ", j, children[j] ); - fprintf(stderr, "asttype %d ", children[j]->asttype); + fprintf(stderr, "asttype %d ", children[j]->getType()); fprintf(stderr, "%s ", children[j]->getTypeString()); if (children[j]->isForStmt()) { chillAST_ForStmt *FS = ((chillAST_ForStmt *) children[j]); @@ -5636,7 +5546,7 @@ void chillAST_CompoundStmt::loseLoopWithLoopVar(char *var) { #endif - vector<chillAST_node *> dupe = children; // simple enough? + vector<chillAST_Node *> dupe = children; // simple enough? for (int i = 0; i < dupe.size(); i++) { //for (int j=0; j<dupe.size(); j++) { // fprintf(stderr, "j %d/%d\n", j, dupe.size()); @@ -5681,14 +5591,14 @@ void chillAST_CompoundStmt::dump(int indent, FILE *fp) { }; -chillAST_node *chillAST_CompoundStmt::constantFold() { +chillAST_Node *chillAST_CompoundStmt::constantFold() { //fprintf(stderr, "chillAST_CompoundStmt::constantFold()\n"); for (int i = 0; i < children.size(); i++) children[i] = children[i]->constantFold(); return this; } -chillAST_node *chillAST_CompoundStmt::clone() { +chillAST_Node *chillAST_CompoundStmt::clone() { chillAST_CompoundStmt *cs = new chillAST_CompoundStmt(); for (int i = 0; i < children.size(); i++) cs->addChild(children[i]->clone()); cs->setParent(parent); @@ -5732,7 +5642,7 @@ void chillAST_CompoundStmt::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> for (int i = 0; i < children.size(); i++) children[i]->gatherScalarRefs(refs, 0); } -void chillAST_CompoundStmt::gatherStatements(std::vector<chillAST_node *> &statements) { +void chillAST_CompoundStmt::gatherStatements(std::vector<chillAST_Node *> &statements) { for (int i = 0; i < children.size(); i++) children[i]->gatherStatements(statements); } @@ -5768,7 +5678,7 @@ bool chillAST_CompoundStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symta return false; /* - vector<chillAST_node*> childrencopy; + vector<chillAST_Node*> childrencopy; for (int i=0; i<children.size(); i++) childrencopy.push_back( children[i] ); bool force = false; @@ -5798,10 +5708,9 @@ bool chillAST_CompoundStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symta } -chillAST_ParenExpr::chillAST_ParenExpr(chillAST_node *sub, chillAST_node *par) { +chillAST_ParenExpr::chillAST_ParenExpr(chillAST_Node *sub, chillAST_Node *par) { subexpr = sub; subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_PARENEXPR; parent = par; isFromSourceFile = true; // default filename = NULL; @@ -5834,13 +5743,13 @@ void chillAST_ParenExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &r } -chillAST_node *chillAST_ParenExpr::constantFold() { +chillAST_Node *chillAST_ParenExpr::constantFold() { subexpr = subexpr->constantFold(); return this; } -chillAST_node *chillAST_ParenExpr::clone() { +chillAST_Node *chillAST_ParenExpr::clone() { chillAST_ParenExpr *PE = new chillAST_ParenExpr(subexpr->clone(), NULL); PE->isFromSourceFile = isFromSourceFile; if (filename) PE->filename = strdup(filename); @@ -5875,7 +5784,7 @@ void chillAST_ParenExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_Sizeof::chillAST_Sizeof(char *athing, chillAST_node *par) { +chillAST_Sizeof::chillAST_Sizeof(char *athing, chillAST_Node *par) { thing = strdup(athing); // memory leak parent = par; isFromSourceFile = true; // default @@ -5900,11 +5809,11 @@ void chillAST_Sizeof::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> void chillAST_Sizeof::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {} -chillAST_node *chillAST_Sizeof::constantFold() { +chillAST_Node *chillAST_Sizeof::constantFold() { return this; } -chillAST_node *chillAST_Sizeof::clone() { +chillAST_Node *chillAST_Sizeof::clone() { chillAST_Sizeof *SO = new chillAST_Sizeof(thing, NULL); SO->isFromSourceFile = isFromSourceFile; if (filename) SO->filename = strdup(filename); @@ -5944,8 +5853,8 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va newdecl->vartype = strdup(olddecl->vartype); - chillAST_node *newparent = newdecl->parent; - chillAST_node *oldparent = olddecl->parent; + chillAST_Node *newparent = newdecl->parent; + chillAST_Node *oldparent = olddecl->parent; //fprintf(stderr, "newparent 0x%x oldparent 0x%x\n", newparent, oldparent ); if (newparent == oldparent) return; @@ -5955,7 +5864,7 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va // find actual location of old decl and insert new one there //fprintf(stderr, "oldparent is of type %s\n", oldparent->getTypeString()); // better be compoundstmt ?? - vector<chillAST_node *> children = oldparent->getChildren(); + vector<chillAST_Node *> children = oldparent->getChildren(); int numchildren = children.size(); //fprintf(stderr, "oldparent has %d children\n", numchildren); @@ -5972,7 +5881,7 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va //fprintf(stderr, "olddecl is 0x%x\n", olddecl); //fprintf(stderr, "I know of %d variables\n", numchildren); for (int i = 0; i < numchildren; i++) { - chillAST_node *child = oldparent->getChild(i); + chillAST_Node *child = oldparent->getChild(i); //fprintf(stderr, "child %d @ 0x%x is of type %s\n", i, child, child->getTypeString()); if (children[i] == olddecl) { index = i; @@ -5994,26 +5903,26 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va } -void gatherVarDecls(vector<chillAST_node *> &code, vector<chillAST_VarDecl *> &decls) { +void gatherVarDecls(vector<chillAST_Node *> &code, vector<chillAST_VarDecl *> &decls) { //fprintf(stderr, "gatherVarDecls()\n"); int numcode = code.size(); //fprintf(stderr, "%d top level statements\n", numcode); for (int i = 0; i < numcode; i++) { - chillAST_node *statement = code[i]; + chillAST_Node *statement = code[i]; statement->gatherVarDecls(decls); } } -void gatherVarUsage(vector<chillAST_node *> &code, vector<chillAST_VarDecl *> &decls) { +void gatherVarUsage(vector<chillAST_Node *> &code, vector<chillAST_VarDecl *> &decls) { //fprintf(stderr, "gatherVarUsage()\n"); int numcode = code.size(); //fprintf(stderr, "%d top level statements\n", numcode); for (int i = 0; i < numcode; i++) { - chillAST_node *statement = code[i]; + chillAST_Node *statement = code[i]; statement->gatherVarUsage(decls); } @@ -6022,12 +5931,11 @@ void gatherVarUsage(vector<chillAST_node *> &code, vector<chillAST_VarDecl *> &d chillAST_IfStmt::chillAST_IfStmt() { cond = thenpart = elsepart = NULL; - asttype = CHILLAST_NODETYPE_IFSTMT; isFromSourceFile = true; // default filename = NULL; } -chillAST_IfStmt::chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p) { +chillAST_IfStmt::chillAST_IfStmt(chillAST_Node *c, chillAST_Node *t, chillAST_Node *e, chillAST_Node *p) { cond = c; if (cond) cond->setParent(this); thenpart = t; @@ -6035,7 +5943,6 @@ chillAST_IfStmt::chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_no elsepart = e; if (elsepart) elsepart->setParent(this); parent = p; - asttype = CHILLAST_NODETYPE_IFSTMT; isFromSourceFile = true; // default filename = NULL; } @@ -6088,14 +5995,14 @@ void chillAST_IfStmt::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs } -chillAST_node *chillAST_IfStmt::constantFold() { +chillAST_Node *chillAST_IfStmt::constantFold() { if (cond) cond = cond->constantFold(); if (thenpart) thenpart = thenpart->constantFold(); if (elsepart) elsepart = elsepart->constantFold(); return this; } -void chillAST_IfStmt::gatherStatements(std::vector<chillAST_node *> &statements) { +void chillAST_IfStmt::gatherStatements(std::vector<chillAST_Node *> &statements) { //print(); printf("\n"); fflush(stdout); thenpart->gatherStatements(statements); @@ -6108,8 +6015,8 @@ void chillAST_IfStmt::gatherStatements(std::vector<chillAST_node *> &statements) } -chillAST_node *chillAST_IfStmt::clone() { - chillAST_node *c, *t, *e; +chillAST_Node *chillAST_IfStmt::clone() { + chillAST_Node *c, *t, *e; c = t = e = NULL; if (cond) c = cond->clone(); // has to be one, right? if (thenpart) t = thenpart->clone(); @@ -6205,7 +6112,7 @@ bool chillAST_IfStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, boo } -chillAST_node *lessthanmacro(chillAST_node *left, chillAST_node *right) { +chillAST_Node *lessthanmacro(chillAST_Node *left, chillAST_Node *right) { chillAST_ParenExpr *lp1 = new chillAST_ParenExpr(left); chillAST_ParenExpr *rp1 = new chillAST_ParenExpr(right); @@ -6221,7 +6128,7 @@ chillAST_node *lessthanmacro(chillAST_node *left, chillAST_node *right) { // look for function declaration with a given name, in the tree with root "node" -void findFunctionDeclRecursive(chillAST_node *node, const char *procname, vector<chillAST_FunctionDecl *> &funcs) { +void findFunctionDeclRecursive(chillAST_Node *node, const char *procname, vector<chillAST_FunctionDecl *> &funcs) { //fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString()); if (node->isFunctionDecl()) { @@ -6263,7 +6170,7 @@ void findFunctionDeclRecursive(chillAST_node *node, const char *procname, vector } -chillAST_FunctionDecl *findFunctionDecl(chillAST_node *node, const char *procname) { +chillAST_FunctionDecl *findFunctionDecl(chillAST_Node *node, const char *procname) { vector<chillAST_FunctionDecl *> functions; findFunctionDeclRecursive(node, procname, functions); @@ -6337,7 +6244,7 @@ chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tdt, chillAST_Ty } -chillAST_NoOp::chillAST_NoOp(chillAST_node *p) { +chillAST_NoOp::chillAST_NoOp(chillAST_Node *p) { parent = p; isFromSourceFile = true; // default filename = NULL; @@ -6345,14 +6252,14 @@ chillAST_NoOp::chillAST_NoOp(chillAST_node *p) { chillAST_Preprocessing::chillAST_Preprocessing() { - position = CHILL_PREPROCESSING_POSITIONUNKNOWN; - pptype = CHILL_PREPROCESSING_TYPEUNKNOWN; + position = CHILLAST_PREPROCESSING_POSITIONUNKNOWN; + pptype = CHILLAST_PREPROCESSING_TYPEUNKNOWN; blurb = strdup(""); // never use null. ignore the leak ?? } -chillAST_Preprocessing::chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos, - CHILL_PREPROCESSING_TYPE t, +chillAST_Preprocessing::chillAST_Preprocessing(CHILLAST_PREPROCESSING_POSITION pos, + CHILLAST_PREPROCESSING_TYPE t, char *text) { position = pos; pptype = t; @@ -6360,28 +6267,28 @@ chillAST_Preprocessing::chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos, } void chillAST_Preprocessing::print(int indent, FILE *fp) { // probably very wrong - if (position == CHILL_PREPROCESSING_LINEAFTER) { + if (position == CHILLAST_PREPROCESSING_LINEAFTER) { fprintf(fp, "\n"); chillindent(indent, fp); } - if (position == CHILL_PREPROCESSING_LINEBEFORE) { // ??? + if (position == CHILLAST_PREPROCESSING_LINEBEFORE) { // ??? //fprintf(fp, "\n"); chillindent(indent, fp); } fprintf(fp, "%s", blurb); - if (position == CHILL_PREPROCESSING_TOTHERIGHT) { + if (position == CHILLAST_PREPROCESSING_TOTHERIGHT) { fprintf(fp, "\n"); } - if (position == CHILL_PREPROCESSING_LINEBEFORE) { + if (position == CHILLAST_PREPROCESSING_LINEBEFORE) { //fprintf(fp, "\n"); // comment seems to have \n at the end already //chillindent(indent, fp); } - //if (pptype != CHILL_PREPROCESSING_IMMEDIATELYBEFORE && pptype != CHILL_PREPROCESSING_UNKNOWN) fprint(fp, "\n"); + //if (pptype != CHILLAST_PREPROCESSING_IMMEDIATELYBEFORE && pptype != CHILLAST_PREPROCESSING_UNKNOWN) fprint(fp, "\n"); } diff --git a/src/ir_clang.cc b/src/ir_clang.cc index c8a0c12..628e101 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -1,5 +1,3 @@ - - /***************************************************************************** Copyright (C) 2009-2010 University of Utah All Rights Reserved. @@ -21,8 +19,6 @@ History: #include "loop.hh" #include "chill_error.hh" -#define DUMPFUNC(x, y) std::cerr << "In function " << x << "\n"; y->dump(); - #include "clang/Frontend/FrontendActions.h" #include <clang/CodeGen/CodeGenAction.h> #include <clang/Frontend/CompilerInstance.h> @@ -45,50 +41,58 @@ History: #include "chillAST.h" +#define NL_RET(x) {chillAST_NodeList *ret = new chillAST_NodeList(); \ + ret->push_back(x); \ + return ret;} + // TODO move to ir_clang.hh -// fwd declarations -chillAST_node *ConvertVarDecl(clang::VarDecl *D, chillAST_node *); -chillAST_node *ConvertTypeDefDecl(clang::TypedefDecl *TDD, chillAST_node *); +chillAST_NodeList* ConvertTypeDefDecl(clang::TypedefDecl *TDD); -chillAST_node *ConvertRecordDecl(clang::RecordDecl *D, chillAST_node *); +chillAST_NodeList* ConvertRecordDecl(clang::RecordDecl *D); -chillAST_node *ConvertDeclStmt(clang::DeclStmt *clangDS, chillAST_node *); +chillAST_NodeList* ConvertDeclStmt(clang::DeclStmt *clangDS); -chillAST_node *ConvertCompoundStmt(clang::CompoundStmt *clangCS, chillAST_node *); +chillAST_NodeList* ConvertCompoundStmt(clang::CompoundStmt *clangCS); -chillAST_node *ConvertFunctionDecl(clang::FunctionDecl *D, chillAST_node *); +chillAST_NodeList* ConvertFunctionDecl(clang::FunctionDecl *D); -chillAST_node *ConvertForStmt(clang::ForStmt *clangFS, chillAST_node *); +chillAST_NodeList* ConvertForStmt(clang::ForStmt *clangFS); -chillAST_node *ConvertUnaryOperator(clang::UnaryOperator *clangU, chillAST_node *O); +chillAST_NodeList* ConvertUnaryOperator(clang::UnaryOperator *clangU); -chillAST_node *ConvertBinaryOperator(clang::BinaryOperator *clangBO, chillAST_node *B); +chillAST_NodeList* ConvertBinaryOperator(clang::BinaryOperator *clangBO); -chillAST_node *ConvertArraySubscriptExpr(clang::ArraySubscriptExpr *clangASE, chillAST_node *); +chillAST_NodeList* ConvertArraySubscriptExpr(clang::ArraySubscriptExpr *clangASE); -chillAST_node *ConvertDeclRefExpr(clang::DeclRefExpr *clangDRE, chillAST_node *); +chillAST_NodeList* ConvertDeclRefExpr(clang::DeclRefExpr *clangDRE); -chillAST_node *ConvertIntegerLiteral(clang::IntegerLiteral *clangIL, chillAST_node *); +chillAST_NodeList* ConvertIntegerLiteral(clang::IntegerLiteral *clangIL); -chillAST_node *ConvertFloatingLiteral(clang::FloatingLiteral *clangFL, chillAST_node *); +chillAST_NodeList* ConvertFloatingLiteral(clang::FloatingLiteral *clangFL); -chillAST_node *ConvertImplicitCastExpr(clang::ImplicitCastExpr *clangICE, chillAST_node *); +chillAST_NodeList* ConvertImplicitCastExpr(clang::ImplicitCastExpr *clangICE); -chillAST_node *ConvertCStyleCastExpr(clang::CStyleCastExpr *clangICE, chillAST_node *); +chillAST_NodeList* ConvertCStyleCastExpr(clang::CStyleCastExpr *clangICE); -chillAST_node *ConvertReturnStmt(clang::ReturnStmt *clangRS, chillAST_node *); +chillAST_NodeList* ConvertReturnStmt(clang::ReturnStmt *clangRS); -chillAST_node *ConvertCallExpr(clang::CallExpr *clangCE, chillAST_node *); +chillAST_NodeList* ConvertCallExpr(clang::CallExpr *clangCE); -chillAST_node *ConvertIfStmt(clang::IfStmt *clangIS, chillAST_node *); +chillAST_NodeList* ConvertIfStmt(clang::IfStmt *clangIS); -chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *); +chillAST_NodeList* ConvertMemberExpr(clang::MemberExpr *clangME); -chillAST_node *ConvertTranslationUnit(clang::TranslationUnitDecl *TUD, char *filename); +chillAST_NodeList* ConvertTranslationUnit(clang::TranslationUnitDecl *TUD, char *filename); -chillAST_node *ConvertGenericClangAST(clang::Stmt *s, chillAST_node *); +/*! + * \brief Convert fon Clang AST to CHiLL AST also append to parent node p if necessary + * + * @param s Clang statement + * @return A set of new statements + */ +chillAST_NodeList* ConvertGenericClangAST(clang::Stmt *s); std::vector<chillAST_VarDecl *> VariableDeclarations; @@ -170,6 +174,11 @@ void PrintTypeDefDecl(TypedefDecl *D, SourceManager *SRCMAN, int level); void PrintVarDecl(VarDecl *D, SourceManager *SRCMAN, int level); +chillAST_Node* unwrap(chillAST_NodeList* nl){ + chillAST_Node* n = (*nl)[0]; + delete nl; + return n; +} void printlines(SourceLocation &S, SourceLocation &E, SourceManager *SRCMAN) { unsigned int startlineno = SRCMAN->getPresumedLineNumber(S); @@ -382,28 +391,27 @@ void PrintCompoundStmt(Stmt *s, SourceManager *SRCMAN, int level) { //fprintf(stderr, "CompoundStmt has %d children\n", numchildren); -#ifdef DEBUGGING - BUH - for (Stmt::child_range I = cs->children(); I; ++I) { - const char *classname = I->getStmtClassName(); - if (!strcmp(classname, "BinaryOperator")) { - BinaryOperator *b = cast<BinaryOperator>(*I); - BinaryOperator::Opcode op = b->getOpcode(); - if (op == BO_Assign) { - fprintf(stderr, "compound statement has child of type ASSIGNMENT STATEMENT "); - SourceLocation S = I->getLocStart(); - SourceLocation E = I->getLocEnd(); - unsigned int startlineno = SRCMAN->getPresumedLineNumber( S ); - unsigned int endlineno = SRCMAN->getPresumedLineNumber( E ); - fprintf(stderr, "(%d-%d)\n", startlineno, endlineno ); - } - else - fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName()); + CHILL_DEBUG_BEGIN + for (Stmt::child_iterator I = cs->child_begin(); I!=cs->child_end(); ++I) { + const char *classname = I->getStmtClassName(); + if (!strcmp(classname, "BinaryOperator")) { + BinaryOperator *b = cast<BinaryOperator>(*I); + BinaryOperator::Opcode op = b->getOpcode(); + if (op == BO_Assign) { + fprintf(stderr, "compound statement has child of type ASSIGNMENT STATEMENT "); + SourceLocation S = I->getLocStart(); + SourceLocation E = I->getLocEnd(); + unsigned int startlineno = SRCMAN->getPresumedLineNumber( S ); + unsigned int endlineno = SRCMAN->getPresumedLineNumber( E ); + fprintf(stderr, "(%d-%d)\n", startlineno, endlineno ); } else fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName()); } -#endif // debugging + else + fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName()); + } + CHILL_DEBUG_END for (auto I = cs->child_begin(); I != cs->child_end(); ++I) { @@ -615,7 +623,7 @@ void PrintVarDecl(VarDecl *D, SourceManager *SRCMAN, int level) { -chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) { +chillAST_NodeList* ConvertVarDecl(VarDecl *D) { //fprintf(stderr, "\nConvertVarDecl()\n"); //fprintf(stderr, "Decl has type %s\n", D->getDeclKindName()); //PrintVarDecl( D, globalSRCMAN, 0 ); @@ -639,7 +647,7 @@ chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) { char *varname = strdup(D->getName().str().c_str()); //fprintf(stderr, "VarDecl (clang 0x%x) for %s %s%s\n", D, vartype, varname, arraypart); - chillAST_VarDecl *chillVD = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, p /* , initializer */ ); + chillAST_VarDecl *chillVD = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, NULL); chillVD->isAParameter = isParm; //fprintf(stderr, "\nthis is the vardecl\n"); @@ -730,11 +738,12 @@ chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) { // store this away for declrefexpr that references it! VariableDeclarations.push_back(chillVD); - return chillVD; + + NL_RET(chillVD); } -chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // for structs and unions +chillAST_NodeList* ConvertRecordDecl(clang::RecordDecl *RD) { // for structs and unions //fprintf(stderr, "ConvertRecordDecl( )\n\nclang sees\n"); //RD->dump(); @@ -753,7 +762,7 @@ chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // f sprintf(blurb, "struct %s", RD->getNameAsString().c_str()); fprintf(stderr, "blurb is '%s'\n", blurb); - chillAST_TypedefDecl *astruct = new chillAST_TypedefDecl(blurb, "", p); + chillAST_TypedefDecl *astruct = new chillAST_TypedefDecl(blurb, "", NULL); astruct->setStruct(true); astruct->setStructName(RD->getNameAsString().c_str()); @@ -779,11 +788,11 @@ chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // f fprintf(stderr, "I just defined a struct\n"); astruct->print(0, stderr); - return astruct; + NL_RET(astruct); } -chillAST_node *ConvertTypeDefDecl(TypedefDecl *TDD, chillAST_node *p) { +chillAST_NodeList* ConvertTypeDefDecl(TypedefDecl *TDD) { //fprintf(stderr, "ConvertTypedefDecl( ) \n"); //fprintf(stderr, "TDD has type %s\n", TDD->getDeclKindName()); //TDD->dump(); fprintf(stderr, "\n"); @@ -796,23 +805,24 @@ chillAST_node *ConvertTypeDefDecl(TypedefDecl *TDD, chillAST_node *p) { char *alias = strdup(TDD->getName().str().c_str()); //fprintf(stderr, "underlying type %s arraypart '%s' name %s\n", under, arraypart, TDD->getName().str().c_str() ); - chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl(under, alias, arraypart, p); + chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl(under, alias, arraypart, NULL); free(under); free(arraypart); - return CTDD; + NL_RET(CTDD); } -chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) { +chillAST_NodeList* ConvertDeclStmt(DeclStmt *clangDS) { //fprintf(stderr, "ConvertDeclStmt()\n"); chillAST_VarDecl *chillvardecl; // the thing we'll return if this is a single declaration bool multiples = !clangDS->isSingleDecl(); if (multiples) { - //fprintf(stderr, "ir_clang.cc multiple declarations in a single CLANG DeclStmt not really handled! (??)\n"); + // TODO unhandled case + CHILL_ERROR("multiple declarations in a single CLANG DeclStmt not really handled! (??)\n"); // for now, try to make the multiple decls into a compoundstmt with them inside. // if we don't get scoping problems, this might work } @@ -840,15 +850,13 @@ chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) { //fprintf(stderr, "%s %s\n", td, varname); char *arraypart = splitTypeInfo(vartype); - chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, p); + chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, NULL); //fprintf(stderr, "DeclStmt (clang 0x%x) for %s %s%s\n", D, vartype, varname, arraypart); // store this away for declrefexpr that references it! VariableDeclarations.push_back(chillvardecl); - if (multiples) p->addChild(chillvardecl); - - // TODO + // TODO if (V->hasInit()) { CHILL_ERROR(" ConvertDeclStmt() UNHANDLED initialization\n"); exit(-1); @@ -856,35 +864,34 @@ chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) { } } // for each of possibly multiple decls - if (multiples) return NULL; // multiple decls added themselves already - return chillvardecl; // OR a single decl + NL_RET(chillvardecl); // OR a single decl } -chillAST_node *ConvertCompoundStmt(CompoundStmt *clangCS, chillAST_node *p) { +chillAST_NodeList* ConvertCompoundStmt(CompoundStmt *clangCS) { //fprintf(stderr, "ConvertCompoundStmt( )\n"); int numchildren = clangCS->size(); //fprintf(stderr, "clang CompoundStmt has %d children\n", numchildren); // make an empty CHILL compound statement chillAST_CompoundStmt *chillCS = new chillAST_CompoundStmt; - chillCS->setParent(p); // for each clang child for (auto I = clangCS->child_begin(); I != clangCS->child_end(); ++I) { // ?? loop looks WRONG // create the chill ast for each child Stmt *child = *I; - chillAST_node *n = ConvertGenericClangAST(child, chillCS); + chillAST_NodeList* nl = ConvertGenericClangAST(child); // usually n will be a statement. We just add it as a child. // SOME DeclStmts have multiple declarations. They will add themselves and return NULL - if (n) chillCS->addChild(n); + chillCS->addChildren(*nl); + delete nl; } - return chillCS; + NL_RET(chillCS); } -chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) { +chillAST_NodeList* ConvertFunctionDecl(FunctionDecl *D) { //fprintf(stderr, "\nConvertFunctionDecl( )\n"); QualType QT = D->getReturnType(); string ReturnTypeStr = QT.getAsString(); @@ -895,7 +902,7 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) { //fprintf(stderr, "function %s has type %s ", FuncName.c_str(), ReturnTypeStr.c_str()); //fprintf(stderr, "\n%s %s()\n", ReturnTypeStr.c_str(), FuncName.c_str()); - chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl(ReturnTypeStr.c_str(), FuncName.c_str(), p, D); + chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl(ReturnTypeStr.c_str(), FuncName.c_str(), NULL, D); int numparams = D->getNumParams(); @@ -907,14 +914,15 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) { QualType T = pvd->getOriginalType(); CHILL_DEBUG_PRINT("OTYPE %s\n", T.getAsString().c_str()); - chillAST_VarDecl *chillPVD = (chillAST_VarDecl *) ConvertVarDecl(clangvardecl, chillFD); + chillAST_NodeList* nl = ConvertVarDecl(clangvardecl); + chillAST_VarDecl* decl = (chillAST_VarDecl*)unwrap(nl); //chillPVD->print(); fflush(stdout); //chillPVD->isAParameter = 1; - VariableDeclarations.push_back(chillPVD); + VariableDeclarations.push_back(decl); - chillFD->addParameter(chillPVD); - CHILL_DEBUG_PRINT("chillAST ParmVarDecl for %s from chill location 0x%x\n", chillPVD->varname, clangvardecl); + chillFD->addParameter(decl); + CHILL_DEBUG_PRINT("chillAST ParmVarDecl for %s from chill location 0x%x\n", decl->varname, clangvardecl); } // for each parameter @@ -929,76 +937,63 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) { Stmt *clangbody = D->getBody(); if (clangbody) { // may just be fwd decl or external, without an actual body //fprintf(stderr, "body of type %s\n", clangbody->getStmtClassName()); - //chillAST_node *CB = ConvertCompoundStmt( dyn_cast<CompoundStmt>(clangbody) ); // always a compound statement? - chillAST_node *CB = ConvertGenericClangAST(clangbody, chillFD); + //chillAST_Node *CB = ConvertCompoundStmt( dyn_cast<CompoundStmt>(clangbody) ); // always a compound statement? + chillAST_NodeList* nl = ConvertGenericClangAST(clangbody); //fprintf(stderr, "FunctionDecl body = 0x%x of type %s\n", CB, CB->getTypeString()); - chillFD->setBody(CB); + chillFD->setBody(unwrap(nl)); } //fprintf(stderr, "adding function %s 0x%x to FunctionDeclarations\n", chillFD->functionName, chillFD); FunctionDeclarations.push_back(chillFD); - return chillFD; + NL_RET(chillFD); } -chillAST_node *ConvertForStmt(ForStmt *clangFS, chillAST_node *p) { - - Stmt *init = clangFS->getInit(); - Expr *cond = clangFS->getCond(); - Expr *incr = clangFS->getInc(); - Stmt *body = clangFS->getBody(); +chillAST_NodeList* ConvertForStmt(ForStmt *clangFS) { - chillAST_node *ini = ConvertGenericClangAST(init, NULL); - chillAST_node *con = ConvertGenericClangAST(cond, NULL); - chillAST_node *inc = ConvertGenericClangAST(incr, NULL); - chillAST_node *bod = ConvertGenericClangAST(body, NULL); - if (bod->asttype != CHILLAST_NODETYPE_COMPOUNDSTMT) { - //fprintf(stderr, "ForStmt body of type %s\n", bod->getTypeString()); + chillAST_Node *init = unwrap(ConvertGenericClangAST(clangFS->getInit())); + chillAST_Node *cond = unwrap(ConvertGenericClangAST(clangFS->getCond())); + chillAST_Node *incr = unwrap(ConvertGenericClangAST(clangFS->getInc())); + chillAST_Node *body = unwrap(ConvertGenericClangAST(clangFS->getBody())); + if (body->getType() != CHILLAST_NODE_COMPOUNDSTMT) { // make single statement loop bodies loop like other loops + CHILL_DEBUG_PRINT("ForStmt body of type %s\n", body->getTypeString()); chillAST_CompoundStmt *cs = new chillAST_CompoundStmt(); - cs->addChild(bod); - bod = cs; + cs->addChild(body); + body = cs; } - - - chillAST_ForStmt *chill_loop = new chillAST_ForStmt(ini, con, inc, bod, p); - ini->setParent(chill_loop); - con->setParent(chill_loop); - inc->setParent(chill_loop); - bod->setParent(chill_loop); - - return chill_loop; + chillAST_ForStmt *chill_loop = new chillAST_ForStmt(init, cond, incr, body, NULL); + NL_RET(chill_loop); } -chillAST_node *ConvertIfStmt(IfStmt *clangIS, chillAST_node *p) { +chillAST_NodeList* ConvertIfStmt(IfStmt *clangIS) { Expr *cond = clangIS->getCond(); Stmt *thenpart = clangIS->getThen(); Stmt *elsepart = clangIS->getElse(); - chillAST_node *con = ConvertGenericClangAST(cond, NULL); - chillAST_node *thn = NULL; - if (thenpart) thn = ConvertGenericClangAST(thenpart, NULL); - chillAST_node *els = NULL; - if (elsepart) els = ConvertGenericClangAST(elsepart, NULL); + chillAST_Node *con = unwrap(ConvertGenericClangAST(cond)); + chillAST_Node *thn = NULL; + if (thenpart) thn = unwrap(ConvertGenericClangAST(thenpart)); + chillAST_Node *els = NULL; + if (elsepart) els = unwrap(ConvertGenericClangAST(elsepart)); chillAST_IfStmt *ifstmt = new chillAST_IfStmt(con, thn, els, NULL); - return ifstmt; + NL_RET(ifstmt); } -chillAST_node *ConvertUnaryOperator(UnaryOperator *clangUO, chillAST_node *p) { +chillAST_NodeList* ConvertUnaryOperator(UnaryOperator *clangUO) { const char *op = unops[clangUO->getOpcode()].c_str(); bool pre = clangUO->isPrefix(); - chillAST_node *sub = ConvertGenericClangAST(clangUO->getSubExpr(), NULL); + chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangUO->getSubExpr())); - chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub, p); - sub->setParent(chillUO); - return chillUO; + chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub, NULL); + NL_RET(chillUO); } -chillAST_node *ConvertBinaryOperator(BinaryOperator *clangBO, chillAST_node *p) { +chillAST_NodeList* ConvertBinaryOperator(BinaryOperator *clangBO) { // get the clang parts Expr *lhs = clangBO->getLHS(); @@ -1007,37 +1002,34 @@ chillAST_node *ConvertBinaryOperator(BinaryOperator *clangBO, chillAST_node *p) // convert to chill equivalents - chillAST_node *l = ConvertGenericClangAST(lhs, NULL); + chillAST_Node *l = unwrap(ConvertGenericClangAST(lhs)); const char *opstring = binops[op].c_str(); - chillAST_node *r = ConvertGenericClangAST(rhs, NULL); + chillAST_Node *r = unwrap(ConvertGenericClangAST(rhs)); // TODO chill equivalent for numeric op. // build up the chill Binary Op AST node - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r, p); - l->setParent(binop); - r->setParent(binop); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r, NULL); - return binop; + NL_RET(binop); } -chillAST_node *ConvertArraySubscriptExpr(ArraySubscriptExpr *clangASE, chillAST_node *p) { +chillAST_NodeList* ConvertArraySubscriptExpr(ArraySubscriptExpr *clangASE) { Expr *clangbase = clangASE->getBase(); Expr *clangindex = clangASE->getIdx(); //fprintf(stderr, "clang base: "); clangbase->dump(); fprintf(stderr, "\n"); - chillAST_node *bas = ConvertGenericClangAST(clangbase, NULL); - chillAST_node *indx = ConvertGenericClangAST(clangindex, NULL); + chillAST_Node *bas = unwrap(ConvertGenericClangAST(clangbase)); + chillAST_Node *indx = unwrap(ConvertGenericClangAST(clangindex)); - chillAST_ArraySubscriptExpr *chillASE = new chillAST_ArraySubscriptExpr(bas, indx, p, clangASE); - bas->setParent(chillASE); - indx->setParent(chillASE); - return chillASE; + // TODO clangAST contamination + chillAST_ArraySubscriptExpr *chillASE = new chillAST_ArraySubscriptExpr(bas, indx, NULL, clangASE); + NL_RET(chillASE); } -chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { +chillAST_NodeList* ConvertDeclRefExpr(DeclRefExpr *clangDRE) { DeclarationNameInfo DNI = clangDRE->getNameInfo(); ValueDecl *vd = static_cast<ValueDecl *>(clangDRE->getDecl()); // ValueDecl ?? VarDecl ?? @@ -1049,7 +1041,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { DeclarationName DN = DNI.getName(); const char *varname = DN.getAsString().c_str(); - chillAST_DeclRefExpr *chillDRE = new chillAST_DeclRefExpr(TypeStr.c_str(), varname, p); + chillAST_DeclRefExpr *chillDRE = new chillAST_DeclRefExpr(TypeStr.c_str(), varname, NULL); //fprintf(stderr, "clang DeclRefExpr refers to declaration of %s @ 0x%x\n", varname, vd); //fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName()); @@ -1082,7 +1074,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { exit(-1); } - chillDRE->decl = (chillAST_node *) chillvd; // start of spaghetti pointers ... + chillDRE->decl = (chillAST_Node *) chillvd; // start of spaghetti pointers ... } else if (!strcmp("Function", vd->getDeclKindName())) { //fprintf(stderr, "declrefexpr of type Function\n"); int numfuncs = FunctionDeclarations.size(); @@ -1098,7 +1090,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { exit(-1); } - chillDRE->decl = (chillAST_node *) chillfd; // start of spaghetti pointers ... + chillDRE->decl = (chillAST_Node *) chillfd; // start of spaghetti pointers ... } else { fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName()); @@ -1106,23 +1098,23 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { exit(-1); } - //fprintf(stderr, "%s\n", DN.getAsString().c_str()); - return chillDRE; + //fprintf(stderr, "%s\n", DN.getAsString().c_str()); + NL_RET(chillDRE); } -chillAST_node *ConvertIntegerLiteral(IntegerLiteral *clangIL, chillAST_node *p) { +chillAST_NodeList* ConvertIntegerLiteral(IntegerLiteral *clangIL) { bool isSigned = clangIL->getType()->isSignedIntegerType(); //int val = clangIL->getIntValue(); const char *printable = clangIL->getValue().toString(10, isSigned).c_str(); int val = atoi(printable); //fprintf(stderr, "int value %s (%d)\n", printable, val); - chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral(val, p); - return chillIL; + chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral(val, NULL); + NL_RET(chillIL); } -chillAST_node *ConvertFloatingLiteral(FloatingLiteral *clangFL, chillAST_node *p) { +chillAST_NodeList* ConvertFloatingLiteral(FloatingLiteral *clangFL) { //fprintf(stderr, "\nConvertFloatingLiteral()\n"); float val = clangFL->getValueAsApproximateDouble(); // TODO approx is a bad idea! string WHAT; @@ -1186,30 +1178,29 @@ chillAST_node *ConvertFloatingLiteral(FloatingLiteral *clangFL, chillAST_node *p buf[len] = '\0'; //fprintf(stderr, "'%s'\n", buf); - chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf, p); + chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf, NULL); - //chillFL->print(); printf("\n"); fflush(stdout); - return chillFL; + //chillFL->print(); printf("\n"); fflush(stdout); + NL_RET(chillFL); } -chillAST_node *ConvertImplicitCastExpr(ImplicitCastExpr *clangICE, chillAST_node *p) { +chillAST_NodeList* ConvertImplicitCastExpr(ImplicitCastExpr *clangICE) { //fprintf(stderr, "ConvertImplicitCastExpr()\n"); CastExpr *CE = dyn_cast<ImplicitCastExpr>(clangICE); //fprintf(stderr, "implicit cast of type %s\n", CE->getCastKindName()); - chillAST_node *sub = ConvertGenericClangAST(clangICE->getSubExpr(), p); - chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub, p); + chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangICE->getSubExpr())); + chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub, NULL); //sub->setParent( chillICE ); // these 2 lines work //return chillICE; - //sub->setParent(p); // ignore the ImplicitCastExpr !! TODO (probably a bad idea) - return sub; - + //sub->setParent(p); // ignore the ImplicitCastExpr !! TODO (probably a bad idea) + NL_RET(chillICE); } -chillAST_node *ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE, chillAST_node *p) { +chillAST_NodeList* ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE) { //fprintf(stderr, "ConvertCStyleCastExpr()\n"); //fprintf(stderr, "C Style cast of kind "); CastExpr *CE = dyn_cast<CastExpr>(clangCSCE); @@ -1219,58 +1210,54 @@ chillAST_node *ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE, chillAST_node *p const char *towhat = strdup(clangCSCE->getTypeAsWritten().getAsString().c_str()); //fprintf(stderr, "before sub towhat (%s)\n", towhat); - chillAST_node *sub = ConvertGenericClangAST(clangCSCE->getSubExprAsWritten(), NULL); + chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangCSCE->getSubExprAsWritten())); //fprintf(stderr, "after sub towhat (%s)\n", towhat); - chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub, p); + chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub, NULL); //fprintf(stderr, "after CSCE towhat (%s)\n", towhat); - sub->setParent(chillCSCE); - return chillCSCE; + NL_RET(chillCSCE); } -chillAST_node *ConvertReturnStmt(ReturnStmt *clangRS, chillAST_node *p) { - chillAST_node *retval = ConvertGenericClangAST(clangRS->getRetValue(), NULL); // NULL is handled +chillAST_NodeList* ConvertReturnStmt(ReturnStmt *clangRS) { + chillAST_Node *retval = unwrap(ConvertGenericClangAST(clangRS->getRetValue())); // NULL is handled //if (retval == NULL) fprintf(stderr, "return stmt returns nothing\n"); - chillAST_ReturnStmt *chillRS = new chillAST_ReturnStmt(retval, p); - if (retval) retval->setParent(chillRS); - return chillRS; + chillAST_ReturnStmt *chillRS = new chillAST_ReturnStmt(retval, NULL); + NL_RET(chillRS); } -chillAST_node *ConvertCallExpr(CallExpr *clangCE, chillAST_node *p) { +chillAST_NodeList* ConvertCallExpr(CallExpr *clangCE) { //fprintf(stderr, "ConvertCallExpr()\n"); - chillAST_node *callee = ConvertGenericClangAST(clangCE->getCallee(), NULL); + chillAST_Node *callee = unwrap(ConvertGenericClangAST(clangCE->getCallee())); //fprintf(stderr, "callee is of type %s\n", callee->getTypeString()); - //chillAST_node *next = ((chillAST_ImplicitCastExpr *)callee)->subexpr; + //chillAST_Node *next = ((chillAST_ImplicitCastExpr *)callee)->subexpr; //fprintf(stderr, "callee is of type %s\n", next->getTypeString()); - chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee, p); - callee->setParent(chillCE); + chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee, NULL); int numargs = clangCE->getNumArgs(); //fprintf(stderr, "CallExpr has %d args\n", numargs); Expr **clangargs = clangCE->getArgs(); for (int i = 0; i < numargs; i++) { - chillCE->addArg(ConvertGenericClangAST(clangargs[i], chillCE)); + chillCE->addArg(unwrap(ConvertGenericClangAST(clangargs[i]))); } - return chillCE; + NL_RET(chillCE); } -chillAST_node *ConvertParenExpr(ParenExpr *clangPE, chillAST_node *p) { - chillAST_node *sub = ConvertGenericClangAST(clangPE->getSubExpr(), NULL); - chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub, p); - sub->setParent(chillPE); +chillAST_NodeList* ConvertParenExpr(ParenExpr *clangPE) { + chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangPE->getSubExpr())); + chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub, NULL); - return chillPE; + NL_RET(chillPE); } -chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) { +chillAST_NodeList* ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) { //fprintf(stderr, "ConvertTranslationUnit( filename %s )\n\n", filename); // TUD derived from Decl and DeclContext static DeclContext *DC = TUD->castToDeclContext(TUD); @@ -1297,20 +1284,20 @@ chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) Decl *D = *DI; if (isa<FunctionDecl>(D)) { //fprintf(stderr, "\nTUD FunctionDecl\n"); - topnode->addChild(ConvertFunctionDecl(dyn_cast<FunctionDecl>(D), topnode)); + topnode->addChild(unwrap(ConvertFunctionDecl(dyn_cast<FunctionDecl>(D)))); } else if (isa<VarDecl>(D)) { //fprintf(stderr, "\nTUD VarDecl\n"); - topnode->addChild(ConvertVarDecl(dyn_cast<VarDecl>(D), topnode)); + topnode->addChild(unwrap(ConvertVarDecl(dyn_cast<VarDecl>(D)))); //fflush(stdout); fprintf(stderr, "\nTUD VarDecl DONE\n"); } else if (isa<TypedefDecl>(D)) { //fprintf(stderr, "\nTUD TypedefDecl\n"); - topnode->addChild(ConvertTypeDefDecl(dyn_cast<TypedefDecl>(D), topnode)); + topnode->addChild(unwrap(ConvertTypeDefDecl(dyn_cast<TypedefDecl>(D)))); } else if (isa<RecordDecl>(D)) { - fprintf(stderr, "\nTUD RecordDecl\n"); - topnode->addChild(ConvertRecordDecl(dyn_cast<RecordDecl>(D), topnode)); + CHILL_DEBUG_PRINT("\nTUD RecordDecl\n"); + topnode->addChild(unwrap(ConvertRecordDecl(dyn_cast<RecordDecl>(D)))); } else if (isa<TypeAliasDecl>(D)) { - fprintf(stderr, "TUD TypeAliasDecl TODO \n"); + CHILL_ERROR("TUD TypeAliasDecl TODO \n"); exit(-1); } else { - fprintf(stderr, "\nTUD a declaration of type %s (%d) which I can't handle\n", D->getDeclKindName(), D->getKind()); + CHILL_ERROR("\nTUD a declaration of type %s (%d) which I can't handle\n", D->getDeclKindName(), D->getKind()); exit(-1); } } @@ -1318,11 +1305,11 @@ chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) //fprintf(stderr, "in ConvertTranslationUnit(), dumping the file\n"); //topnode->dump(); - return (chillAST_node *) topnode; + NL_RET(topnode); } -chillAST_node *ConvertGenericClangAST(Stmt *s, chillAST_node *p) { +chillAST_NodeList* ConvertGenericClangAST(Stmt *s) { if (s == NULL) return NULL; //fprintf(stderr, "\nConvertGenericClangAST() Stmt of type %d (%s)\n", s->getStmtClass(),s->getStmtClassName()); @@ -1330,40 +1317,40 @@ chillAST_node *ConvertGenericClangAST(Stmt *s, chillAST_node *p) { //if (isa<Decl>(D)) fprintf(stderr, "Decl of kind %d (%s)\n", D->getKind(),D->getDeclKindName() ); - chillAST_node *ret = NULL; + chillAST_NodeList *ret = NULL; // find the SINGLE constant or data reference at this node or below if (isa<CompoundStmt>(s)) { - ret = ConvertCompoundStmt(dyn_cast<CompoundStmt>(s), p); + ret = ConvertCompoundStmt(dyn_cast<CompoundStmt>(s)); } else if (isa<DeclStmt>(s)) { - ret = ConvertDeclStmt(dyn_cast<DeclStmt>(s), p); + ret = ConvertDeclStmt(dyn_cast<DeclStmt>(s)); } else if (isa<ForStmt>(s)) { - ret = ConvertForStmt(dyn_cast<ForStmt>(s), p); + ret = ConvertForStmt(dyn_cast<ForStmt>(s)); } else if (isa<BinaryOperator>(s)) { - ret = ConvertBinaryOperator(dyn_cast<BinaryOperator>(s), p); + ret = ConvertBinaryOperator(dyn_cast<BinaryOperator>(s)); } else if (isa<ArraySubscriptExpr>(s)) { - ret = ConvertArraySubscriptExpr(dyn_cast<ArraySubscriptExpr>(s), p); + ret = ConvertArraySubscriptExpr(dyn_cast<ArraySubscriptExpr>(s)); } else if (isa<DeclRefExpr>(s)) { - ret = ConvertDeclRefExpr(dyn_cast<DeclRefExpr>(s), p); + ret = ConvertDeclRefExpr(dyn_cast<DeclRefExpr>(s)); } else if (isa<FloatingLiteral>(s)) { - ret = ConvertFloatingLiteral(dyn_cast<FloatingLiteral>(s), p); + ret = ConvertFloatingLiteral(dyn_cast<FloatingLiteral>(s)); } else if (isa<IntegerLiteral>(s)) { - ret = ConvertIntegerLiteral(dyn_cast<IntegerLiteral>(s), p); + ret = ConvertIntegerLiteral(dyn_cast<IntegerLiteral>(s)); } else if (isa<UnaryOperator>(s)) { - ret = ConvertUnaryOperator(dyn_cast<UnaryOperator>(s), p); + ret = ConvertUnaryOperator(dyn_cast<UnaryOperator>(s)); } else if (isa<ImplicitCastExpr>(s)) { - ret = ConvertImplicitCastExpr(dyn_cast<ImplicitCastExpr>(s), p); + ret = ConvertImplicitCastExpr(dyn_cast<ImplicitCastExpr>(s)); } else if (isa<CStyleCastExpr>(s)) { - ret = ConvertCStyleCastExpr(dyn_cast<CStyleCastExpr>(s), p); + ret = ConvertCStyleCastExpr(dyn_cast<CStyleCastExpr>(s)); } else if (isa<ReturnStmt>(s)) { - ret = ConvertReturnStmt(dyn_cast<ReturnStmt>(s), p); + ret = ConvertReturnStmt(dyn_cast<ReturnStmt>(s)); } else if (isa<CallExpr>(s)) { - ret = ConvertCallExpr(dyn_cast<CallExpr>(s), p); + ret = ConvertCallExpr(dyn_cast<CallExpr>(s)); } else if (isa<ParenExpr>(s)) { - ret = ConvertParenExpr(dyn_cast<ParenExpr>(s), p); + ret = ConvertParenExpr(dyn_cast<ParenExpr>(s)); } else if (isa<IfStmt>(s)) { - ret = ConvertIfStmt(dyn_cast<IfStmt>(s), p); + ret = ConvertIfStmt(dyn_cast<IfStmt>(s)); } else if (isa<MemberExpr>(s)) { - ret = ConvertMemberExpr(dyn_cast<MemberExpr>(s), p); + ret = ConvertMemberExpr(dyn_cast<MemberExpr>(s)); // these can only happen at the top level? @@ -1611,7 +1598,7 @@ IR_ArraySymbol *IR_chillArrayRef::symbol() const { //fprintf(stderr, "base: "); chillASE->base->print(); printf("\n"); fflush(stdout); - chillAST_node *mb = chillASE->multibase(); + chillAST_Node *mb = chillASE->multibase(); chillAST_VarDecl *vd = (chillAST_VarDecl *) mb; //fprintf(stderr, "symbol: '%s'\n", vd->varname); @@ -1621,22 +1608,22 @@ IR_ArraySymbol *IR_chillArrayRef::symbol() const { //fprintf(stderr, "ir_clang.cc returning IR_chillArraySymbol 0x%x\n", AS); return AS; /* - chillAST_node *b = chillASE->base; + chillAST_Node *b = chillASE->base; fprintf(stderr, "base of type %s\n", b->getTypeString()); //b->print(); printf("\n"); fflush(stdout); - if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { + if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { b = ((chillAST_ImplicitCastExpr*)b)->subexpr; fprintf(stderr, "base of type %s\n", b->getTypeString()); } - if (b->asttype == CHILLAST_NODETYPE_DECLREFEXPR) { + if (b->getType() == CHILLAST_NODE_DECLREFEXPR) { if (NULL == ((chillAST_DeclRefExpr*)b)->decl) { fprintf(stderr, "IR_chillArrayRef::symbol() var decl = 0x%x\n", ((chillAST_DeclRefExpr*)b)->decl); exit(-1); } return new IR_chillArraySymbol(ir_, ((chillAST_DeclRefExpr*)b)->decl); // -> decl? } - if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { // multidimensional array + if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { // multidimensional array return ( } fprintf(stderr, "IR_chillArrayRef::symbol() can't handle\n"); @@ -1726,25 +1713,25 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) { chillupperbound = cond->getRHS(); conditionoperator = achillforstmt->conditionoperator; - chillAST_node *inc = chillforstmt->getInc(); + chillAST_Node *inc = chillforstmt->getInc(); // check the increment //fprintf(stderr, "increment is of type %s\n", inc->getTypeString()); //inc->print(); printf("\n"); fflush(stdout); - if (inc->asttype == CHILLAST_NODETYPE_UNARYOPERATOR) { + if (inc->getType() == CHILLAST_NODE_UNARYOPERATOR) { if (!strcmp(((chillAST_UnaryOperator *) inc)->op, "++")) step_size_ = 1; else step_size_ = -1; - } else if (inc->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) { + } else if (inc->getType() == CHILLAST_NODE_BINARYOPERATOR) { int beets = false; // slang chillAST_BinaryOperator *bop = (chillAST_BinaryOperator *) inc; if (bop->isAssignmentOp()) { // I=I+1 or similar - chillAST_node *rhs = bop->getRHS(); // (I+1) + chillAST_Node *rhs = bop->getRHS(); // (I+1) // TODO looks like this will fail for I=1+I or I=J+1 etc. do more checking char *assop = bop->getOp(); //fprintf(stderr, "'%s' is an assignment op\n", bop->getOp()); if (streq(assop, "+=") || streq(assop, "-=")) { - chillAST_node *stride = rhs; + chillAST_Node *stride = rhs; //fprintf(stderr, "stride is of type %s\n", stride->getTypeString()); if (stride->isIntegerLiteral()) { int val = ((chillAST_IntegerLiteral *) stride)->value; @@ -1754,7 +1741,7 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) { } else beets = true; // += or -= but not constant stride } else if (rhs->isBinaryOperator()) { chillAST_BinaryOperator *binoprhs = (chillAST_BinaryOperator *) rhs; - chillAST_node *intlit = binoprhs->getRHS(); + chillAST_Node *intlit = binoprhs->getRHS(); if (intlit->isIntegerLiteral()) { int val = ((chillAST_IntegerLiteral *) intlit)->value; if (!strcmp(binoprhs->getOp(), "+")) step_size_ = val; @@ -1881,13 +1868,13 @@ void IR_chillBlock::dump() const { } //StmtList -vector<chillAST_node *> IR_chillBlock::getStmtList() const { +vector<chillAST_Node *> IR_chillBlock::getStmtList() const { fprintf(stderr, "IR_xxxxBlock::getStmtList()\n"); return statements; // ?? } -void IR_chillBlock::addStatement(chillAST_node *s) { +void IR_chillBlock::addStatement(chillAST_Node *s) { statements.push_back(s); } @@ -1921,10 +1908,10 @@ class NULLASTConsumer : public ASTConsumer { }; -void findmanually(chillAST_node *node, char *procname, std::vector<chillAST_node *> &procs) { +void findmanually(chillAST_Node *node, char *procname, std::vector<chillAST_Node *> &procs) { //fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString()); - if (node->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) { + if (node->getType() == CHILLAST_NODE_FUNCTIONDECL) { char *name = ((chillAST_FunctionDecl *) node)->functionName; //fprintf(stderr, "node name 0x%x ", name); //fprintf(stderr, "%s procname ", name); @@ -2078,7 +2065,7 @@ aClangCompiler::aClangCompiler(char *filename) { // create another AST, very similar to the clang AST but not written by idiots CHILL_DEBUG_PRINT("converting entire clang AST into chill AST (ir_clang.cc)\n"); - chillAST_node *wholefile = ConvertTranslationUnit(TUD, filename); + chillAST_Node *wholefile = unwrap(ConvertTranslationUnit(TUD, filename)); fflush(stdout); //fprintf(stderr, "printing whole file\n"); @@ -2140,7 +2127,7 @@ chillAST_FunctionDecl *aClangCompiler::findprocedurebyname(char *procname) { //fprintf(stderr, "searching through files in the clang AST\n\n"); //fprintf(stderr, "astContext_ 0x%x\n", astContext_); - std::vector<chillAST_node *> procs; + std::vector<chillAST_Node *> procs; findmanually(entire_file_AST, procname, procs); //fprintf(stderr, "procs has %d members\n", procs.size()); @@ -2267,7 +2254,7 @@ IR_clangCode::IR_clangCode(const char *fname, const char *proc_name) : IR_Code() pInstance->setCurrentFunction(localFD); - chillAST_node *b = localFD->getBody(); // we do this just because it will get done next + chillAST_Node *b = localFD->getBody(); // we do this just because it will get done next CHILL_DEBUG_PRINT("calling new CG_chillBuilder() umwut?\n"); ocg_ = new omega::CG_chillBuilder(); // ocg == omega code gen @@ -2300,7 +2287,7 @@ IR_clangCode::~IR_clangCode() { // TODO should output the entire file, not just the function we're working on chillAST_SourceFile *src = chillfunc->getSourceFile(); - //chillAST_node *p = chillfunc->parent; // should be translationDeclUnit + //chillAST_Node *p = chillfunc->parent; // should be translationDeclUnit if (src) { //src->print(); // tmp if (src->isSourceFile()) src->printToFile(); @@ -2319,7 +2306,7 @@ IR_ScalarSymbol *IR_clangCode::CreateScalarSymbol(const IR_Symbol *sym, int i) { // do we have to check to see if it's already there? VariableDeclarations.push_back(vd); - chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ?? + chillAST_Node *bod = chillfunc->getBody(); // always a compoundStmt ?? bod->insertChild(0, vd); fprintf(stderr, "returning ... really\n"); return new IR_chillScalarSymbol(this, CSS->chillvd); // CSS->clone(); @@ -2392,7 +2379,7 @@ IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outp exit(-1); } - chillAST_node *nodezero = CR->chillnodes[0]; + chillAST_Node *nodezero = CR->chillnodes[0]; if (!nodezero->isIntegerLiteral()) { fprintf(stderr, "IR_clangCode::CreateArraySymbol() array dimension %d not an IntegerLiteral\n", i); exit(-1); @@ -2410,7 +2397,7 @@ IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outp // put decl in some symbol table VariableDeclarations.push_back(vd); // insert decl in the IR_code body - chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ?? + chillAST_Node *bod = chillfunc->getBody(); // always a compoundStmt ?? bod->insertChild(0, vd); return new IR_chillArraySymbol(this, vd); @@ -2449,7 +2436,7 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector const IR_chillArraySymbol *c_sym = static_cast<const IR_chillArraySymbol *>(sym); chillAST_VarDecl *vd = c_sym->chillvd; - std::vector<chillAST_node *> inds; + std::vector<chillAST_Node *> inds; //fprintf(stderr, "%d array indeces\n", sym->n_dim()); for (int i = 0; i < index.size(); i++) { @@ -2466,7 +2453,7 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector inds.push_back(CR->chillnodes[0]); /* - chillAST_node *nodezero = CR->chillnodes[0]; + chillAST_Node *nodezero = CR->chillnodes[0]; if (!nodezero->isIntegerLiteral()) { fprintf(stderr,"IR_clangCode::CreateArrayRef() array dimension %d not an IntegerLiteral\n",i); fprintf(stderr, "it is a %s\n", nodezero->getTypeString()); @@ -2495,7 +2482,7 @@ std::vector<IR_ArrayRef *> IR_clangCode::FindArrayRef(const omega::CG_outputRepr //fprintf(stderr, "FindArrayRef()\n"); std::vector<IR_ArrayRef *> arrays; const omega::CG_chillRepr *crepr = static_cast<const omega::CG_chillRepr *>(repr); - std::vector<chillAST_node *> chillstmts = crepr->getChillCode(); + std::vector<chillAST_Node *> chillstmts = crepr->getChillCode(); //fprintf(stderr, "there are %d chill statements in this repr\n", chillstmts.size()); @@ -2591,7 +2578,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl std::vector<IR_Control *> controls; - chillAST_node *blockast = NULL; + chillAST_Node *blockast = NULL; int numstmts = CB->statements.size(); CHILL_DEBUG_PRINT("%d statements\n", numstmts); @@ -2609,7 +2596,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl CHILL_DEBUG_END - //vector<chillAST_node *> funcchildren = chillfunc->getChildren(); + //vector<chillAST_Node *> funcchildren = chillfunc->getChildren(); //fprintf(stderr, "%d children of clangcode\n", funcchildren.size()); // includes parameters // build up a vector of "controls". @@ -2617,10 +2604,10 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl // bundled up into an IR_Block // ifs and loops will get their own entry - std::vector<chillAST_node *> children; + std::vector<chillAST_Node *> children; - if (blockast->asttype == CHILLAST_NODETYPE_FORSTMT) { + if (blockast->getType() == CHILLAST_NODE_FORSTMT) { CHILL_DEBUG_BEGIN fflush(stdout); fprintf(stderr, "found a top level For statement (Loop)\n"); @@ -2631,17 +2618,17 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) blockast)); } - //else if (blockast->asttype == CHILLAST_NODETYPE_IFSTMT) { + //else if (blockast->getType() == CHILLAST_NODE_IFSTMT) { // controls.push_back( new IR_clangIf( this, (chillAST_IfStmt *)blockast)); //} - else if (blockast->asttype == CHILLAST_NODETYPE_COMPOUNDSTMT || - blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) { + else if (blockast->getType() == CHILLAST_NODE_COMPOUNDSTMT || + blockast->getType() == CHILLAST_NODE_FUNCTIONDECL) { - if (blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) { - //fprintf(stderr, "ir_clanc.cc blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL\n"); + if (blockast->getType() == CHILLAST_NODE_FUNCTIONDECL) { + //fprintf(stderr, "ir_clanc.cc blockast->getType() == CHILLAST_NODE_FUNCTIONDECL\n"); chillAST_FunctionDecl *FD = (chillAST_FunctionDecl *) blockast; - chillAST_node *bod = FD->getBody(); + chillAST_Node *bod = FD->getBody(); //fprintf(stderr, "bod 0x%x\n", bod); children = bod->getChildren(); @@ -2667,8 +2654,8 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl IR_chillBlock *basicblock = new IR_chillBlock(this); // no statements for (int i = 0; i < numchildren; i++) { //fprintf(stderr, "child %d is of type %s\n", i, children[i]->getTypeString()); - CHILL_ASTNODE_TYPE typ = children[i]->asttype; - if (typ == CHILLAST_NODETYPE_LOOP) { + CHILLAST_NODE_TYPE typ = children[i]->getType(); + if (typ == CHILLAST_NODE_LOOP) { if (numchildren == 1) { CHILL_DEBUG_PRINT("found a For statement (Loop)\n"); } else { @@ -2687,7 +2674,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) children[i])); } - //else if (typ == CHILLAST_NODETYPE_IFSTMT ) // TODO + //else if (typ == CHILLAST_NODE_IFSTMT ) // TODO else { // straight line code basicblock->addStatement(children[i]); CHILL_DEBUG_BEGIN @@ -2730,8 +2717,8 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C IR_chillBlock *CBlock = new IR_chillBlock(controls[0]->ir_); // the thing we're building - std::vector<chillAST_node *> statements; - chillAST_node *parent = NULL; + std::vector<chillAST_Node *> statements; + chillAST_Node *parent = NULL; for (int i = 0; i < controls.size(); i++) { switch (controls[i]->type()) { case IR_CONTROL_LOOP: { @@ -2750,7 +2737,7 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C case IR_CONTROL_BLOCK: { CHILL_DEBUG_PRINT("control %d is IR_CONTROL_BLOCK\n", i); IR_chillBlock *CB = static_cast<IR_chillBlock *>(controls[i]); - std::vector<chillAST_node *> blockstmts = CB->statements; + std::vector<chillAST_Node *> blockstmts = CB->statements; for (int j = 0; j < blockstmts.size(); j++) { if (parent == NULL) { parent = blockstmts[j]->parent; @@ -2778,7 +2765,7 @@ IR_Block *IR_clangCode::GetCode() const { // return IR_Block corresponding to //Stmt *s = func_->getBody(); // clang statement, and clang getBody //fprintf(stderr, "chillfunc 0x%x\n", chillfunc); - //chillAST_node *bod = chillfunc->getBody(); // chillAST + //chillAST_Node *bod = chillfunc->getBody(); // chillAST //fprintf(stderr, "printing the function getBody()\n"); //fprintf(stderr, "sourceManager 0x%x\n", sourceManager); //bod->print(); @@ -2792,7 +2779,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { fprintf(stderr, "IR_xxxxCode::ReplaceCode( old, *repr)\n"); CG_chillRepr *chillrepr = (CG_chillRepr *) repr; - std::vector<chillAST_node *> newcode = chillrepr->getChillCode(); + std::vector<chillAST_Node *> newcode = chillrepr->getChillCode(); int numnew = newcode.size(); //fprintf(stderr, "new code (%d) is\n", numnew); @@ -2855,7 +2842,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { } } - chillAST_node *par; + chillAST_Node *par; switch (old->type()) { case IR_CONTROL_LOOP: { //fprintf(stderr, "old is IR_CONTROL_LOOP\n"); @@ -2886,7 +2873,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { fflush(stdout); fprintf(stderr, "\n}\n"); - std::vector<chillAST_node *> oldparentcode = par->getChildren(); // probably only works for compoundstmts + std::vector<chillAST_Node *> oldparentcode = par->getChildren(); // probably only works for compoundstmts //fprintf(stderr, "ir_clang.cc oldparentcode\n"); // find loop in the parent @@ -2940,7 +2927,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { //fprintf(stderr, "\nafter inserting %d statements into the Clang IR,", numnew); CHILL_DEBUG_BEGIN fprintf(stderr, "new parent2 is\n\n{\n"); - std::vector<chillAST_node *> newparentcode = par->getChildren(); + std::vector<chillAST_Node *> newparentcode = par->getChildren(); for (int i = 0; i < newparentcode.size(); i++) { fflush(stdout); //fprintf(stderr, "%d ", i); @@ -2973,7 +2960,7 @@ void IR_clangCode::ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) { //exit(-1); } - chillAST_node *newthing = crepr->chillnodes[0]; + chillAST_Node *newthing = crepr->chillnodes[0]; fprintf(stderr, "with new "); newthing->print(); printf("\n\n"); @@ -3032,7 +3019,7 @@ IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *re //fprintf(stderr, "IR_clangCode::QueryExpOperation()\n"); CG_chillRepr *crepr = (CG_chillRepr *) repr; - chillAST_node *node = crepr->chillnodes[0]; + chillAST_Node *node = crepr->chillnodes[0]; //fprintf(stderr, "chillAST node type %s\n", node->getTypeString()); // really need to be more rigorous than this hack // TODO @@ -3104,7 +3091,7 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C CG_chillRepr *crepr = (CG_chillRepr *) repr; //Expr *e = static_cast<const omega::CG_chillRepr *>(repr)->GetExpression(); wrong.. CLANG - chillAST_node *e = crepr->chillnodes[0]; // ?? + chillAST_Node *e = crepr->chillnodes[0]; // ?? //e->print(); printf("\n"); fflush(stdout); // really need to be more rigorous than this hack // TODO @@ -3200,7 +3187,7 @@ Expr *op1, *op2; IR_Ref *IR_clangCode::Repr2Ref(const omega::CG_outputRepr *repr) const { CG_chillRepr *crepr = (CG_chillRepr *) repr; - chillAST_node *node = crepr->chillnodes[0]; + chillAST_Node *node = crepr->chillnodes[0]; //Expr *e = static_cast<const omega::CG_chillRep *>(repr)->GetExpression(); @@ -3221,13 +3208,13 @@ IR_Ref *IR_clangCode::Repr2Ref(const omega::CG_outputRepr *repr) const { } } -chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *) { +chillAST_NodeList* ConvertMemberExpr(clang::MemberExpr *clangME) { fprintf(stderr, "ConvertMemberExpr()\n"); clang::Expr *E = clangME->getBase(); E->dump(); - chillAST_node *base = ConvertGenericClangAST(clangME->getBase(), NULL); + chillAST_Node *base = unwrap(ConvertGenericClangAST(clangME->getBase())); DeclarationNameInfo memnameinfo = clangME->getMemberNameInfo(); DeclarationName DN = memnameinfo.getName(); @@ -3240,6 +3227,6 @@ chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *) { ME->print(); fprintf(stderr, "\n"); - return ME; + NL_RET(ME); } diff --git a/src/omegatools.cc b/src/omegatools.cc index c7233c8..07b12f5 100644 --- a/src/omegatools.cc +++ b/src/omegatools.cc @@ -613,7 +613,7 @@ void exp2formula(IR_Code *ir, CG_chillRepr *CR = (CG_chillRepr *) v[0]; // cheat for now. we should not know this is a chillRepr //fprintf(stderr, "v "); CR->dump(); fflush(stdout); //fprintf(stderr, "v "); v[0]->dump(); /* printf("\n"); */ fflush(stdout); - chillAST_node *node = CR->GetCode(); + chillAST_Node *node = CR->GetCode(); //fprintf(stderr, "\n**** walking parents!\n"); @@ -695,7 +695,7 @@ void exp2formula(IR_Code *ir, // r is enclosing relation, we build another that will include Variable_ID e = find_index(r, s, side); // s is the array named "index" - std::vector<chillAST_node *> internals = ((CG_chillRepr *) v[0])->getChillCode(); + std::vector<chillAST_Node *> internals = ((CG_chillRepr *) v[0])->getChillCode(); int numnodes = internals.size(); // always 1? std::vector<chillAST_DeclRefExpr *> dres; std::vector<chillAST_VarDecl *> decls; |