diff options
Diffstat (limited to 'lib/chillcg/src/CG_chillRepr.cc')
-rwxr-xr-x | lib/chillcg/src/CG_chillRepr.cc | 100 |
1 files changed, 16 insertions, 84 deletions
diff --git a/lib/chillcg/src/CG_chillRepr.cc b/lib/chillcg/src/CG_chillRepr.cc index a47ecbc..044610c 100755 --- a/lib/chillcg/src/CG_chillRepr.cc +++ b/lib/chillcg/src/CG_chillRepr.cc @@ -14,114 +14,46 @@ #include <code_gen/CG_chillRepr.h> #include <stdio.h> -#include <stdlib.h> // for exit() +#include <stdlib.h> +#include <code_gen/CGdebug.h> namespace omega { CG_chillRepr::~CG_chillRepr() { } - //void CG_chillRepr::AppendStmt(Stmt *s) const { - // tree_node_list_->push_back(s); - //} - - //void CG_chillRepr::AppendV(StmtList *sl) const { - // for(int i=0; i<sl->size(); ++i) tree_node_list_->push_back((*sl)[i]); - //} - - chillAST_Node * CG_chillRepr::GetCode() { - //fprintf(stderr, "CG_chillRepr::GetCode() this %p size %d\n", this, chillnodes.size()); - - if (0 == chillnodes.size()) return NULL; // error? - - if (1 == chillnodes.size()) return chillnodes[0]; - - // make a compoundstatement with all the code ??? probably should be that way already - fprintf(stderr, "CG_chillRepr GetCode(), multiple (%d) statements in the code??\n", chillnodes.size()); - for (int i=0; i<chillnodes.size(); i++) { - fprintf(stderr, "chillnode %d %p\n", i, chillnodes[i] ); + if (0 == chillnodes.size()) { + CG_ERROR("No contained chillnodes\n"); + return NULL; // error? } + if (1 == chillnodes.size()) return chillnodes[0]; + CG_DEBUG_PRINT("Creating a compound statements\n"); chillAST_CompoundStmt *CS = new chillAST_CompoundStmt(); for (int i=0; i<chillnodes.size(); i++) { CS->addChild( chillnodes[i] ); } return CS; } - - - CG_outputRepr* CG_chillRepr::clone() const { // make a deep/shallow COPY of all the nodes - //fprintf(stderr, "CG_chillRepr::clone() %d chill nodes\n", chillnodes.size()); - //for (int i=0; i<chillnodes.size(); i++) { chillnodes[i]->print(); printf("\n"); } fflush(stdout); - - CG_chillRepr *newrepr = new CG_chillRepr(); // empty + CG_outputRepr* CG_chillRepr::clone() const { + CG_chillRepr *newrepr = new CG_chillRepr(); - // deep ( nothing is the same as in the source ) - for (int i=0; i<chillnodes.size(); i++) newrepr->addStatement( chillnodes[i]->clone() ); + for (int i=0; i<chillnodes.size(); i++) + newrepr->addStatement( chillnodes[i]->clone() ); - // shallow (the submembers are the same ) - //for (int i=0; i<chillnodes.size(); i++) newrepr->addStatement( chillnodes[i] ); - //fprintf(stderr, "done cloning\n"); - return newrepr; + return newrepr; } - - void CG_chillRepr::clear() { chillnodes.clear(); } - - - // TODO this is duplicated and shouldn't be here anyway - static std::string binops[] = { - " ", " ", // BO_PtrMemD, BO_PtrMemI, // [C++ 5.5] Pointer-to-member operators. - "*", "/", "%", // BO_Mul, BO_Div, BO_Rem, // [C99 6.5.5] Multiplicative operators. - "+", "-", // BO_Add, BO_Sub, // [C99 6.5.6] Additive operators. - "<<", ">>", // BO_Shl, BO_Shr, // [C99 6.5.7] Bitwise shift operators. - "<", ">", "<=", ">=", // BO_LT, BO_GT, BO_LE, BO_GE, // [C99 6.5.8] Relational operators. - "==", "!=", // BO_EQ, BO_NE, // [C99 6.5.9] Equality operators. - "&", // BO_And, // [C99 6.5.10] Bitwise AND operator. - "??", // BO_Xor, // [C99 6.5.11] Bitwise XOR operator. - "|", // BO_Or, // [C99 6.5.12] Bitwise OR operator. - "&&", // BO_LAnd, // [C99 6.5.13] Logical AND operator. - "||", // BO_LOr, // [C99 6.5.14] Logical OR operator. - "=", "*=", // BO_Assign, BO_MulAssign, // [C99 6.5.16] Assignment operators. - "/=", "%=", // BO_DivAssign, BO_RemAssign, - "+=", "-=", // BO_AddAssign, BO_SubAssign, - "???", "???", // BO_ShlAssign, BO_ShrAssign, - "&&=", "???", // BO_AndAssign, BO_XorAssign, - "||=", // BO_OrAssign, - ","}; // BO_Comma // [C99 6.5.17] Comma operator. - - - static std::string unops[] = { - "++", "--", // [C99 6.5.2.4] Postfix increment and decrement - "++", "--", // [C99 6.5.3.1] Prefix increment and decrement - "@", "*", // [C99 6.5.3.2] Address and indirection - "+", "-", // [C99 6.5.3.3] Unary arithmetic - "~", "!", // [C99 6.5.3.3] Unary arithmetic - "__real", "__imag", // "__real expr"/"__imag expr" Extension. - "__extension" // __extension__ marker. - }; - - - - //void CG_chillRepr::dump() const { Dump(); } + void CG_chillRepr::dump() const { + for (int i = 0; i < chillnodes.size(); i++) + chillnodes[i]->print(0,stdout); + } - void CG_chillRepr::Dump() const { - CG_chillRepr *me = (CG_chillRepr *)this; // ?? - //fprintf(stderr, "repr of type "); - //fprintf(stderr, "%s\n", this->type()); - int numnodes = me->chillnodes.size(); - //fprintf(stderr, "repr %p %d nodes\n", this, numnodes); - for (int i=0; i<numnodes; i++) { - me->chillnodes[i]->print(); printf("\n"); fflush(stdout); - } - return; - } - } // namespace |