diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-23 22:02:47 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-23 22:02:47 -0600 |
commit | ddf5a43a66a91009e7fa33a689aac45e73c4dc97 (patch) | |
tree | dbb1376238c94d2a4a18a52b75f336ae61654d99 | |
parent | 2f96d12dd05213276875d56fec361ff99ec9bd76 (diff) | |
download | chill-ddf5a43a66a91009e7fa33a689aac45e73c4dc97.tar.gz chill-ddf5a43a66a91009e7fa33a689aac45e73c4dc97.tar.bz2 chill-ddf5a43a66a91009e7fa33a689aac45e73c4dc97.zip |
staging
-rw-r--r-- | include/chillAST/chillAST_def.hh | 32 | ||||
-rw-r--r-- | include/chillAST/chillAST_node.hh | 17 | ||||
-rw-r--r-- | include/chillAST/chillASTs.hh | 138 | ||||
-rwxr-xr-x | lib/chillcg/src/CG_chillBuilder.cc | 81 | ||||
-rw-r--r-- | src/chillASTs.cc | 1040 | ||||
-rwxr-xr-x | src/ir_clang.cc | 64 |
6 files changed, 344 insertions, 1028 deletions
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh index 289b835..7d729d6 100644 --- a/include/chillAST/chillAST_def.hh +++ b/include/chillAST/chillAST_def.hh @@ -16,12 +16,10 @@ #include <ir_enums.hh> // for IR_CONDITION_* -#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_TRANSLATIONUNIT = 1, + CHILLAST_NODE_SOURCEFILE = 1, CHILLAST_NODE_TYPEDEFDECL, CHILLAST_NODE_VARDECL, // CHILLAST_NODE_PARMVARDECL, not used any more @@ -29,7 +27,8 @@ enum CHILLAST_NODE_TYPE { CHILLAST_NODE_RECORDDECL, // struct or union (or class) CHILLAST_NODE_MACRODEFINITION, CHILLAST_NODE_COMPOUNDSTMT, - CHILLAST_NODE_LOOP, // AKA ForStmt + CHILLAST_NODE_LOOP = 8, + CHILLAST_NODE_FORSTMT = 8, CHILLAST_NODE_TERNARYOPERATOR, CHILLAST_NODE_BINARYOPERATOR, CHILLAST_NODE_UNARYOPERATOR, @@ -88,7 +87,7 @@ enum CHILLAST_PREPROCESSING_POSITION { // when tied to another statement CHILLAST_PREPROCESSING_IMMEDIATELYBEFORE // on same line }; -char *parseUnderlyingType(char *sometype); +char *parseUnderlyingType(const char *sometype); char *parseArrayParts(char *sometype); @@ -175,24 +174,23 @@ 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 +typedef std::vector<chillAST_VarDecl *> chillAST_SymbolTable; +typedef std::vector<chillAST_TypedefDecl *> chillAST_TypedefTable; -chillAST_VarDecl *symbolTableFindName(chillAST_SymbolTable *table, const char *name); // fwd decl +chillAST_VarDecl *symbolTableFindName(chillAST_SymbolTable *table, const char *name); chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, - const char *name); // fwd decl TODO too many similar named functions + const char *name); -void printSymbolTable(chillAST_SymbolTable *st); // fwd decl -void printSymbolTableMoreInfo(chillAST_SymbolTable *st); // fwd decl +void printSymbolTable(chillAST_SymbolTable *st); +void printSymbolTableMoreInfo(chillAST_SymbolTable *st); -chillAST_Node *lessthanmacro(chillAST_Node *left, chillAST_Node *right); // fwd declaration -chillAST_SymbolTable *addSymbolToTable(chillAST_SymbolTable *st, chillAST_VarDecl *vd); // fwd decl -chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tt, chillAST_TypedefDecl *td); // fwd decl +chillAST_Node *lessthanmacro(chillAST_Node *left, chillAST_Node *right); +chillAST_SymbolTable *addSymbolToTable(chillAST_SymbolTable *st, chillAST_VarDecl *vd); +chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tt, chillAST_TypedefDecl *td); -bool streq(const char *a, const char *b); // fwd decl -void chillindent(int i, FILE *fp); // fwd declaration +void chillindent(int i, FILE *fp); void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl); chillAST_DeclRefExpr *buildDeclRefExpr(chillAST_VarDecl *); diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh index f0afe17..ed155b2 100644 --- a/include/chillAST/chillAST_node.hh +++ b/include/chillAST/chillAST_node.hh @@ -8,6 +8,7 @@ //! generic node of the actual chillAST, a multiway tree node. class chillAST_Node { public: + // TODO decide how to hide some data //! this Node's parent chillAST_Node *parent; //! this node's children @@ -26,8 +27,18 @@ public: static int chill_array_counter; //! for manufactured pointer static int chill_pointer_counter; + + //! Base constructor for all inherited class + chillAST_Node() { + parent = NULL; + metacomment = NULL; + isFromSourceFile = true; + filename = NULL; + } //! the type of this current node virtual CHILLAST_NODE_TYPE getType() {return CHILLAST_NODE_UNKNOWN;}; + //! the precedence of the current node, 0 being the highest + virtual int getPrec() {return INT16_MAX;} bool isSourceFile() { return (getType() == CHILLAST_NODE_SOURCEFILE); }; @@ -136,7 +147,6 @@ public: // void addDecl( chillAST_VarDecl *vd); // recursive, adds to first symbol table it can find - // TODO decide how to hide some data int getNumChildren() { return children.size(); }; @@ -151,6 +161,11 @@ public: void setMetaComment(const char *c) { metacomment = strdup(c); }; + virtual void chillMergeChildInfo(chillAST_Node){ + // TODO if (par) par->getSourceFile()->addFunc(this); for FuncDecl + // TODO if (par) par->getSourceFile()->addMacro(this); For MacroDecl + // TODO if (parent) parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table + } virtual void addChild(chillAST_Node *c) { c->parent = this; diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index fd7ebe4..fb27373 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -9,8 +9,7 @@ class chillAST_NULL : public chillAST_Node { // NOOP? public: virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_NULL;} - chillAST_NULL(chillAST_Node *p = NULL) { - parent = p; + chillAST_NULL() { }; void print(int indent = 0, FILE *fp = stderr) { @@ -92,9 +91,9 @@ 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_TypedefDecl(char *t, const char *nt, char *a, chillAST_Node *par); + chillAST_TypedefDecl(char *t, const char *nt, char *a); const char *getUnderlyingType() { fprintf(stderr, "TypedefDecl getUnderLyingType()\n"); @@ -172,13 +171,13 @@ public: 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_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_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_VarDecl(chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_Node *par); + chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *n, const char *arraypart); void dump(int indent = 0, FILE *fp = stderr); @@ -227,17 +226,11 @@ public: //char *functionparameters; // TODO probably should split this node into 2 types, one for variables, one for functions // constructors - chillAST_DeclRefExpr(); + chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_Node *dec); - chillAST_DeclRefExpr(const char *variablename, chillAST_Node *p); + chillAST_DeclRefExpr(chillAST_VarDecl *vd); - chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_Node *p); - - chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_Node *dec, chillAST_Node *p); - - chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_Node *p = NULL); - - chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_Node *p = NULL); + chillAST_DeclRefExpr(chillAST_FunctionDecl *fd); // other methods particular to this type of node bool operator!=(chillAST_DeclRefExpr &other) { return decl != other.decl; }; @@ -394,11 +387,7 @@ private: 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, const char *orig, chillAST_Node *p); + chillAST_RecordDecl(const char *nam, const char *orig); void setName(const char *newname) { name = strdup(newname); }; @@ -490,9 +479,9 @@ public: 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_FunctionDecl(const char *rt, const char *fname, chillAST_Node *p, void *unique); + chillAST_FunctionDecl(const char *rt, const char *fname, void *unique); void addParameter(chillAST_VarDecl *p); @@ -599,7 +588,6 @@ public: virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_SOURCEFILE;} // constructors - chillAST_SourceFile(); // defined in chill_ast.cc chillAST_SourceFile(const char *filename); // defined in chill_ast.cc void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc @@ -704,11 +692,7 @@ public: char *getRhsString() { return rhsString; } - chillAST_MacroDefinition(); - - chillAST_MacroDefinition(const char *name, chillAST_Node *par); - - chillAST_MacroDefinition(const char *name, const char *rhs, chillAST_Node *par); + chillAST_MacroDefinition(const char *name, const char *rhs); void addParameter(chillAST_VarDecl *p); // parameters have no TYPE ?? chillAST_VarDecl *hasParameterNamed(const char *name); @@ -778,7 +762,7 @@ 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); // other methods particular to this type of node void addSyncs(); @@ -901,8 +885,7 @@ public: // 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); // other methods particular to this type of node bool isNotLeaf() { return true; }; @@ -980,9 +963,7 @@ public: // 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); // other methods particular to this type of node int evalAsInt(); @@ -1092,28 +1073,28 @@ 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 + + //! always a decl ref expr? No, for multidimensional array, is another ASE + chillAST_Node *base; 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 - void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! + //! making sure its unique through original reference, DO NOT REFERENCE THROUGH THIS! + void *uniquePtr; // constructors - chillAST_ArraySubscriptExpr(); - - chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, chillAST_Node *p, void *unique); - - chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, bool writtento, chillAST_Node *p, void *unique); + chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, bool writtento, 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); // other methods particular to this type of node bool operator!=(const chillAST_ArraySubscriptExpr &); bool operator==(const chillAST_ArraySubscriptExpr &); - chillAST_VarDecl *multibase(); // method for finding the basedecl + //! Method for finding the basedecl, retursn the VARDECL of the thing the subscript is an index into + chillAST_VarDecl *multibase(); chillAST_Node *multibase2() { return base->multibase2(); } chillAST_Node *getIndex(int dim); @@ -1181,9 +1162,7 @@ public: // constructors - chillAST_MemberExpr(); - - chillAST_MemberExpr(chillAST_Node *bas, const char *mem, chillAST_Node *p, void *unique, + chillAST_MemberExpr(chillAST_Node *bas, const char *mem, void *unique, CHILLAST_MEMBER_EXP_TYPE t = CHILLAST_MEMBER_EXP_DOT); // other methods particular to this type of node @@ -1244,7 +1223,7 @@ public: int value; // constructors - chillAST_IntegerLiteral(int val, chillAST_Node *p = NULL); + chillAST_IntegerLiteral(int val); // other methods particular to this type of node int evalAsInt() { return value; } @@ -1285,20 +1264,21 @@ public: int float0double1; char *allthedigits; // if not NULL, use this as printable representation - int precision; // float == 1, double == 2, ??? + //! Control the precision, float == 1, double == 2 + int precision; // constructors - chillAST_FloatingLiteral(float val, chillAST_Node *p); + chillAST_FloatingLiteral(float val); - chillAST_FloatingLiteral(double val, chillAST_Node *p); + chillAST_FloatingLiteral(double val); - chillAST_FloatingLiteral(float val, int pre, chillAST_Node *p); + chillAST_FloatingLiteral(float val, int pre); - chillAST_FloatingLiteral(double val, int pre, chillAST_Node *p); + chillAST_FloatingLiteral(double val, int pre); - chillAST_FloatingLiteral(float val, const char *printable, chillAST_Node *p); + chillAST_FloatingLiteral(float val, const char *printable); - chillAST_FloatingLiteral(float val, int pre, const char *printable, chillAST_Node *p); + chillAST_FloatingLiteral(float val, int pre, const char *printable); chillAST_FloatingLiteral(chillAST_FloatingLiteral *old); @@ -1339,12 +1319,14 @@ 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 + //! String representing the operator char *op; // TODO enum - bool prefix; // or post + //! true for prefix unary operator + bool prefix; 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); // other methods particular to this type of node bool isAssignmentOp() { @@ -1395,7 +1377,7 @@ public: chillAST_Node *subexpr; // constructors - chillAST_ImplicitCastExpr(chillAST_Node *sub, chillAST_Node *p); + chillAST_ImplicitCastExpr(chillAST_Node *sub); // other methods particular to this type of node bool isNotLeaf() { return true; }; @@ -1440,11 +1422,12 @@ 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 + //! String representing the type it casts to char *towhat; chillAST_Node *subexpr; // constructors - chillAST_CStyleCastExpr(const char *to, chillAST_Node *sub, chillAST_Node *p = NULL); + chillAST_CStyleCastExpr(const char *to, chillAST_Node *sub); // other methods particular to this type of node @@ -1490,7 +1473,7 @@ public: chillAST_Node *subexpr; // constructors - chillAST_CStyleAddressOf(chillAST_Node *sub, chillAST_Node *p = NULL); + chillAST_CStyleAddressOf(chillAST_Node *sub); // other methods particular to this type of node @@ -1534,7 +1517,7 @@ public: chillAST_Node *sizeinbytes; // constructors - chillAST_CudaMalloc(chillAST_Node *devmemptr, chillAST_Node *size, chillAST_Node *p = NULL); + chillAST_CudaMalloc(chillAST_Node *devmemptr, chillAST_Node *size); // other methods particular to this type of node @@ -1575,7 +1558,7 @@ public: chillAST_VarDecl *variable; // constructors - chillAST_CudaFree(chillAST_VarDecl *var, chillAST_Node *p = NULL); + chillAST_CudaFree(chillAST_VarDecl *var); // other methods particular to this type of node @@ -1613,13 +1596,13 @@ 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 + //! to void if this is null , sizeof(thing) if it is not + char *thing; + //! The subexpression calculating bytes chillAST_Node *sizeexpr; // bytes // constructors - chillAST_Malloc(chillAST_Node *size, chillAST_Node *p = NULL); - - chillAST_Malloc(char *thething, chillAST_Node *numthings, chillAST_Node *p = NULL); // malloc (sizeof(int) *1024) + chillAST_Malloc(char *thething, chillAST_Node *numthings); // malloc (sizeof(int) *1024) // other methods particular to this type of node @@ -1670,8 +1653,7 @@ public: char *cudaMemcpyKind; // could use the actual enum // constructors - chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_Node *size, char *kind, - chillAST_Node *p = NULL); + chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_Node *size, char *kind); // other methods particular to this type of node @@ -1711,7 +1693,7 @@ public: // variables that are special for this type of node // constructors - chillAST_CudaSyncthreads(chillAST_Node *p = NULL); + chillAST_CudaSyncthreads(); // other methods particular to this type of node @@ -1742,10 +1724,11 @@ 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 + //! expression to return chillAST_Node *returnvalue; // constructors - chillAST_ReturnStmt(chillAST_Node *retval, chillAST_Node *p); + chillAST_ReturnStmt(chillAST_Node *retval); // other methods particular to this type of node @@ -1787,7 +1770,7 @@ public: chillAST_VarDecl *block; // constructors - chillAST_CallExpr(chillAST_Node *function, chillAST_Node *p); + chillAST_CallExpr(chillAST_Node *function); void addArg(chillAST_Node *newarg); @@ -1830,7 +1813,7 @@ public: chillAST_Node *subexpr; // constructors - chillAST_ParenExpr(chillAST_Node *sub, chillAST_Node *p = NULL); + chillAST_ParenExpr(chillAST_Node *sub); // other methods particular to this type of node @@ -1870,10 +1853,11 @@ 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 + //! the object of sizeof function char *thing; // constructors - chillAST_Sizeof(char *t, chillAST_Node *p = NULL); + chillAST_Sizeof(char *t); // other methods particular to this type of node @@ -1912,14 +1896,14 @@ public: class chillAST_NoOp : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_NOOP;} - chillAST_NoOp(chillAST_Node *p = NULL); // { parent = p; }; + chillAST_NoOp(); // { parent = p; }; // required methods that I can't seem to get to inherit void print(int indent = 0, FILE *fp = stderr) {}; // print CODE in chill_ast.cc void dump(int indent = 0, FILE *fp = stderr) {}; // print ast in chill_ast.cc chillAST_Node *constantFold() {}; - chillAST_Node *clone() { return new chillAST_NoOp(parent); }; // ?? + chillAST_Node *clone() { chillAST_Node* n = new chillAST_NoOp(); n->setParent(parent); return n; }; // ?? void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento) {}; @@ -1956,7 +1940,7 @@ public: // 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); // other methods particular to this type of node chillAST_Node *getCond() { return cond; }; diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc index 648353a..ccc7813 100755 --- a/lib/chillcg/src/CG_chillBuilder.cc +++ b/lib/chillcg/src/CG_chillBuilder.cc @@ -141,7 +141,7 @@ namespace omega { //n->print(); printf("\n"); fflush(stdout); //fprintf(stderr, "old DRE name was %s\n", DRE->declarationName); - if (streq( oldvar, DRE->declarationName)) { + if (!strcmp( oldvar, DRE->declarationName)) { //fprintf(stderr, "yep. replacing\n"); @@ -547,7 +547,7 @@ namespace omega { 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?? + chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "=", rAST->clone()); // clone?? delete lhs; delete rhs; return new CG_chillRepr(bop); @@ -570,7 +570,7 @@ namespace omega { 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?? + chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "+=", rAST->clone()); // clone?? delete lhs; delete rhs; return new CG_chillRepr(bop); @@ -681,29 +681,16 @@ namespace omega { exit(-1); } - //fprintf(stderr, "%s is a %s\n", name, def->getTypeString()); - if (def->isMacroDefinition()) { - chillAST_CallExpr *CE = new chillAST_CallExpr( def, toplevel ); - int numparams = list.size(); + if (def->isMacroDefinition() || def->isFunctionDecl()) { + chillAST_CallExpr *CE = new chillAST_CallExpr( def ); + CE->setParent(toplevel); + int numparams = list.size(); for (int i=0; i<numparams; i++) { CG_chillRepr *CR = (CG_chillRepr *) list[i]; CE->addArg( CR->GetCode() ); } return new CG_chillRepr( CE ); } - else if (def->isFunctionDecl()) { - // TODO are these cases exactly the same? - chillAST_CallExpr *CE = new chillAST_CallExpr( def, toplevel ); - int numparams = list.size(); - for (int i=0; i<numparams; i++) { - CG_chillRepr *CR = (CG_chillRepr *) list[i]; - CE->addArg( CR->GetCode() ); - } - return new CG_chillRepr( CE ); - } - else { - } - // chillAST_CallExpr::chillAST_CallExpr(chillAST_Node *function, chillAST_Node *p ); @@ -797,7 +784,7 @@ namespace omega { } - chillAST_IfStmt *if_stmt = new chillAST_IfStmt( conditional, then_part, else_part, NULL); + chillAST_IfStmt *if_stmt = new chillAST_IfStmt( conditional, then_part, else_part); delete guardList; delete true_stmtList; @@ -838,7 +825,7 @@ namespace omega { std::vector<chillAST_Node*> nodes = static_cast<CG_chillRepr*>(index)->getChillCode(); //fprintf(stderr, "%d index nodes\n", nodes.size()); chillAST_Node *indexnode = nodes[0]; - if (!streq("DeclRefExpr", indexnode->getTypeString())) { + if (strcmp("DeclRefExpr", indexnode->getTypeString())) { fprintf(stderr, "CG_chillBuilder::CreateInductive index is not a DeclRefExpr\n"); if (indexnode->isIntegerLiteral()) fprintf(stderr, "isIntegerLiteral()\n"); @@ -866,13 +853,12 @@ namespace omega { // unclear is this will always be the same // TODO error checking && incr vs decr - chillAST_BinaryOperator *init = new chillAST_BinaryOperator( indexnode, "=", lowernode, NULL); - chillAST_BinaryOperator *cond = new chillAST_BinaryOperator( indexnode, "<=", uppernode, NULL); + chillAST_BinaryOperator *init = new chillAST_BinaryOperator( indexnode, "=", lowernode); + chillAST_BinaryOperator *cond = new chillAST_BinaryOperator( indexnode, "<=", uppernode); - //chillAST_BinaryOperator *inc = new chillAST_BinaryOperator( indexnode, "+", stepnode, NULL); - chillAST_BinaryOperator *incr = new chillAST_BinaryOperator( indexnode, "+=", stepnode, NULL); + chillAST_BinaryOperator *incr = new chillAST_BinaryOperator( indexnode, "+=", stepnode); - chillAST_ForStmt *loop = new chillAST_ForStmt( init, cond, incr, NULL /* NULL BODY DANGER! */, NULL); + chillAST_ForStmt *loop = new chillAST_ForStmt( init, cond, incr, NULL /* NULL BODY DANGER! */); return new CG_chillRepr(loop); @@ -1001,17 +987,17 @@ namespace omega { //----------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreateInt(int i) const { fprintf(stderr, "CG_chillBuilder::CreateInt( %d )\n",i); - chillAST_IntegerLiteral *il = new chillAST_IntegerLiteral(i, NULL); // parent not available + chillAST_IntegerLiteral *il = new chillAST_IntegerLiteral(i); // parent not available return new CG_chillRepr(il); } CG_outputRepr* CG_chillBuilder::CreateFloat(float f) const { //fprintf(stderr, "CG_chillBuilder::CreateFloat( %f )\n", f); - chillAST_FloatingLiteral *fl = new chillAST_FloatingLiteral(f, NULL); // parent not available + chillAST_FloatingLiteral *fl = new chillAST_FloatingLiteral(f); // parent not available return new CG_chillRepr(fl); } CG_outputRepr* CG_chillBuilder::CreateDouble(double d) const { //fprintf(stderr, "CG_chillBuilder::CreateInt( %f )\n",d); - chillAST_FloatingLiteral *dl = new chillAST_FloatingLiteral(d, NULL); // parent not available + chillAST_FloatingLiteral *dl = new chillAST_FloatingLiteral(d); // parent not available return new CG_chillRepr(dl); } @@ -1054,7 +1040,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); // parent not available //fprintf(stderr, "made a new chillRepr from "); dre->dump(); fflush(stdout); return new CG_chillRepr( dre ); } @@ -1066,7 +1052,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); // parent not available return new CG_chillRepr( dre ); } @@ -1087,7 +1073,7 @@ namespace omega { 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 + chillAST_BinaryOperator *bop = new chillAST_BinaryOperator( left, "+", right); // parent not available return new CG_chillRepr( bop ); /* Expr *lhs = static_cast<CG_chillRepr*>(lop)->GetExpression(); @@ -1132,7 +1118,7 @@ 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_UnaryOperator *ins = new chillAST_UnaryOperator("-", true, rAST->clone(), NULL); // clone? + chillAST_UnaryOperator *ins = new chillAST_UnaryOperator("-", true, rAST->clone()); // clone? delete crop; // ?? note: the chillRepr, not the chillAST_Node return new CG_chillRepr(ins); } else { @@ -1142,7 +1128,7 @@ namespace omega { //lAST->print(); printf(" - "); //rAST->print(); printf("\n"); fflush(stdout); - chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "-", rAST->clone(), NULL); // clone?? + chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "-", rAST->clone()); // clone?? delete clop; delete crop; // ?? note: the chillReprs, not the chillAST_Nodes return new CG_chillRepr(bop); @@ -1178,7 +1164,7 @@ namespace omega { rAST->print(0, stderr); fprintf(stderr, "\n"); - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "*", rAST, NULL); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "*", rAST); delete lop; delete rop; // ?? //fprintf(stderr, "CG_chillBuilder::CreateTimes() returning a CG_chillRepr with a binop inside\n"); return new CG_chillRepr( binop ); @@ -1218,7 +1204,7 @@ namespace omega { //rAST->print(0, stderr); //fprintf(stderr, " ??\n"); - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "/", rAST, NULL); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "/", rAST); delete lop; delete rop; // ?? return new CG_chillRepr( binop ); } @@ -1240,7 +1226,7 @@ namespace omega { //rAST->print(0, stderr); //fprintf(stderr, " ??\n"); - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "/", rAST, NULL); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "/", rAST); return new CG_chillRepr( binop ); } @@ -1316,7 +1302,7 @@ namespace omega { //rAST->print(0, stderr); //fprintf(stderr, " ??\n"); - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "&&", rAST, NULL); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "&&", rAST); return new CG_chillRepr( binop ); } @@ -1360,7 +1346,7 @@ namespace omega { //rAST->print(0, stderr); //fprintf(stderr, " ??\n"); - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "<=", rAST, NULL); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "<=", rAST); delete lop; delete rop; // ?? return new CG_chillRepr( binop ); } @@ -1386,7 +1372,7 @@ namespace omega { //rAST->print(0, stderr); //fprintf(stderr, " ??\n"); - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "==", rAST, NULL); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "==", rAST); delete lop; delete rop; // ?? return new CG_chillRepr( binop ); } @@ -1413,7 +1399,7 @@ namespace omega { //rAST->print(0, stderr); //fprintf(stderr, " ??\n"); - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "!=", rAST, NULL); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "!=", rAST); delete lop; delete rop; // ?? return new CG_chillRepr( binop ); } @@ -1459,7 +1445,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, CHILLAST_MEMBER_EXP_DOT ); + chillAST_MemberExpr *memexpr = new chillAST_MemberExpr( DRE, rvd->varname, NULL, CHILLAST_MEMBER_EXP_DOT ); //delete lop; delete rop; // ?? @@ -1643,7 +1629,8 @@ namespace omega { */ - chillAST_RecordDecl *rd = new chillAST_RecordDecl(struct_name.c_str(), toplevel); + chillAST_RecordDecl *rd = new chillAST_RecordDecl(struct_name.c_str(), NULL); + rd->setParent(toplevel); rd->setStruct( true ); // SO FAR, struct has no members! @@ -1710,7 +1697,7 @@ namespace omega { chillAST_TypedefDecl *tdd = (chillAST_TypedefDecl *)n; //tdd->print(); printf("\n"); fflush(stdout); - chillAST_VarDecl *vd = new chillAST_VarDecl( tdd, name.c_str(), "", NULL); + chillAST_VarDecl *vd = new chillAST_VarDecl( tdd, name.c_str(), ""); // we need to add this to function ?? TODO //fprintf(stderr, "adding typedef instance to symbolTable\n"); @@ -1730,7 +1717,7 @@ namespace omega { rd->print(); printf("\n"); fflush(stdout); rd->dump(); printf("\n"); fflush(stdout); - chillAST_VarDecl *vd = new chillAST_VarDecl( rd, name.c_str(), "", NULL); + chillAST_VarDecl *vd = new chillAST_VarDecl( rd, name.c_str(), ""); //fprintf(stderr, "CG_chillBuilder.cc, adding struct instance to body of function's symbolTable\n"); @@ -1887,7 +1874,7 @@ namespace omega { // build up a member expression (or a binop with dot operation?? ) // make a declrefexpr that refers to this variable definition chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr( thestructvd ); - chillAST_MemberExpr *ME = new chillAST_MemberExpr( DRE, member.c_str(), NULL, NULL ); // uniq TODO + chillAST_MemberExpr *ME = new chillAST_MemberExpr( DRE, member.c_str(), NULL); // uniq TODO return new CG_chillRepr( ME ); } diff --git a/src/chillASTs.cc b/src/chillASTs.cc index 5b8e1e8..29bc59a 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -2,6 +2,7 @@ #include <chilldebug.h> +#include <stack> #include "chillAST.h" using namespace std; @@ -52,26 +53,27 @@ const char *ChillAST_Node_Names[] = { "fake3" }; -char *parseUnderlyingType(char *sometype) { +bool streq(const char * a, const char * b) { + return !strcmp(a,b); +} + +//! Parse to the most basic type +char *parseUnderlyingType(const char *sometype) { int len = strlen(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? 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'; + *(p+1) = '\0'; return underlying; } @@ -160,9 +162,8 @@ chillAST_VarDecl *variableDeclFindSubpart(chillAST_VarDecl *decl, const char *na } } -chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, - const char *name) { // fwd decl TODO too many similar named functions - if (!table) return NULL; // ?? +chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, const char *name) { + if (!table) return NULL; char *varname = strdup(name), *subpart; @@ -178,7 +179,7 @@ chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, //! remove UL from numbers, MODIFIES the argument! char *ulhack(char *brackets) { - CHILL_DEBUG_PRINT("ulhack( \"%s\" -> ", brackets); + CHILL_DEBUG_PRINT("ulhack( \"%s\" -> \n", brackets); int len = strlen(brackets); for (int i = 0; i < len - 2; i++) { if (isdigit(brackets[i])) { @@ -189,7 +190,6 @@ char *ulhack(char *brackets) } } } - CHILL_DEBUG_PRINT("%s", brackets); return brackets; } @@ -197,7 +197,7 @@ char *ulhack(char *brackets) //! remove __restrict__ , MODIFIES the argument! char *restricthack(char *typeinfo) { - CHILL_DEBUG_PRINT("restricthack( \"%s\" -> ", typeinfo); + CHILL_DEBUG_PRINT("restricthack( \"%s\" -> \n", typeinfo); std::string r("__restrict__"); std::string t(typeinfo); size_t index = t.find(r); @@ -211,7 +211,6 @@ char *restricthack(char *typeinfo) while (*after != '\0') *c++ = *after++; *c = '\0'; - CHILL_DEBUG_PRINT("%s", typeinfo); return typeinfo; } @@ -240,24 +239,11 @@ char *parseArrayParts(char *sometype) { } -char *splitTypeInfo(char *underlyingtype) { // return the bracketed part of a type - char *ap = ulhack(parseArrayParts(underlyingtype)); // return this +//! return the bracketed part of a type, int *buh[32] to int +char *splitTypeInfo(char *underlyingtype) { + char *ap = ulhack(parseArrayParts(underlyingtype)); - // now need to remove all that from the underlyingtype to get - char *arraypart = strdup(""); // leak - if (index(underlyingtype, '[')) { - // looks like an array - free(arraypart); - char *start = index(underlyingtype, '['); // wrong. can have int *buh[32] - arraypart = strdup(start); - if (*(start - 1) == ' ') start--; // hack - *start = '\0'; - - // ugly. very leaky - strcpy(underlyingtype, parseUnderlyingType(underlyingtype)); - - // ulhack( arraypart ); - } + strcpy(underlyingtype, parseUnderlyingType(underlyingtype)); return ap; // leak unless caller frees this } @@ -268,30 +254,26 @@ bool isRestrict(const char *sometype) { // does not modify sometype return (std::string::npos != t.find(r)); } - -bool streq(const char *a, const char *b) { return !strcmp(a, b); }; // slightly less ugly // TODO enums - 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 - fprintf(stderr, "nodetype %s findVariableNamed( %s )\n", getTypeString(), name); + CHILL_DEBUG_PRINT("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()); + CHILL_DEBUG_PRINT("%s has a symbol table\n", getTypeString()); chillAST_VarDecl *vd = symbolTableFindVariableNamed(getSymbolTable(), name); if (vd) { - fprintf(stderr, "found it\n"); + CHILL_DEBUG_PRINT("found it\n"); return vd; // found locally } - fprintf(stderr, "%s has a symbol table but couldn't find %s\n", getTypeString(), name); + CHILL_DEBUG_PRINT("%s has a symbol table but couldn't find %s\n", getTypeString(), name); } if (!parent) { - fprintf(stderr, "%s has no parent\n", getTypeString()); + CHILL_DEBUG_PRINT("%s has no parent\n", getTypeString()); return NULL; // no more recursion available } // recurse upwards //fprintf(stderr, "recursing from %s up to parent %p\n", getTypeString(), parent); - fprintf(stderr, "recursing from %s up to parent\n", getTypeString()); + CHILL_DEBUG_PRINT("recursing from %s up to parent\n", getTypeString()); return parent->findVariableNamed(name); } @@ -346,35 +328,18 @@ void chillAST_Node::printPreprocAFTER(int indent, FILE *fp) { } } - -chillAST_SourceFile::chillAST_SourceFile() { - SourceFileName = strdup("No Source File"); - parent = NULL; // top node - metacomment = NULL; - global_symbol_table = NULL; - global_typedef_table = NULL; - FileToWrite = NULL; - frontend = strdup("unknown"); - isFromSourceFile = true; - filename = NULL; -}; - chillAST_SourceFile::chillAST_SourceFile(const char *filename) { - SourceFileName = strdup(filename); - parent = NULL; // top node - metacomment = NULL; + if(filename) SourceFileName = strdup(filename); + else SourceFileName = strdup("No Source File"); global_symbol_table = NULL; global_typedef_table = NULL; FileToWrite = NULL; frontend = strdup("unknown"); - isFromSourceFile = true; - filename = NULL; }; void chillAST_SourceFile::print(int indent, FILE *fp) { - //fprintf(stderr, "chillAST_SourceFile::print()\n"); fflush(fp); - fprintf(fp, "\n// this source derived from CHILL AST originally from file '%s' as parsed by frontend compiler %s\n\n", + CHILL_DEBUG_PRINT("\n// this source derived from CHILL AST originally from file '%s' as parsed by frontend compiler %s\n\n", SourceFileName, frontend); std::vector<char *> includedfiles; int sofar = 0; @@ -382,67 +347,19 @@ void chillAST_SourceFile::print(int indent, FILE *fp) { //fprintf(fp, "#define __rose_lt(x,y) ((x)<(y)?(x):(y))\n#define __rose_gt(x,y) ((x)>(y)?(x):(y))\n"); // help diff figure out what's going on int numchildren = children.size(); - //fprintf(stderr, "// sourcefile has %d children\n", numchildren); - //fprintf(stderr, "they are\n"); - //for (int i=0; i<numchildren; i++) { - // fprintf(stderr, "%s ", children[i]->getTypeString()); - // if (children[i]->isFunctionDecl()) { - // fprintf(stderr, "%s ", ((chillAST_FunctionDecl *)children[i])->functionName); - // } - // fprintf(stderr, "\n"); - //} for (int i = 0; i < numchildren; i++) { - //fprintf(fp, "\n// child %d of type %s:\n", i, children[i]->getTypeString()); if (children[i]->isFromSourceFile) { if (children[i]->isFunctionDecl()) { fprintf(stderr, "\nchild %d function %s\n", i, ((chillAST_FunctionDecl *) children[i])->functionName); } - //fprintf(stderr, "child %d IS from source file\n", i); - //if (children[i]->isMacroDefinition()) fprintf(fp, "\n"); fflush(fp); children[i]->print(indent, fp); if (children[i]->isVarDecl()) fprintf(fp, ";\n"); fflush(fp); // top level vardecl\n"); - } else { - //fprintf(stderr, "child %d is not from source file\n", i); - // this should all go away - -#ifdef NOPE - if (children[i]->filename // not null and not empty string - //&& 0 != strlen(children[i]->filename) - ) { // should not be necessary - //fprintf(fp, "// need an include for %s\n", children[i]->filename); - bool rddid = false; - sofar = includedfiles.size(); - - for (int j=0; j<sofar; j++) { - //fprintf(stderr, "comparing %s and %s\n", includedfiles[j], children[i]->filename ); - if (!strcmp( includedfiles[j], children[i]->filename) ) { // this file has already been included - rddid = true; - //fprintf(stderr, "already did that one\n"); - } - } - - if (false == rddid) { // we need to include it now - fprintf(fp, "#include \"%s\"\n", children[i]->filename); - includedfiles.push_back(strdup( children[i]->filename )); - } - //else { - // fprintf(fp, "already did\n"); - //} - } -#endif // NOPE - - } } fflush(fp); - - //fprintf(fp, "\n\n// functions??\n"); - //for (int i=0; i<functions.size(); i++) { - // fprintf(fp, "\n\n"); functions[i]->print(0,fp); fflush(fp); - //} }; @@ -464,9 +381,6 @@ void chillAST_SourceFile::printToFile(char *filename) { fprintf(stderr, "can't open file '%s' for writing\n", fn); exit(-1); } - - //fprintf(fp, "\n\n"); - //dump(0, fp); fprintf(fp, "\n\n"); print(0, fp); @@ -485,8 +399,6 @@ void chillAST_SourceFile::dump(int indent, FILE *fp) { chillAST_MacroDefinition *chillAST_SourceFile::findMacro(const char *name) { - //fprintf(stderr, "chillAST_SourceFile::findMacro( %s )\n", name ); - int numMacros = macrodefinitions.size(); for (int i = 0; i < numMacros; i++) { if (!strcmp(macrodefinitions[i]->macroName, name)) return macrodefinitions[i]; @@ -496,8 +408,6 @@ chillAST_MacroDefinition *chillAST_SourceFile::findMacro(const char *name) { chillAST_FunctionDecl *chillAST_SourceFile::findFunction(const char *name) { - //fprintf(stderr, "chillAST_SourceFile::findMacro( %s )\n", name ); - int numFuncs = functions.size(); for (int i = 0; i < numFuncs; i++) { if (!strcmp(functions[i]->functionName, name)) return functions[i]; @@ -515,31 +425,30 @@ chillAST_Node *chillAST_SourceFile::findCall(const char *name) { chillAST_VarDecl *chillAST_SourceFile::findVariableNamed(const char *name) { - fprintf(stderr, "SOURCEFILE SPECIAL %s findVariableNamed( %s )\n", getTypeString(), name); + CHILL_DEBUG_PRINT("SOURCEFILE SPECIAL %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()); + CHILL_DEBUG_PRINT("%s has a symbol table\n", getTypeString()); chillAST_VarDecl *vd = symbolTableFindVariableNamed(getSymbolTable(), name); if (vd) { - fprintf(stderr, "found it\n"); + CHILL_DEBUG_PRINT("found it\n"); return vd; // found locally } - fprintf(stderr, "%s has a symbol table but couldn't find %s\n", getTypeString(), name); + CHILL_DEBUG_PRINT("%s has a symbol table but couldn't find %s\n", getTypeString(), name); } - fprintf(stderr, "looking for %s in SourceFile global_symbol_table\n", name); + CHILL_DEBUG_PRINT("looking for %s in SourceFile global_symbol_table\n", name); chillAST_VarDecl *vd = symbolTableFindVariableNamed(global_symbol_table, name); if (vd) { - fprintf(stderr, "found it\n"); + CHILL_DEBUG_PRINT("found it\n"); return vd; // found locally } if (!parent) { - fprintf(stderr, "%s has no parent\n", getTypeString()); + CHILL_DEBUG_PRINT("%s has no parent\n", getTypeString()); return NULL; // no more recursion available } // recurse upwards - //fprintf(stderr, "recursing from %s up to parent %p\n", getTypeString(), parent); - fprintf(stderr, "recursing from %s up to parent\n", getTypeString()); + CHILL_DEBUG_PRINT("recursing from %s up to parent\n", getTypeString()); return parent->findVariableNamed(name); } @@ -556,12 +465,10 @@ chillAST_TypedefDecl::chillAST_TypedefDecl() { }; -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); +chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt) { underlyingtype = strdup(t); newtype = strdup(nt); arraypart = NULL; - parent = NULL; metacomment = NULL; isStruct = isUnion = false; structname = NULL; @@ -571,15 +478,13 @@ 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) { underlyingtype = strdup(t); - //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s )\n", underlyingtype); - newtype = strdup(a); // the new named type ?? + newtype = strdup(a); - arraypart = strdup(p); // array (p)art? + arraypart = strdup(p); // splitarraypart(); // TODO - parent = par; metacomment = NULL; isStruct = isUnion = false; structname = NULL; @@ -590,8 +495,6 @@ chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chil void chillAST_TypedefDecl::print(int indent, FILE *fp) { - //fprintf(fp, "typedefdecl->print()\n"); - printPreprocBEFORE(indent, fp); if (isStruct) { @@ -661,32 +564,7 @@ chillAST_RecordDecl *chillAST_TypedefDecl::getStructDef() { return NULL; } - -chillAST_RecordDecl::chillAST_RecordDecl() { - name = strdup("unknown"); // ?? - originalname = NULL; // ?? - isStruct = isUnion = false; - parent = NULL; - isFromSourceFile = true; // default - filename = NULL; -} - -chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, chillAST_Node *p) { - //fprintf(stderr, "chillAST_RecordDecl::chillAST_RecordDecl()\n"); - parent = p; - if (nam) name = strdup(nam); - else name = strdup("unknown"); // ?? - originalname = NULL; // ?? // make them do it manually? - isStruct = isUnion = false; - isFromSourceFile = true; // default - filename = NULL; -} - -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); - parent = p; - if (p) p->addChild(this); - +chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, const char *orig) { if (nam) name = strdup(nam); else name = strdup("unknown"); // ?? @@ -731,30 +609,27 @@ chillAST_VarDecl *chillAST_RecordDecl::findSubpartByType(const char *typ) { void chillAST_RecordDecl::print(int indent, FILE *fp) { - //fprintf(fp, "chillAST_RecordDecl::print()\n"); + CHILL_DEBUG_PRINT("chillAST_RecordDecl::print()\n"); if (isUnnamed) return; printPreprocBEFORE(indent, fp); chillindent(indent, fp); if (isStruct) { - //fprintf(fp, "\n/* A Record Decl STRUCT */\n"); chillindent(indent, fp); fprintf(fp, "struct "); if (strncmp("unnamed", name, 7)) fprintf(fp, "%s\n", name); chillindent(indent, fp); fprintf(fp, "{\n"); for (int i = 0; i < subparts.size(); i++) { - //fprintf(fp, "a %s\n", subparts[i]->getTypeString()); subparts[i]->print(indent + 1, fp); fprintf(fp, ";\n"); } fprintf(fp, "} "); fprintf(fp, - "\n"); // TODO need semicolon when defining struct. can't have it when part of a typedef. One of the following lines is correct in each case. - //fprintf(fp, ";\n"); + "\n"); // ?? need semicolon when defining struct. can't have it when part of a typedef. } else { - fprintf(fp, "/* UNKNOWN RECORDDECL print() */ "); + CHILL_ERROR("/* UNKNOWN RECORDDECL print() */ "); exit(-1); } printPreprocAFTER(indent, fp); @@ -791,57 +666,19 @@ void chillAST_RecordDecl::dump(int indent, FILE *fp) { } - -chillAST_FunctionDecl::chillAST_FunctionDecl() { - functionName = strdup("YouScrewedUp"); +chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, void *unique) { + CHILL_DEBUG_PRINT("chillAST_FunctionDecl::chillAST_FunctionDecl with unique %p\n", unique); + if (fname) + functionName = strdup(fname); + else + functionName = strdup("YouScrewedUp"); forwarddecl = externfunc = builtin = false; - uniquePtr = (void *) NULL; - this->setFunctionCPU(); - parent = NULL; - metacomment = NULL; - //symbol_table = NULL; // eventually, pointing to body's symbol table - typedef_table = NULL; - body = new chillAST_CompoundStmt(); - isFromSourceFile = true; // default - filename = NULL; -}; - - -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; - - parent = par; - metacomment = NULL; - if (par) par->getSourceFile()->addFunc(this); - // symbol_table = NULL; //use body's instead typedef_table = NULL; body = new chillAST_CompoundStmt(); - isFromSourceFile = true; // default - filename = NULL; -}; - - -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); this->setFunctionCPU(); - //fprintf(stderr, "functionName %s\n", functionName); - forwarddecl = externfunc = builtin = false; - - body = new chillAST_CompoundStmt(); uniquePtr = unique; // a quick way to check equivalence. DO NOT ACCESS THROUGH THIS - parent = par; - metacomment = NULL; - if (par) par->getSourceFile()->addFunc(this); - //symbol_table = NULL; // use body's - typedef_table = NULL; - isFromSourceFile = true; // default - filename = NULL; }; @@ -973,7 +810,7 @@ void chillAST_FunctionDecl::addChild(chillAST_Node *node) { } body->addChild(node); - node->parent = this; // this, or body?? + node->setParent(this); // this, or body?? } @@ -1233,49 +1070,12 @@ chillAST_Node *chillAST_FunctionDecl::constantFold() { return this; } - -chillAST_MacroDefinition::chillAST_MacroDefinition() { - macroName = strdup("UNDEFINEDMACRO"); - rhsString = NULL; - parent = NULL; - metacomment = NULL; - symbol_table = NULL; - //rhsideString = NULL; - isFromSourceFile = true; // default - filename = NULL; -}; - - -chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_Node *par) { - macroName = strdup(mname); - rhsString = NULL; - parent = par; +chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname = NULL, const char *rhs = NULL) { + if (mname) macroName = strdup(mname); else macroName = strdup("UNDEFINEDMACRO"); + if(rhs) rhsString = strdup(rhs); else rhsString = NULL; metacomment = NULL; symbol_table = NULL; - //rhsideString = NULL; - if (par) par->getSourceFile()->addMacro(this); - - //fprintf(stderr, "chillAST_MacroDefinition::chillAST_MacroDefinition( %s, ", mname); - //if (par) fprintf(stderr, " parent NOT NULL);\n"); - //else fprintf(stderr, " parent NULL);\n"); - isFromSourceFile = true; // default - filename = NULL; -}; - - -chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char *rhs, chillAST_Node *par) { - macroName = strdup(mname); - rhsString = strdup(rhs); - parent = par; - metacomment = NULL; - symbol_table = NULL; - - if (par) par->getSourceFile()->addMacro(this); - - //fprintf(stderr, "chillAST_MacroDefinition::chillAST_MacroDefinition( %s, ", mname); - //if (par) fprintf(stderr, " parent NOT NULL);\n"); - //else fprintf(stderr, " parent NULL);\n"); isFromSourceFile = true; // default filename = NULL; }; @@ -1283,16 +1083,13 @@ chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char chillAST_Node *chillAST_MacroDefinition::clone() { - // TODO ?? cloning a macro makes no sense + CHILL_ERROR("cloning a macro makes no sense\n"); return this; -#ifdef CONFUSED - - //fprintf(stderr, "chillAST_MacroDefinition::clone() for %s\n", macroName); - chillAST_MacroDefinition *clo = new chillAST_MacroDefinition( macroName, parent); + chillAST_MacroDefinition *clo = new chillAST_MacroDefinition( macroName ); + clo->setParent(parent); for (int i=0; i<parameters.size(); i++) clo->addParameter( parameters[i] ); clo->setBody( body->clone() ); return clo; -#endif } @@ -1334,7 +1131,7 @@ void chillAST_MacroDefinition::insertChild(int i, chillAST_Node *node) { void chillAST_MacroDefinition::addChild(chillAST_Node *node) { body->addChild(node); - node->parent = this; // this, or body?? + node->setParent(this); // this, or body?? } @@ -1356,8 +1153,7 @@ void chillAST_MacroDefinition::dump(int indent, FILE *fp) { void chillAST_MacroDefinition::print(int indent, FILE *fp) { // UHOH TODO - //fprintf(fp, "\n"); // ignore indentation - //fprintf(stderr, "macro has %d parameters\n", numParameters()); + CHILL_DEBUG_PRINT("macro has %d parameters\n", numParameters()); printPreprocBEFORE(indent, fp); @@ -1381,18 +1177,11 @@ chillAST_ForStmt::chillAST_ForStmt() { body = new chillAST_CompoundStmt(); conditionoperator = IR_COND_UNKNOWN; - parent = NULL; - metacomment = NULL; symbol_table = NULL; - isFromSourceFile = true; // default - filename = NULL; } -chillAST_ForStmt::chillAST_ForStmt(chillAST_Node *ini, chillAST_Node *con, chillAST_Node *inc, chillAST_Node *bod, - chillAST_Node *par) { - parent = par; - metacomment = NULL; +chillAST_ForStmt::chillAST_ForStmt(chillAST_Node *ini, chillAST_Node *con, chillAST_Node *inc, chillAST_Node *bod) { init = ini; cond = con; incr = inc; @@ -1406,7 +1195,7 @@ chillAST_ForStmt::chillAST_ForStmt(chillAST_Node *ini, chillAST_Node *con, chill if (body) body->setParent(this); // not sure this should be legal if (!cond->isBinaryOperator()) { - fprintf(stderr, "ForStmt conditional is of type %s. Expecting a BinaryOperator\n", cond->getTypeString()); + CHILL_ERROR("ForStmt conditional is of type %s. Expecting a BinaryOperator\n", cond->getTypeString()); exit(-1); } chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *) cond; @@ -1416,12 +1205,10 @@ chillAST_ForStmt::chillAST_ForStmt(chillAST_Node *ini, chillAST_Node *con, chill else if (!strcmp(condstring, ">")) conditionoperator = IR_COND_GT; else if (!strcmp(condstring, ">=")) conditionoperator = IR_COND_GE; else { - fprintf(stderr, "ForStmt, illegal/unhandled end condition \"%s\"\n", condstring); - fprintf(stderr, "currently can only handle <, >, <=, >=\n"); + CHILL_ERROR("ForStmt, illegal/unhandled end condition \"%s\"\n", condstring); + CHILL_ERROR("currently can only handle <, >, <=, >=\n"); exit(1); } - isFromSourceFile = true; // default - filename = NULL; } @@ -1598,9 +1385,10 @@ chillAST_Node *chillAST_ForStmt::constantFold() { chillAST_Node *chillAST_ForStmt::clone() { - chillAST_ForStmt *fs = new chillAST_ForStmt(init->clone(), cond->clone(), incr->clone(), body->clone(), parent); + chillAST_ForStmt *fs = new chillAST_ForStmt(init->clone(), cond->clone(), incr->clone(), body->clone()); fs->isFromSourceFile = isFromSourceFile; if (filename) fs->filename = strdup(filename); + fs->setParent(getParent()); return fs; } @@ -1731,7 +1519,7 @@ void chillAST_ForStmt::removeSyncComment() { bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bool forcesync) { - fprintf(stderr, "\nchillAST_ForStmt::findLoopIndexesToReplace( force = %d )\n", forcesync); + CHILL_DEBUG_PRINT("\nchillAST_ForStmt::findLoopIndexesToReplace( force = %d )\n", forcesync); //if (metacomment) fprintf(stderr, "metacomment '%s'\n", metacomment); bool force = forcesync; @@ -1829,7 +1617,7 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo fprintf(stderr, "containing non-loop is a %s\n", contain->getTypeString()); contain->print(0, stderr); - contain->insertChild(0, newguy); // ugly order TODO + contain->insertChild(0, newguy); // TODO ugly order contain->addVariableToSymbolTable(newguy); // adds to first enclosing symbolTable if (!symbolTableFindName(contain->getSymbolTable(), vname)) { @@ -2040,7 +1828,7 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) { // wrap the loop body in an if chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(decls[0]); chillAST_BinaryOperator *ifcond = new chillAST_BinaryOperator(DRE, "<=", ifcondrhs); - chillAST_IfStmt *ifstmt = new chillAST_IfStmt(ifcond, body, NULL, NULL); + chillAST_IfStmt *ifstmt = new chillAST_IfStmt(ifcond, body, NULL); newstmt = ifstmt; } @@ -2057,18 +1845,7 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) { } -chillAST_BinaryOperator::chillAST_BinaryOperator() { - //fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator() %p no parent\n", this); - CHILL_DEBUG_PRINT("no parent\n"); - lhs = rhs = NULL; - op = NULL; - 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) { //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); @@ -2078,11 +1855,10 @@ chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_Node *l, const char *o lhs = l; rhs = r; - parent = par; 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); + if (oper) op = strdup(oper); // if this writes to lhs and lhs type has an 'imwrittento' concept, set that up if (isAssignmentOp()) { @@ -2151,30 +1927,7 @@ void chillAST_BinaryOperator::print(int indent, FILE *fp) { // TODO this needp printPreprocBEFORE(indent, fp); chillindent(indent, fp); - bool needparens = false; - if (lhs) { - if (lhs->isImplicitCastExpr()) { - // fprintf(stderr, "\nlhs 0x%x isImplicitCastExpr()\n", lhs); - // fprintf(stderr, "lhs subexpr 0x%x\n", ((chillAST_ImplicitCastExpr*)lhs)->subexpr); - // fprintf(stderr, "lhs subexpr type %s\n", ((chillAST_ImplicitCastExpr*)lhs)->subexpr->getTypeString()); - // - if (((chillAST_ImplicitCastExpr *) lhs)->subexpr->isNotLeaf()) needparens = true; - } else if (lhs->isNotLeaf()) { - if (isMinusOp() && lhs->isPlusOp()) needparens = false; - else if (isPlusMinusOp() && lhs->isMultDivOp()) needparens = false; - else needparens = true; - } - } - - //fprintf(stderr, "\n\nbinop "); - //lhs->printonly(0,stderr); - //fprintf(stderr," %s ",op); - //rhs->printonly(0,stderr); - //fprintf(stderr,"\n"); - //fprintf(stderr, "op is %s lhs %s rhs %s\n", op, lhs->getTypeString(), rhs->getTypeString()); - //fprintf(stderr, "lhs "); lhs->printonly(0, stderr); fprintf(stderr, " "); - //fprintf(stderr, "lhs needparens = %d\n", needparens); - + bool needparens = getPrec()<=lhs->getPrec(); if (needparens) fprintf(fp, "("); if (lhs) lhs->print(0, fp); @@ -2183,23 +1936,7 @@ void chillAST_BinaryOperator::print(int indent, FILE *fp) { // TODO this needp fprintf(fp, " %s ", op); - needparens = false; - //fprintf(stderr, "binop rhs is of type %s\n", rhs->getTypeString()); - if (rhs) { - if (rhs->isImplicitCastExpr()) { - if (((chillAST_ImplicitCastExpr *) rhs)->subexpr->isNotLeaf()) needparens = true; - } - //else if (rhs->isNotLeaf()) needparens = true; // too many parens. test too simple - else if (rhs->isNotLeaf()) { - // really need the precedence ordering, and check relative of op and rhs op - if (isMinusOp()) needparens = true; // safer. perhaps complicated thing on rhs of a minus - else if (isPlusMinusOp() && rhs->isMultDivOp()) needparens = false; - else needparens = true; - } - } - //fprintf(stderr, "rhs "); rhs->printonly(0, stderr); fprintf(stderr, " "); - //fprintf(stderr, "rhs needparens = %d\n\n", needparens); - //if (!needparens) fprintf(stderr, "rhs isNotLeaf() = %d\n", rhs->isNotLeaf()); + needparens = getPrec()<=rhs->getPrec(); if (needparens) fprintf(fp, "("); if (rhs) rhs->print(0, fp); @@ -2240,15 +1977,15 @@ class chillAST_Node *chillAST_BinaryOperator::constantFold() { if (lhs->isConstant() && rhs->isConstant()) { //fprintf(stderr, "binop folding constants\n"); print(0,stderr); fprintf(stderr, "\n"); - if (streq(op, "+") || streq(op, "-") || streq(op, "*")) { + if (!strcmp(op, "+") || !strcmp(op, "-") || !strcmp(op, "*")) { if (lhs->isIntegerLiteral() && rhs->isIntegerLiteral()) { chillAST_IntegerLiteral *l = (chillAST_IntegerLiteral *) lhs; chillAST_IntegerLiteral *r = (chillAST_IntegerLiteral *) rhs; chillAST_IntegerLiteral *I; - if (streq(op, "+")) I = new chillAST_IntegerLiteral(l->value + r->value, parent); - if (streq(op, "-")) I = new chillAST_IntegerLiteral(l->value - r->value, parent); - if (streq(op, "*")) I = new chillAST_IntegerLiteral(l->value * r->value, parent); + if (!strcmp(op, "+")) I = new chillAST_IntegerLiteral(l->value + r->value); + if (!strcmp(op, "-")) I = new chillAST_IntegerLiteral(l->value - r->value); + if (!strcmp(op, "*")) I = new chillAST_IntegerLiteral(l->value * r->value); returnval = I; //fprintf(stderr, "%d %s %d becomes %d\n", l->value,op, r->value, I->value); @@ -2257,7 +1994,7 @@ class chillAST_Node *chillAST_BinaryOperator::constantFold() { // usually don't want to do this for floats or doubles // could probably check for special cases like 0.0/30.0 or X/X or X/1.0 #ifdef FOLDFLOATS - float lval, rval; + float lval, rval; if (lhs->isIntegerLiteral()) { lval = (float) ((chillAST_IntegerLiteral *)lhs)->value; } @@ -2295,7 +2032,7 @@ class chillAST_Node *chillAST_BinaryOperator::clone() { chillAST_Node *l = lhs->clone(); chillAST_Node *r = rhs->clone(); - chillAST_BinaryOperator *bo = new chillAST_BinaryOperator(l, op, r, parent); + chillAST_BinaryOperator *bo = new chillAST_BinaryOperator(l, op, r); l->setParent(bo); r->setParent(bo); bo->isFromSourceFile = isFromSourceFile; @@ -2434,26 +2171,18 @@ bool chillAST_BinaryOperator::isSameAs(chillAST_Node *other) { return lhs->isSameAs(o->lhs) && rhs->isSameAs(o->rhs); // recurse } - -chillAST_TernaryOperator::chillAST_TernaryOperator() { - op = strdup("?"); // the only one so far - condition = lhs = rhs = NULL; - isFromSourceFile = true; // default - filename = NULL; -} - chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_Node *c, chillAST_Node *l, - chillAST_Node *r, chillAST_Node *par) { - - op = strdup(oper); + chillAST_Node *r) { + if (op) + op = strdup(oper); + else + op = strdup("?"); // the only one so far condition = c; - condition->setParent(this); lhs = l; - lhs->setParent(this); rhs = r; - rhs->setParent(this); - isFromSourceFile = true; // default - filename = NULL; + if (condition) condition->setParent(this); + if (lhs) lhs->setParent(this); + if (rhs) rhs->setParent(this); } void chillAST_TernaryOperator::dump(int indent, FILE *fp) { @@ -2557,52 +2286,7 @@ class chillAST_Node *chillAST_TernaryOperator::constantFold() { chillAST_Node *returnval = this; if (condition->isConstant()) { - //fprintf(stderr, "ternop folding constants\n"); - //print(0,stderr); - //fprintf(stderr, "\n"); - - // assume op is "?" // TODO - /* - - if (streq(op, "+") || streq(op, "-") || streq(op, "*")) { - if (lhs->isIntegerLiteral() && rhs->isIntegerLiteral()) { - chillAST_IntegerLiteral *l = (chillAST_IntegerLiteral *)lhs; - chillAST_IntegerLiteral *r = (chillAST_IntegerLiteral *)rhs; - chillAST_IntegerLiteral *I; - - if (streq(op, "+")) I = new chillAST_IntegerLiteral(l->value+r->value, parent); - if (streq(op, "-")) I = new chillAST_IntegerLiteral(l->value-r->value, parent); - if (streq(op, "*")) I = new chillAST_IntegerLiteral(l->value*r->value, parent); - - returnval = I; - //fprintf(stderr, "%d %s %d becomes %d\n", l->value,op, r->value, I->value); - } - else { // at least one is a float - float lval, rval; - if (lhs->isIntegerLiteral()) { - lval = (float) ((chillAST_IntegerLiteral *)lhs)->value; - } - else { - lval = ((chillAST_FloatingLiteral *)lhs)->value; - } - if (rhs->isIntegerLiteral()) { - rval = (float) ((chillAST_IntegerLiteral *)rhs)->value; - } - else { - rval = ((chillAST_FloatingLiteral *)rhs)->value; - } - - chillAST_FloatingLiteral *F; - if (streq(op, "+")) F = new chillAST_FloatingLiteral(lval + rval, parent); - if (streq(op, "-")) F = new chillAST_FloatingLiteral(lval - rval, parent); - if (streq(op, "*")) F = new chillAST_FloatingLiteral(lval * rval, parent); - - returnval = F; - } - } - else fprintf(stderr, "can't fold op '%s' yet\n", op); - */ } return returnval; @@ -2633,96 +2317,30 @@ void chillAST_TernaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr rhs->gatherScalarRefs(refs, 0); } - -chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() { - //fprintf(stderr, "\n%p chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 0\n", this); +chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, bool writtento, void *unique) { base = index = NULL; basedecl = NULL; //fprintf(stderr, "setting basedecl NULL for ASE %p\n", this); - imwrittento = false; // ?? + imwrittento = writtento; // ?? imreadfrom = false; // ?? parent = NULL; metacomment = NULL; - //fprintf(stderr, "chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() NEED TO FAKE A LOCATION\n"); - isFromSourceFile = true; // default - filename = NULL; - //fprintf(stderr, "\nASE %p is empty\n", this); -} - - -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"); - bas->setParent(this); - if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong - else base = bas; - if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr *) indx)->subexpr; // probably wrong - else index = indx; - - base->setParent(this); - index->setParent(this); - - imwrittento = false; // ?? - imreadfrom = false; // ?? - uniquePtr = (void *) unique; - //fprintf(stderr,"chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() original = 0x%x\n", uniquePtr); - //fprintf(stderr, "chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 1 calling multibase()\n"); - basedecl = multibase();//fprintf(stderr, "%p ASE 1 basedecl = %p\n",this,basedecl); - //basedecl->print(); printf("\n"); - //basedecl->dump(); printf("\n"); fflush(stdout); - //fprintf(stderr, "basedecl varname %s\n", basedecl->varname); - isFromSourceFile = true; // default - filename = NULL; - - //fprintf(stderr, "\nASE %p parent %p ", this, parent); print(0,stderr); fprintf(stderr, "\n\n"); -} - - -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"); - - bas->setParent(this); - if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong - else base = bas; - - if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr *) indx)->subexpr; // probably wrong - else index = indx; - - //fprintf(stderr, "setting parent of base %p to %p\n", base, this); - //fprintf(stderr, "setting parent of index %p to %p\n", index, this); - base->setParent(this); - index->setParent(this); - - imwrittento = writtento; // ?? - //fprintf(stderr, "ASE %p imwrittento %d\n", this, imwrittento); - imreadfrom = false; // ?? - - uniquePtr = (void *) unique; - //fprintf(stderr,"chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() original = 0x%x\n", uniquePtr); - - basedecl = multibase(); - - //fprintf(stderr, "%p ASE 2 basedecl = %p\n", this, basedecl); - //printf("basedecl is "); fflush(stdout); basedecl->print(); printf("\n"); fflush(stdout); - //basedecl->dump(); printf("\n"); fflush(stdout); - //fprintf(stderr, "basedecl varname %s\n", basedecl->varname); - isFromSourceFile = true; // default - filename = NULL; - - //fprintf(stderr, "chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 2 DONE\n"); - //print(0,stderr); fprintf(stderr, "\n\n"); - //fprintf(stderr, "\nASE %p parent %p ", this, parent); print(0,stderr); fprintf(stderr, "\n\n"); + if (bas) { + if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong + else base = bas; + base->setParent(this); + basedecl = multibase(); + } + if (indx) { + if (indx->isImplicitCastExpr()) index = ((chillAST_ImplicitCastExpr *) indx)->subexpr; // probably wrong + else index = indx; + index->setParent(this); + } + uniquePtr = unique; } - -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) { //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 4\n"); //fprintf(stderr,"chillAST_ArraySubscriptExpr( chillAST_VarDecl *v, std::vector<int> indeces)\n"); - parent = par; //if (parent == NULL) { // fprintf(stderr, "dammit. ASE %p has no parent\n", this); //} @@ -2740,7 +2358,7 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, st //fflush(stdout); //fprintf(stderr, "\n"); - chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(v->vartype, v->varname, v, NULL); + chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(v->vartype, v->varname, v); basedecl = v; // ?? //fprintf(stderr, "%p ASE 3 basedecl = %p ", this, basedecl); //fprintf(stderr, "of type %s\n", basedecl->getTypeString()); @@ -2800,7 +2418,7 @@ chillAST_Node *chillAST_Node::getEnclosingStatement(int level) { // TODO do for return NULL; } - fprintf(stderr, "getEnclosingStatement() level %d type %s, returning NULL\n", level, getTypeString()); + CHILL_ERROR("level %d type %s, returning NULL\n", level, getTypeString()); exit(-1); return NULL; @@ -2865,12 +2483,9 @@ char *chillAST_ArraySubscriptExpr::stringRep(int indent) { char *blurb; char *b = base->stringRep(0); char *i = index->stringRep(0); - // combine. shoudl be using strings. much cleaner TODO std::string s = string(b) + "[" + string(i) + "]"; fprintf(stderr, "ASE stringrep %s\n", s.c_str()); return strdup(s.c_str()); - - } @@ -2893,116 +2508,13 @@ 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 - //print(); printf("\n"); fflush(stdout); - //base->print(); printf("\n"); fflush(stdout); - //fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() base of type %s\n", base->getTypeString()); - return base->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; - //fprintf(stderr, "base is of type %s\n", b->getTypeString()); - - if (!b) return NULL; // just in case ?? - - if (base->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding - b = ((chillAST_ImplicitCastExpr *) b)->subexpr; - } - - if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { // multidimensional array! - // recurse - return ((chillAST_ArraySubscriptExpr *) b)->multibase(); - } - - if (b->getType() == CHILLAST_NODE_DECLREFEXPR) return (((chillAST_DeclRefExpr *) b)->getVarDecl()); - - - if (b->isBinaryOperator()) { - // presumably a dot or pointer ref that resolves to an array - chillAST_BinaryOperator *BO = (chillAST_BinaryOperator *) b; - if (strcmp(BO->op, ".")) { - fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase(), UNHANDLED case:\n"); - fprintf(stderr, "base is binary operator, of type %s\n", BO->op); - exit(-1); - } - - chillAST_Node *l = BO->lhs; - chillAST_Node *r = BO->rhs; - printf("L %s\nR %s\n", l->getTypeString(), r->getTypeString()); - exit(-1); - - return NULL; // TODO do checks? - } - - if (b->isMemberExpr()) { - //c.i[c.count] we want i member of inspector - - 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 - //fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() Member Expression base of type %s\n", n->getTypeString()); - //fprintf(stderr, "base is "); ME->base->dump(); - - // NEED to be able to get lowest level recorddecl or typedef from this base - - fprintf(stderr, "chillast.cc, L2315, bailing??\n"); - exit(0); - - if (!n->isDeclRefExpr()) { - fprintf(stderr, "MemberExpr member is not chillAST_DeclRefExpr\n"); - exit(-1); - } - chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) n; - n = DRE->decl; - //fprintf(stderr, "DRE decl is of type %s\n", n->getTypeString()); - assert(n->isVarDecl()); - chillAST_VarDecl *vd = (chillAST_VarDecl *) n; - vd->print(); - printf("\n"); - fflush(stdout); - - chillAST_TypedefDecl *tdd = vd->typedefinition; - chillAST_RecordDecl *rd = vd->vardef; - //fprintf(stderr, "tdd %p rd %p\n", tdd, rd); - - print(); - printf("\n"); - dump(); - printf("\n"); - fflush(stdout); - - assert(tdd != NULL || rd != NULL); - - chillAST_VarDecl *sub; - if (tdd) sub = tdd->findSubpart(ME->member); - if (rd) sub = rd->findSubpart(ME->member); - - //fprintf(stderr, "subpart is "); sub->print(); printf("\n"); fflush(stdout); - - return sub; // what if the sub is an array ?? TODO - } - - - fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase(), UNHANDLED case %s\n", - b->getTypeString()); - print(); - printf("\n"); - fflush(stdout); - fprintf(stderr, "base is: "); - b->print(); - printf("\n"); - fflush(stdout); - exit(-1); } chillAST_Node *chillAST_ArraySubscriptExpr::getIndex(int dim) { - //fprintf(stderr, "chillAST_ArraySubscriptExpr::getIndex( %d )\n", dim); + CHILL_DEBUG_PRINT("chillAST_ArraySubscriptExpr::getIndex( %d )\n", dim); chillAST_Node *b = base; @@ -3010,93 +2522,41 @@ chillAST_Node *chillAST_ArraySubscriptExpr::getIndex(int dim) { std::vector<chillAST_Node *> ind; chillAST_Node *curindex = index; for (;;) { - if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) b = ((chillAST_ImplicitCastExpr *) b)->subexpr; + 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); curindex = ((chillAST_ArraySubscriptExpr *) b)->index; b = ((chillAST_ArraySubscriptExpr *) b)->base; depth++; } else { - //fprintf(stderr, "base "); b->print(); fprintf(stderr, "\n"); - //fprintf(stderr, "index "); curindex->print(); fprintf(stderr, "\n"); - //fprintf(stderr, "stopping at base type %s\n", b->getTypeString()); ind.push_back(curindex); break; } } - //fprintf(stderr, "depth %d\n", depth ); - //for (int i=0; i<ind.size(); i++) { ind[i]->print(); fprintf(stderr, "\n"); } - return ind[depth - dim]; - /* - if (dim == 0) return index; // single dimension - fprintf(stderr, "DIM NOT 0\n"); - // multidimension - chillAST_Node *b = base; - if (base->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding - b = ((chillAST_ImplicitCastExpr*)b)->subexpr; - } - if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding - b = ((chillAST_ImplicitCastExpr*)b)->subexpr; - } - - b->print(); printf("\n"); fflush(stdout); - if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { - return ((chillAST_ArraySubscriptExpr *)b)->getIndex(dim-1); - } - - fprintf(stderr, "chillAST_ArraySubscriptExpr::getIndex() failed\n"); - */ - exit(-1); } 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() { - //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); - - //fprintf(stderr, "old base "); base->print(); printf("\n"); fflush(stdout); - //fprintf(stderr, "old base "); base->dump(); printf("\n"); fflush(stdout); if (base->isDeclRefExpr()) { chillAST_VarDecl *vd = (chillAST_VarDecl *) (((chillAST_DeclRefExpr *) base)->decl); - //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(); - //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(); - //fprintf(stderr, "new index "); i->print(); printf("\n"); fflush(stdout); - - //if (!index->parent) { - // fprintf(stderr, "ASE %p SOURCE OF CLONE INDEX %p of type %s HAS NO PARENT\n", this, index, index->getTypeString()); - // fprintf(stderr, "ASE SOURCE IS "); print(0,stderr); fprintf(stderr, "\n\n"); - //} - //fprintf(stderr, "cloning AST %p, after cloning base and index, creating a new ASE\n", this); - chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr(b, i, imwrittento, parent, uniquePtr /* ?? */ ); - //fprintf(stderr, "cloned AST will be %p with parent %p and base %p index %p\n", ASE, parent, b, i); + chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr(b, i, imwrittento, uniquePtr); + ASE->setParent(parent); ASE->imreadfrom = false; // don't know this yet - //ASE->imreadfrom = imreadfrom; // ?? - //if (ASE->imreadfrom) { - // fprintf(stderr, "in chillAST_ArraySubscriptExpr::clone(), imreadfrom is being set. \n"); - // ASE->print(); fflush(stdout); fprintf(stderr, "\n"); - //} - //fprintf(stderr, "cloned result "); ASE->print(); printf("\n\n\n"); fflush(stdout); - //fprintf(stderr, "ASE clone() this 0x%x clone 0x%x\n", this, ASE); ASE->isFromSourceFile = isFromSourceFile; if (filename) ASE->filename = strdup(filename); return ASE; @@ -3168,33 +2628,29 @@ void chillAST_ArraySubscriptExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chi void chillAST_ArraySubscriptExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { - //fprintf(stderr,"chillAST_ArraySubscriptExpr::replaceChild()\n"); - // arraysubscriptexpression doesn t really have children (should it?) - // try index ??? if (old == index) { - //fprintf(stderr, "old is index\n"); index = newchild; index->parent = this; return; } - // try base ??? unclear if this makes sense TODO if (old == base) { - //fprintf(stderr, "old is base\n"); base = newchild; base->parent = this; return; } - fprintf(stderr, "chillAST_ArraySubscriptExpr::replaceChild() old is not base or index\n"); - print(0, stderr); - fprintf(stderr, "\nchild: "); - if (!old) fprintf(stderr, "oldchild NULL!\n"); - old->print(0, stderr); - fprintf(stderr, "\nnew: "); - newchild->print(0, stderr); - fprintf(stderr, "\n"); + CHILL_DEBUG_BEGIN + fprintf(stderr, "chillAST_ArraySubscriptExpr::replaceChild() old is not base or index\n"); + print(0, stderr); + fprintf(stderr, "\nchild: "); + if (!old) fprintf(stderr, "oldchild NULL!\n"); + old->print(0, stderr); + fprintf(stderr, "\nnew: "); + newchild->print(0, stderr); + fprintf(stderr, "\n"); + CHILL_DEBUG_END exit(-1); // make easier for gdb }; @@ -3206,39 +2662,20 @@ bool chillAST_ArraySubscriptExpr::operator!=(const chillAST_ArraySubscriptExpr & bool chillAST_ArraySubscriptExpr::operator==(const chillAST_ArraySubscriptExpr &other) { - //fprintf(stderr, "chillAST_ArraySubscriptExpr::operator==\n"); - //fprintf(stderr, "this->basedecl 0x%x other.basedecl 0x%x\n", this->basedecl, other.basedecl); - //this->basedecl->print(); printf("\n\n"); - //other.basedecl->print(); printf("\n"); fflush(stdout); - - //this->print(); printf(" 0x%x == 0x%x ",this->uniquePtr, other.uniquePtr ); other.print(); printf(" ?? "); fflush(stdout); - //if ( this->uniquePtr == other.uniquePtr) fprintf(stderr, "t\n"); - //else fprintf(stderr, "f\n"); return this->uniquePtr == other.uniquePtr; } -chillAST_MemberExpr::chillAST_MemberExpr() { - base = NULL; - member = NULL; - parent = NULL; - metacomment = NULL; - 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, +chillAST_MemberExpr::chillAST_MemberExpr(chillAST_Node *bas, const char *mem, void *unique, CHILLAST_MEMBER_EXP_TYPE t) { base = bas; - if (base) base->setParent(this); + if (bas) + base->setParent(this); if (mem) member = strdup(mem); - parent = p; - metacomment = NULL; + else + member = NULL; uniquePtr = unique; exptype = t; - isFromSourceFile = true; // default - filename = NULL; return; // ignore tests below ?? TODO ?? @@ -3329,7 +2766,7 @@ class chillAST_Node *chillAST_MemberExpr::constantFold() { 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 /* ?? */ ); + chillAST_MemberExpr *ME = new chillAST_MemberExpr(b, m, uniquePtr /* ?? */ ); ME->isFromSourceFile = isFromSourceFile; if (filename) ME->filename = strdup(filename); return ME; @@ -3461,72 +2898,38 @@ chillAST_VarDecl *chillAST_MemberExpr::multibase() { } - -chillAST_DeclRefExpr::chillAST_DeclRefExpr() { - declarationType = strdup("UNKNOWN"); - declarationName = strdup("NONE"); - decl = NULL; - parent = NULL; - metacomment = NULL; - isFromSourceFile = true; // default - filename = NULL; -} - -chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *varname, chillAST_Node *par) { - declarationType = strdup("UNKNOWN"); - declarationName = strdup(varname); - decl = NULL; - parent = par; - isFromSourceFile = true; // default - filename = NULL; -} - -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 ); - declarationType = strdup(vartype); - declarationName = strdup(varname); - decl = NULL; - parent = par; - isFromSourceFile = true; // default - 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) { //fprintf(stderr, "DRE::DRE2 0x%x %s %s 0x%x\n", this, vartype, varname, d ); - declarationType = strdup(vartype); - declarationName = strdup(varname); + if (vartype) declarationType = strdup(vartype); + else declarationType = strdup("UNKNOWN"); + if (varname) declarationName = strdup(varname); + else declarationName = strdup("NONE"); decl = d; - parent = par; - isFromSourceFile = true; // default - filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_Node *par) { // variable def +chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd) { // variable def //fprintf(stderr, "DRE::DRE3 (VD) 0x%x %s %s 0x%x\n", this, vd->vartype, vd->varname, vd ); declarationType = strdup(vd->vartype); declarationName = strdup(vd->varname); decl = vd; - parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_Node *par) { // function def +chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_FunctionDecl *fd) { // function def declarationType = strdup(fd->returnType); declarationName = strdup(fd->functionName); decl = fd; - parent = par; isFromSourceFile = true; // default filename = NULL; } chillAST_DeclRefExpr *buildDeclRefExpr(chillAST_VarDecl *vd) { - chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr(vd, NULL); - + chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr(vd); + return dre; } void chillAST_DeclRefExpr::print(int indent, FILE *fp) { @@ -3567,7 +2970,8 @@ class chillAST_Node *chillAST_DeclRefExpr::constantFold() { // can never do any class chillAST_Node *chillAST_DeclRefExpr::clone() { //fprintf(stderr, "chillAST_DeclRefExpr::clone()\n"); - chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(declarationType, declarationName, decl, parent); + chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(declarationType, declarationName, decl); + DRE->setParent(parent); DRE->isFromSourceFile = isFromSourceFile; if (filename) DRE->filename = strdup(filename); return DRE; @@ -3811,9 +3215,8 @@ void chillAST_VarDecl::splitarraypart() { } -chillAST_IntegerLiteral::chillAST_IntegerLiteral(int val, chillAST_Node *par) { +chillAST_IntegerLiteral::chillAST_IntegerLiteral(int val) { value = val; - parent = par; isFromSourceFile = true; // default filename = NULL; } @@ -3836,67 +3239,61 @@ class chillAST_Node *chillAST_IntegerLiteral::constantFold() { return this; } // class chillAST_Node *chillAST_IntegerLiteral::clone() { - chillAST_IntegerLiteral *IL = new chillAST_IntegerLiteral(value, parent); + chillAST_IntegerLiteral *IL = new chillAST_IntegerLiteral(value); IL->isFromSourceFile = isFromSourceFile; if (filename) IL->filename = strdup(filename); return IL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, chillAST_Node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val) { value = val; precision = 1; float0double1 = 0; // which is live! allthedigits = NULL; - parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, chillAST_Node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val) { doublevalue = val; precision = 2; float0double1 = 1; // which is live! allthedigits = NULL; - 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) { value = val; - precision = 1; float0double1 = 0; // which is live! precision = precis; // allthedigits = NULL; - 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) { doublevalue = val; float0double1 = 1; // which is live! precision = precis; // allthedigits = NULL; - 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) { value = val; float0double1 = 0; // which is live! precision = 1; allthedigits = NULL; if (printthis) allthedigits = strdup(printthis); //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits); - 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) { value = val; float0double1 = 0; // which is live! precision = precis; // but value is a float?? TODO @@ -3907,7 +3304,6 @@ chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const allthedigits = strdup(printthis); } //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits); - parent = par; isFromSourceFile = true; // default filename = NULL; } @@ -4003,12 +3399,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) { op = strdup(oper); prefix = pre; subexpr = sub; subexpr->setParent(this); - parent = par; isFromSourceFile = true; // default filename = NULL; } @@ -4065,7 +3460,8 @@ chillAST_Node *chillAST_UnaryOperator::constantFold() { if (streq(op, "-")) { if (subexpr->isIntegerLiteral()) { int intval = ((chillAST_IntegerLiteral *) subexpr)->value; - chillAST_IntegerLiteral *I = new chillAST_IntegerLiteral(-intval, parent); + chillAST_IntegerLiteral *I = new chillAST_IntegerLiteral(-intval); + I->setParent(parent); returnval = I; //fprintf(stderr, "integer -%d becomes %d\n", intval, I->value); } else { @@ -4088,7 +3484,8 @@ chillAST_Node *chillAST_UnaryOperator::constantFold() { class chillAST_Node *chillAST_UnaryOperator::clone() { - chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, subexpr->clone(), parent); + chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, subexpr->clone()); + UO->setParent(parent); UO->isFromSourceFile = isFromSourceFile; if (filename) UO->filename = strdup(filename); return UO; @@ -4143,14 +3540,11 @@ bool chillAST_UnaryOperator::isSameAs(chillAST_Node *other) { } -chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_Node *sub, chillAST_Node *par) { +chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_Node *sub) { subexpr = sub; subexpr->setParent(this); - parent = par; //fprintf(stderr, "ImplicitCastExpr 0x%x has subexpr 0x%x", this, subexpr); //fprintf(stderr, " of type %s\n", subexpr->getTypeString()); - isFromSourceFile = true; // default - filename = NULL; } void chillAST_ImplicitCastExpr::print(int indent, FILE *fp) { @@ -4185,7 +3579,8 @@ class chillAST_Node *chillAST_ImplicitCastExpr::constantFold() { class chillAST_Node *chillAST_ImplicitCastExpr::clone() { - chillAST_ImplicitCastExpr *ICE = new chillAST_ImplicitCastExpr(subexpr->clone(), parent); + chillAST_ImplicitCastExpr *ICE = new chillAST_ImplicitCastExpr(subexpr->clone()); + ICE->setParent(getParent()); ICE->isFromSourceFile = isFromSourceFile; if (filename) ICE->filename = strdup(filename); return ICE; @@ -4225,16 +3620,13 @@ 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) { //fprintf(stderr, "chillAST_CStyleCastExpr::chillAST_CStyleCastExpr( %s, ...)\n", to); towhat = strdup(to); subexpr = sub; if (subexpr) subexpr->setParent(this); - 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) { @@ -4296,7 +3688,8 @@ class chillAST_Node *chillAST_CStyleCastExpr::constantFold() { class chillAST_Node *chillAST_CStyleCastExpr::clone() { - chillAST_CStyleCastExpr *CSCE = new chillAST_CStyleCastExpr(towhat, subexpr->clone(), parent); + chillAST_CStyleCastExpr *CSCE = new chillAST_CStyleCastExpr(towhat, subexpr->clone()); + CSCE->setParent(getParent()); CSCE->isFromSourceFile = isFromSourceFile; if (filename) CSCE->filename = strdup(filename); return CSCE; @@ -4336,13 +3729,10 @@ 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) { subexpr = sub; subexpr->setParent(this); - parent = par; //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub ); - isFromSourceFile = true; // default - filename = NULL; } void chillAST_CStyleAddressOf::print(int indent, FILE *fp) { @@ -4369,7 +3759,8 @@ class chillAST_Node *chillAST_CStyleAddressOf::constantFold() { } class chillAST_Node *chillAST_CStyleAddressOf::clone() { - chillAST_CStyleAddressOf *CSAO = new chillAST_CStyleAddressOf(subexpr->clone(), parent); + chillAST_CStyleAddressOf *CSAO = new chillAST_CStyleAddressOf(subexpr->clone()); + CSAO->setParent(getParent()); CSAO->isFromSourceFile = isFromSourceFile; if (filename) CSAO->filename = strdup(filename); return CSAO; @@ -4407,18 +3798,11 @@ void chillAST_CStyleAddressOf::gatherVarUsage(vector<chillAST_VarDecl *> &decls) } -chillAST_Malloc::chillAST_Malloc(chillAST_Node *size, chillAST_Node *p) { +chillAST_Malloc::chillAST_Malloc(char *thething, chillAST_Node *numthings) { thing = NULL; - sizeexpr = size; // probably a multiply like sizeof(int) * 1024 - parent = p; - isFromSourceFile = true; // default - filename = NULL; -}; - -chillAST_Malloc::chillAST_Malloc(char *thething, chillAST_Node *numthings, chillAST_Node *p) { + if (thething) thing = strdup(thething); // "int" or "float" or "struct widget" sizeexpr = numthings; - parent = p; isFromSourceFile = true; // default filename = NULL; }; @@ -4428,7 +3812,8 @@ chillAST_Node *chillAST_Malloc::constantFold() { } chillAST_Node *chillAST_Malloc::clone() { - chillAST_Malloc *M = new chillAST_Malloc(thing, sizeexpr, parent); // the general version + chillAST_Malloc *M = new chillAST_Malloc(thing, sizeexpr); // the general version + M->setParent(getParent()); M->isFromSourceFile = isFromSourceFile; if (filename) M->filename = strdup(filename); return M; @@ -4483,12 +3868,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) { devPtr = devmemptr; sizeinbytes = size; // probably a multiply like sizeof(int) * 1024 - parent = p; - isFromSourceFile = true; // default - filename = NULL; }; void chillAST_CudaMalloc::print(int indent, FILE *fp) { @@ -4517,7 +3899,8 @@ class chillAST_Node *chillAST_CudaMalloc::constantFold() { } class chillAST_Node *chillAST_CudaMalloc::clone() { - chillAST_CudaMalloc *CM = new chillAST_CudaMalloc(devPtr->clone(), sizeinbytes->clone(), parent); + chillAST_CudaMalloc *CM = new chillAST_CudaMalloc(devPtr->clone(), sizeinbytes->clone()); + CM->setParent(getParent()); CM->isFromSourceFile = isFromSourceFile; if (filename) CM->filename = strdup(filename); return CM; @@ -4557,11 +3940,8 @@ 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) { variable = var; - parent = p; - isFromSourceFile = true; // default - filename = NULL; }; void chillAST_CudaFree::print(int indent, FILE *fp) { @@ -4581,7 +3961,8 @@ class chillAST_Node *chillAST_CudaFree::constantFold() { } class chillAST_Node *chillAST_CudaFree::clone() { - chillAST_CudaFree *CF = new chillAST_CudaFree(variable, parent); + chillAST_CudaFree *CF = new chillAST_CudaFree(variable); + CF->setParent(getParent()); CF->isFromSourceFile = isFromSourceFile; if (filename) CF->filename = strdup(filename); return CF; @@ -4611,16 +3992,12 @@ 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) { dest = d; src = s; //fprintf(stderr, "chillAST_CudaMemcpy::chillAST_CudaMemcpy( dest %s, src %s, ...)\n", d->varname, s->varname ); size = siz; cudaMemcpyKind = kind; - isFromSourceFile = true; // default - filename = NULL; - parent = par; }; void chillAST_CudaMemcpy::print(int indent, FILE *fp) { @@ -4656,7 +4033,8 @@ class chillAST_Node *chillAST_CudaMemcpy::constantFold() { 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); + strdup(cudaMemcpyKind)); + CMCPY->setParent(getParent()); CMCPY->isFromSourceFile = isFromSourceFile; if (filename) CMCPY->filename = strdup(filename); return CMCPY; @@ -4702,10 +4080,7 @@ void chillAST_CudaMemcpy::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CudaSyncthreads::chillAST_CudaSyncthreads(chillAST_Node *par) { - parent = par; - isFromSourceFile = true; // default - filename = NULL; +chillAST_CudaSyncthreads::chillAST_CudaSyncthreads() { } void chillAST_CudaSyncthreads::print(int indent, FILE *fp) { @@ -4721,12 +4096,9 @@ void chillAST_CudaSyncthreads::dump(int indent, FILE *fp) { } -chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_Node *retval, chillAST_Node *par) { +chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_Node *retval) { returnvalue = retval; if (returnvalue) returnvalue->setParent(this); - parent = par; - isFromSourceFile = true; // default - filename = NULL; } @@ -4765,7 +4137,8 @@ class chillAST_Node *chillAST_ReturnStmt::constantFold() { class chillAST_Node *chillAST_ReturnStmt::clone() { chillAST_Node *val = NULL; if (returnvalue) val = returnvalue->clone(); - chillAST_ReturnStmt *RS = new chillAST_ReturnStmt(val, parent); + chillAST_ReturnStmt *RS = new chillAST_ReturnStmt(val); + RS->setParent(getParent()); RS->isFromSourceFile = isFromSourceFile; if (filename) RS->filename = strdup(filename); return RS; @@ -4797,17 +4170,13 @@ 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) { //, int numofargs, chillAST_Node **theargs ) { //fprintf(stderr, "chillAST_CallExpr::chillAST_CallExpr callee type %s\n", c->getTypeString()); callee = c; //callee->setParent( this ); // ?? numargs = 0; - parent = par; grid = block = NULL; - isFromSourceFile = true; // default - filename = NULL; } @@ -4953,7 +4322,7 @@ chillAST_Node *chillAST_CallExpr::clone() { //fprintf(stderr, "chillAST_CallExpr::clone()\n"); //print(0, stderr); fprintf(stderr, "\n"); - chillAST_CallExpr *CE = new chillAST_CallExpr(callee->clone(), NULL); + chillAST_CallExpr *CE = new chillAST_CallExpr(callee->clone()); for (int i = 0; i < args.size(); i++) CE->addArg(args[i]->clone()); CE->isFromSourceFile = isFromSourceFile; if (filename) CE->filename = strdup(filename); @@ -4983,12 +4352,10 @@ chillAST_VarDecl::chillAST_VarDecl() { isABuiltin = false; isRestrict = isDevice = isShared = false; // fprintf(stderr, "RDS = false\n"); knownArraySizes = false; - isFromSourceFile = true; // default - filename = NULL; }; -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) { //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); @@ -5006,8 +4373,6 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - parent = par; - knownArraySizes = false; //fprintf(stderr, "arraypart len %d\n", strlen(a)); @@ -5033,13 +4398,10 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table } - isFromSourceFile = true; // default - filename = NULL; }; -chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam, const char *array, - chillAST_Node *par) { +chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam, const char *array) { // define a variable whose type is a struct! fprintf(stderr, "3chillAST_VarDecl::chillAST_VarDecl( %s %p struct ", nam, this); @@ -5066,7 +4428,6 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - parent = par; knownArraySizes = false; //fprintf(stderr, "arraypart len %d\n", strlen(a)); @@ -5090,13 +4451,11 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam if (parent) parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table - isFromSourceFile = true; // default - filename = NULL; }; -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) { 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); @@ -5113,7 +4472,6 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, con numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - parent = par; knownArraySizes = false; //fprintf(stderr, "arraypart len %d\n", strlen(a)); @@ -5136,16 +4494,12 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, con byreference = false; isABuiltin = false; isRestrict = isDevice = isShared = false; // //fprintf(stderr, "RDS = false\n"); - if (parent) parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table - isFromSourceFile = true; // default - filename = NULL; }; -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) { CHILL_DEBUG_PRINT("chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart '%s' ) %p\n", t, n, a, this); - vartype = strdup(t); typedefinition = NULL; underlyingtype = parseUnderlyingType(vartype); @@ -5165,11 +4519,8 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, numdimensions = 0; arraysizes = NULL; uniquePtr = ptr; - parent = par; knownArraySizes = false; - if (par) par->addChild(this); // ?? - //fprintf(stderr, "name arraypart len %d\n", strlen(a)); //fprintf(stderr, "arraypart '%s'\n", arraypart); for (int i = 0; i < strlen(a); i++) { @@ -5282,10 +4633,6 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, // members of a struct are passed up to the func or sourcefile. if (parent) parent->addVariableToSymbolTable(this); // should percolate up until something has a symbol table - - isFromSourceFile = true; // default - filename = NULL; - CHILL_DEBUG_PRINT("LEAVING\n"); //parent->print(); fprintf(stderr, "\n\n"); @@ -5458,8 +4805,6 @@ chillAST_CompoundStmt::chillAST_CompoundStmt() { parent = NULL; symbol_table = new chillAST_SymbolTable; typedef_table = NULL; - isFromSourceFile = true; // default - filename = NULL; }; @@ -5601,7 +4946,7 @@ chillAST_Node *chillAST_CompoundStmt::constantFold() { 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); + cs->setParent(getParent()); cs->isFromSourceFile = isFromSourceFile; if (filename) cs->filename = strdup(filename); return cs; @@ -5708,12 +5053,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) { subexpr = sub; subexpr->setParent(this); - parent = par; - isFromSourceFile = true; // default - filename = NULL; } void chillAST_ParenExpr::print(int indent, FILE *fp) { @@ -5750,7 +5092,8 @@ chillAST_Node *chillAST_ParenExpr::constantFold() { chillAST_Node *chillAST_ParenExpr::clone() { - chillAST_ParenExpr *PE = new chillAST_ParenExpr(subexpr->clone(), NULL); + chillAST_ParenExpr *PE = new chillAST_ParenExpr(subexpr->clone()); + PE->setParent(getParent()); PE->isFromSourceFile = isFromSourceFile; if (filename) PE->filename = strdup(filename); return PE; @@ -5784,11 +5127,8 @@ void chillAST_ParenExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_Sizeof::chillAST_Sizeof(char *athing, chillAST_Node *par) { +chillAST_Sizeof::chillAST_Sizeof(char *athing) { thing = strdup(athing); // memory leak - parent = par; - isFromSourceFile = true; // default - filename = NULL; } void chillAST_Sizeof::print(int indent, FILE *fp) { @@ -5814,7 +5154,8 @@ chillAST_Node *chillAST_Sizeof::constantFold() { } chillAST_Node *chillAST_Sizeof::clone() { - chillAST_Sizeof *SO = new chillAST_Sizeof(thing, NULL); + chillAST_Sizeof *SO = new chillAST_Sizeof(thing); + SO->setParent(getParent()); SO->isFromSourceFile = isFromSourceFile; if (filename) SO->filename = strdup(filename); return SO; @@ -5935,16 +5276,13 @@ chillAST_IfStmt::chillAST_IfStmt() { 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) { cond = c; if (cond) cond->setParent(this); thenpart = t; if (thenpart) thenpart->setParent(this); elsepart = e; if (elsepart) elsepart->setParent(this); - parent = p; - isFromSourceFile = true; // default - filename = NULL; } void chillAST_IfStmt::gatherVarDecls(vector<chillAST_VarDecl *> &decls) { @@ -6022,7 +5360,8 @@ chillAST_Node *chillAST_IfStmt::clone() { if (thenpart) t = thenpart->clone(); if (elsepart) e = elsepart->clone(); - chillAST_IfStmt *IS = new chillAST_IfStmt(c, t, e, parent); + chillAST_IfStmt *IS = new chillAST_IfStmt(c, t, e); + IS->setParent(getParent()); IS->isFromSourceFile = isFromSourceFile; if (filename) IS->filename = strdup(filename); return IS; @@ -6244,10 +5583,7 @@ chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tdt, chillAST_Ty } -chillAST_NoOp::chillAST_NoOp(chillAST_Node *p) { - parent = p; - isFromSourceFile = true; // default - filename = NULL; +chillAST_NoOp::chillAST_NoOp() { }; // so we have SOMETHING for NoOp in the cc file ??? diff --git a/src/ir_clang.cc b/src/ir_clang.cc index 628e101..44ab3ee 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -647,7 +647,7 @@ chillAST_NodeList* ConvertVarDecl(VarDecl *D) { 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, NULL); + chillAST_VarDecl *chillVD = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D); chillVD->isAParameter = isParm; //fprintf(stderr, "\nthis is the vardecl\n"); @@ -805,7 +805,7 @@ chillAST_NodeList* ConvertTypeDefDecl(TypedefDecl *TDD) { 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, NULL); + chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl(under, alias, arraypart); free(under); free(arraypart); @@ -820,16 +820,11 @@ chillAST_NodeList* ConvertDeclStmt(DeclStmt *clangDS) { chillAST_VarDecl *chillvardecl; // the thing we'll return if this is a single declaration bool multiples = !clangDS->isSingleDecl(); - if (multiples) { - // 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 - } DeclGroupRef dgr = clangDS->getDeclGroup(); clang::DeclGroupRef::iterator DI = dgr.begin(); clang::DeclGroupRef::iterator DE = dgr.end(); + chillAST_NodeList* decls = new chillAST_NodeList(); for (; DI != DE; ++DI) { Decl *D = *DI; @@ -847,14 +842,15 @@ chillAST_NodeList* ConvertDeclStmt(DeclStmt *clangDS) { string TypeStr = T.getAsString(); char *vartype = strdup(TypeStr.c_str()); - //fprintf(stderr, "%s %s\n", td, varname); + CHILL_DEBUG_PRINT("DeclStmt (clang 0x%x) for %s %s\n", D, vartype, varname); + //fprintf(stderr, "%s %s\n", td, varname); char *arraypart = splitTypeInfo(vartype); - 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); + chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D); // store this away for declrefexpr that references it! VariableDeclarations.push_back(chillvardecl); + decls->push_back(chillvardecl); // TODO if (V->hasInit()) { @@ -864,7 +860,7 @@ chillAST_NodeList* ConvertDeclStmt(DeclStmt *clangDS) { } } // for each of possibly multiple decls - NL_RET(chillvardecl); // OR a single decl + return decls; } @@ -902,7 +898,7 @@ chillAST_NodeList* ConvertFunctionDecl(FunctionDecl *D) { //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(), NULL, D); + chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl(ReturnTypeStr.c_str(), FuncName.c_str(), D); int numparams = D->getNumParams(); @@ -962,7 +958,7 @@ chillAST_NodeList* ConvertForStmt(ForStmt *clangFS) { cs->addChild(body); body = cs; } - chillAST_ForStmt *chill_loop = new chillAST_ForStmt(init, cond, incr, body, NULL); + chillAST_ForStmt *chill_loop = new chillAST_ForStmt(init, cond, incr, body); NL_RET(chill_loop); } @@ -978,7 +974,7 @@ chillAST_NodeList* ConvertIfStmt(IfStmt *clangIS) { chillAST_Node *els = NULL; if (elsepart) els = unwrap(ConvertGenericClangAST(elsepart)); - chillAST_IfStmt *ifstmt = new chillAST_IfStmt(con, thn, els, NULL); + chillAST_IfStmt *ifstmt = new chillAST_IfStmt(con, thn, els); NL_RET(ifstmt); } @@ -988,7 +984,7 @@ chillAST_NodeList* ConvertUnaryOperator(UnaryOperator *clangUO) { bool pre = clangUO->isPrefix(); chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangUO->getSubExpr())); - chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub, NULL); + chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub); NL_RET(chillUO); } @@ -1008,7 +1004,7 @@ chillAST_NodeList* ConvertBinaryOperator(BinaryOperator *clangBO) { // TODO chill equivalent for numeric op. // build up the chill Binary Op AST node - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r, NULL); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r); NL_RET(binop); } @@ -1109,7 +1105,7 @@ chillAST_NodeList* ConvertIntegerLiteral(IntegerLiteral *clangIL) { 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, NULL); + chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral(val); NL_RET(chillIL); } @@ -1178,7 +1174,7 @@ chillAST_NodeList* ConvertFloatingLiteral(FloatingLiteral *clangFL) { buf[len] = '\0'; //fprintf(stderr, "'%s'\n", buf); - chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf, NULL); + chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf); //chillFL->print(); printf("\n"); fflush(stdout); NL_RET(chillFL); @@ -1190,7 +1186,7 @@ chillAST_NodeList* ConvertImplicitCastExpr(ImplicitCastExpr *clangICE) { CastExpr *CE = dyn_cast<ImplicitCastExpr>(clangICE); //fprintf(stderr, "implicit cast of type %s\n", CE->getCastKindName()); chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangICE->getSubExpr())); - chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub, NULL); + chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub); //sub->setParent( chillICE ); // these 2 lines work //return chillICE; @@ -1212,7 +1208,7 @@ chillAST_NodeList* ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE) { chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangCSCE->getSubExprAsWritten())); //fprintf(stderr, "after sub towhat (%s)\n", towhat); - chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub, NULL); + chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub); //fprintf(stderr, "after CSCE towhat (%s)\n", towhat); NL_RET(chillCSCE); } @@ -1222,7 +1218,7 @@ 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, NULL); + chillAST_ReturnStmt *chillRS = new chillAST_ReturnStmt(retval); NL_RET(chillRS); } @@ -1236,7 +1232,7 @@ chillAST_NodeList* ConvertCallExpr(CallExpr *clangCE) { //chillAST_Node *next = ((chillAST_ImplicitCastExpr *)callee)->subexpr; //fprintf(stderr, "callee is of type %s\n", next->getTypeString()); - chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee, NULL); + chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee); int numargs = clangCE->getNumArgs(); //fprintf(stderr, "CallExpr has %d args\n", numargs); @@ -1251,7 +1247,7 @@ chillAST_NodeList* ConvertCallExpr(CallExpr *clangCE) { chillAST_NodeList* ConvertParenExpr(ParenExpr *clangPE) { chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangPE->getSubExpr())); - chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub, NULL); + chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub); NL_RET(chillPE); } @@ -1730,13 +1726,13 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) { char *assop = bop->getOp(); //fprintf(stderr, "'%s' is an assignment op\n", bop->getOp()); - if (streq(assop, "+=") || streq(assop, "-=")) { + if (!strcmp(assop, "+=") || !strcmp(assop, "-=")) { chillAST_Node *stride = rhs; //fprintf(stderr, "stride is of type %s\n", stride->getTypeString()); if (stride->isIntegerLiteral()) { int val = ((chillAST_IntegerLiteral *) stride)->value; - if (streq(assop, "+=")) step_size_ = val; - else if (streq(assop, "-=")) step_size_ = -val; + if (!strcmp(assop, "+=")) step_size_ = val; + else if (!strcmp(assop, "-=")) step_size_ = -val; else beets = true; } else beets = true; // += or -= but not constant stride } else if (rhs->isBinaryOperator()) { @@ -2470,7 +2466,7 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector // now we've got the vardecl AND the indeces to make a chillAST that represents the array reference // TODO Passing NULL for chillAST node? CHILL_DEBUG_PRINT("Passed NULL as chillAST node"); - chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr(vd, inds, NULL); + chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr(vd, inds); auto ref = new IR_chillArrayRef(this, ASE, 0); @@ -2828,8 +2824,8 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { //fprintf(stderr, "it's in the olddecls (exactly)\n"); inthere = 1; } - if (streq(decls[i]->varname, olddecls[j]->varname)) { - if (streq(decls[i]->arraypart, olddecls[j]->arraypart)) { + if (!strcmp(decls[i]->varname, olddecls[j]->varname)) { + if (!strcmp(decls[i]->arraypart, olddecls[j]->arraypart)) { //fprintf(stderr, "it's in the olddecls (INEXACTLY)\n"); inthere = 1; } @@ -3110,9 +3106,9 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C //fprintf(stderr, "ir_clang.cc BOP TODO\n"); exit(-1); // chillAST_BinaryOperator *bop = (chillAST_BinaryOperator *) e; char *op = bop->op; // TODO enum for operator types - if (streq(op, "=")) { + if (!strcmp(op, "=")) { v.push_back(new omega::CG_chillRepr(bop->rhs)); // for assign, return RHS - } else if (streq(op, "+") || streq(op, "-") || streq(op, "*") || streq(op, "/")) { + } else if (!strcmp(op, "+") || !strcmp(op, "-") || !strcmp(op, "*") || !strcmp(op, "/")) { v.push_back(new omega::CG_chillRepr(bop->lhs)); // for +*-/ return both lhs and rhs v.push_back(new omega::CG_chillRepr(bop->rhs)); } else { @@ -3124,7 +3120,7 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C omega::CG_chillRepr *repr; chillAST_UnaryOperator *uop = (chillAST_UnaryOperator *) e; char *op = uop->op; // TODO enum - if (streq(op, "+") || streq(op, "-")) { + if (!strcmp(op, "+") || !strcmp(op, "-")) { v.push_back(new omega::CG_chillRepr(uop->subexpr)); } else { CHILL_ERROR("ir_clang.cc IR_clangCode::QueryExpOperand() Unary Operator UNHANDLED op (%s)\n", op); @@ -3221,7 +3217,7 @@ chillAST_NodeList* ConvertMemberExpr(clang::MemberExpr *clangME) { const char *member = DN.getAsString().c_str(); //fprintf(stderr, "%s\n", DN.getAsString().c_str()); - chillAST_MemberExpr *ME = new chillAST_MemberExpr(base, member, NULL, clangME); + chillAST_MemberExpr *ME = new chillAST_MemberExpr(base, member, clangME); fprintf(stderr, "this is the Member Expresion\n"); ME->print(); |