summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/chillcg/include/code_gen/CG_chillBuilder.h300
-rwxr-xr-xlib/chillcg/include/code_gen/CG_chillRepr.h22
-rwxr-xr-xlib/chillcg/src/CG_chillBuilder.cc497
-rwxr-xr-xlib/chillcg/src/CG_chillRepr.cc100
-rw-r--r--lib/codegen/include/code_gen/CG_outputBuilder.h4
-rw-r--r--lib/codegen/include/code_gen/CG_stringBuilder.h2
-rw-r--r--lib/codegen/include/code_gen/CGdebug.h31
-rwxr-xr-xlib/codegen/src/CG_stringBuilder.cc6
8 files changed, 234 insertions, 728 deletions
diff --git a/lib/chillcg/include/code_gen/CG_chillBuilder.h b/lib/chillcg/include/code_gen/CG_chillBuilder.h
index 172f198..22f495a 100755
--- a/lib/chillcg/include/code_gen/CG_chillBuilder.h
+++ b/lib/chillcg/include/code_gen/CG_chillBuilder.h
@@ -5,191 +5,145 @@
#include <code_gen/CG_outputBuilder.h>
#include <code_gen/CG_chillRepr.h>
#include <string>
-
-
namespace omega {
-class CG_chillBuilder : public CG_outputBuilder {
-private:
-
- chillAST_SourceFile *toplevel;
- chillAST_FunctionDecl *currentfunction;
-
- chillAST_SymbolTable *symtab_; // symbol table for FUNC (parameters?)
- chillAST_SymbolTable *symtab2_; // symbol table for func BODY
-
-public:
- CG_chillBuilder() ;
- CG_chillBuilder(chillAST_SourceFile *top, chillAST_FunctionDecl *func ) ;
- ~CG_chillBuilder();
+ class CG_chillBuilder : public CG_outputBuilder {
+ private:
+ chillAST_SourceFile *toplevel;
+ chillAST_FunctionDecl *currentfunction;
+ chillAST_SymbolTable *symtab_; // symbol table for FUNC (parameters?)
+ chillAST_SymbolTable *symtab2_; // symbol table for func BODY
+ public:
+ CG_chillBuilder();
+
+ CG_chillBuilder(chillAST_SourceFile *top, chillAST_FunctionDecl *func);
+
+ ~CG_chillBuilder();
+
+ const char *ClassName() { return "chillBuilder"; };
+
+ //! place holder generation TODO DOC and Usage
+ CG_outputRepr *CreatePlaceHolder(int indent,
+ CG_outputRepr *stmt,
+ Tuple<CG_outputRepr *> &funcList,
+ Tuple<std::string> &loop_vars) const;
+
+ CG_outputRepr *CreateSubstitutedStmt(int indent,
+ CG_outputRepr *stmt,
+ const std::vector<std::string> &vars,
+ std::vector<CG_outputRepr *> &subs,
+ bool actuallyPrint = true) const;
+
+ CG_outputRepr *CreateAssignment(int indent, CG_outputRepr *lhs, CG_outputRepr *rhs) const;
+
+ CG_outputRepr *CreatePlusAssignment(int indent,
+ CG_outputRepr *lhs,
+ CG_outputRepr *rhs) const;
+
+ CG_outputRepr *CreateInvoke(const std::string &funcName,
+ std::vector<CG_outputRepr *> &argList) const;
+
+ CG_outputRepr *CreateComment(int indent, const std::string &commentText) const;
+
+ CG_outputRepr *CreateAttribute(CG_outputRepr *control,
+ const std::string &commentText) const;
+
+ CG_outputRepr *CreatePragmaAttribute(CG_outputRepr *scopeStmt, int looplevel,
+ const std::string &pragmaText) const;
+
+ CG_outputRepr *CreatePrefetchAttribute(CG_outputRepr *scopeStmt, int looplevel,
+ const std::string &arrName, int hint) const;
+
+ CG_outputRepr *CreateIf(int indent,
+ CG_outputRepr *guardCondition,
+ CG_outputRepr *true_stmtList,
+ CG_outputRepr *false_stmtList) const;
+
+ CG_outputRepr *CreateInductive(CG_outputRepr *index,
+ CG_outputRepr *lower,
+ CG_outputRepr *upper,
+ CG_outputRepr *step) const;
+
+ CG_outputRepr *CreateLoop(int indent,
+ CG_outputRepr *control,
+ CG_outputRepr *stmtList) const;
+
+ CG_outputRepr *CreateInt(int num) const;
+
+ CG_outputRepr *CreateFloat(float num) const;
+
+ CG_outputRepr *CreateDouble(double num) const;
+
+ bool isInteger(CG_outputRepr *op) const;
+
+ CG_outputRepr *CreateIdent(const std::string &idStr) const;
+
+ CG_outputRepr *CreateDotExpression(CG_outputRepr *l, CG_outputRepr *r) const;
- const char *ClassName() { return "chillBuilder"; };
-
- //---------------------------------------------------------------------------
- // place holder generation not in CG_outputBuilder ?? or CG_roseBuilder
- //---------------------------------------------------------------------------
- CG_outputRepr* CreatePlaceHolder(int indent,
- CG_outputRepr *stmt,
- Tuple<CG_outputRepr*> &funcList,
- Tuple<std::string> &loop_vars) const;
-
- //---------------------------------------------------------------------------
- // substitute variables in stmt
- //---------------------------------------------------------------------------
-
-
- CG_outputRepr *CreateSubstitutedStmt(int indent,
- CG_outputRepr *stmt,
- const std::vector<std::string> &vars,
- std::vector<CG_outputRepr *> &subs,
- bool actuallyPrint =true) const;
-
-
-
- //---------------------------------------------------------------------------
- // assignment generation
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateAssignment(int indent, CG_outputRepr* lhs, CG_outputRepr* rhs) const;
-
- CG_outputRepr *CreatePlusAssignment(int indent,
- CG_outputRepr *lhs,
- CG_outputRepr *rhs) const;
-
-
- //---------------------------------------------------------------------------
- // function invocation generation
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateInvoke(const std::string &funcName,
- std::vector<CG_outputRepr*> &argList,
- bool is_array = true) const;
-
- //---------------------------------------------------------------------------
- // comment generation
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateComment(int indent, const std::string &commentText) const;
-
- //---------------------------------------------------------------------------
- // Attribute generation
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateAttribute(CG_outputRepr *control,
- const std::string &commentText) const;
-
- //---------------------------------------------------------------------------
- // Pragma Attribute
- //---------------------------------------------------------------------------
- CG_outputRepr* CreatePragmaAttribute(CG_outputRepr *scopeStmt, int looplevel,
- const std::string &pragmaText) const;
-
- //---------------------------------------------------------------------------
- // Prefetch Attribute
- //---------------------------------------------------------------------------
- CG_outputRepr* CreatePrefetchAttribute(CG_outputRepr *scopeStmt, int looplevel,
- const std::string &arrName, int hint) const;
-
- //---------------------------------------------------------------------------
- // if stmt gen operations
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateIf(int indent,
- CG_outputRepr* guardCondition,
- CG_outputRepr* true_stmtList,
- CG_outputRepr* false_stmtList) const;
-
- //---------------------------------------------------------------------------
- // inductive variable generation, to be used in CreateLoop as control
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateInductive(CG_outputRepr* index,
- CG_outputRepr* lower,
- CG_outputRepr* upper,
- CG_outputRepr* step) const;
-
- //---------------------------------------------------------------------------
- // loop stmt generation
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateLoop(int indent,
- CG_outputRepr* control,
- CG_outputRepr* stmtList) const;
-
- //---------------------------------------------------------------------------
- // basic operations
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateInt(int num ) const; // create Integer constant?
- CG_outputRepr* CreateFloat(float num ) const; //
- CG_outputRepr* CreateDouble(double num ) const; // should these all be chillRepr ???
-
-
-
-
- bool isInteger(CG_outputRepr *op) const;
- CG_outputRepr* CreateIdent(const std::string &idStr) const; // create a new INTEGER identifier
-
-
- CG_outputRepr* CreateDotExpression(CG_outputRepr *l, CG_outputRepr *r) const;
- CG_outputRepr* CreateArrayRefExpression(const std::string &_s,
- CG_outputRepr *rop) const;
- CG_outputRepr* CreateArrayRefExpression(CG_outputRepr *lop,
- CG_outputRepr *rop) const;
- CG_outputRepr* ObtainInspectorData(const std::string &_s, const std::string &member_name) const;
- bool QueryInspectorType(const std::string &varName) const;
- CG_outputRepr* CreateNullStatement() const;
-
- //---------------------------------------------------------------------------
- // binary arithmetic operations
- //---------------------------------------------------------------------------
- CG_outputRepr* CreatePlus( CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateMinus( CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateTimes( CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateIntegerDivide(CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateIntegerFloor( CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateIntegerMod( CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateIntegerCeil( CG_outputRepr* lop, CG_outputRepr* rop) const;
-
- //---------------------------------------------------------------------------
- // binary logical operations
- //---------------------------------------------------------------------------
- CG_outputRepr* CreateAnd(CG_outputRepr* lop, CG_outputRepr* rop) const;
-
- //---------------------------------------------------------------------------
- // binary relational operations
- //---------------------------------------------------------------------------
- //CG_outputRepr* CreateGE(CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateLE(CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateEQ(CG_outputRepr* lop, CG_outputRepr* rop) const;
- CG_outputRepr* CreateNEQ(CG_outputRepr* lop, CG_outputRepr* rop) const;
-
- //---------------------------------------------------------------------------
- // stmt list gen operations
- //---------------------------------------------------------------------------
- CG_outputRepr*
+ CG_outputRepr *CreateArrayRefExpression(const std::string &_s,
+ CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateArrayRefExpression(CG_outputRepr *lop,
+ CG_outputRepr *rop) const;
+
+ CG_outputRepr *ObtainInspectorData(const std::string &_s, const std::string &member_name) const;
+
+ bool QueryInspectorType(const std::string &varName) const;
+
+ CG_outputRepr *CreateNullStatement() const;
+
+ CG_outputRepr *CreatePlus(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateMinus(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateTimes(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateIntegerDivide(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateIntegerFloor(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateIntegerMod(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateIntegerCeil(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateAnd(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateLE(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateEQ(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *CreateNEQ(CG_outputRepr *lop, CG_outputRepr *rop) const;
+
+ CG_outputRepr *
CreateStmtList(CG_outputRepr *singleton = NULL) const;
- CG_outputRepr*
- StmtListInsertLast(CG_outputRepr* list, CG_outputRepr* node) const;
- CG_outputRepr*
- StmtListAppend(CG_outputRepr* list1, CG_outputRepr* list2) const;
- CG_outputRepr *CreateAddressOf(CG_outputRepr *op) const ;
- CG_outputRepr *CreateBreakStatement(void) const;
- CG_outputRepr *CreateStatementFromExpression(CG_outputRepr *exp) const;
+ CG_outputRepr *
+ StmtListInsertLast(CG_outputRepr *list, CG_outputRepr *node) const;
+
+ CG_outputRepr *
+ StmtListAppend(CG_outputRepr *list1, CG_outputRepr *list2) const;
+
+ CG_outputRepr *CreateAddressOf(CG_outputRepr *op) const;
+
+ CG_outputRepr *CreateBreakStatement(void) const;
+
+ CG_outputRepr *CreateStatementFromExpression(CG_outputRepr *exp) const;
+
+ CG_outputRepr *CreateStruct(const std::string struct_name,
+ std::vector<std::string> data_members,
+ std::vector<CG_outputRepr *> data_types);
- //---------------------------------------------------------------------------
- // Utility Functions
- //---------------------------------------------------------------------------
- //CompoundStmt *StmtV2Compound(StmtList *slist) const // ??
- //{ return new (astContext_)CompoundStmt(*astContext_, &(*slist)[0], (*slist).size(), SourceLocation(), SourceLocation()); }
+ CG_outputRepr *CreateClassInstance(std::string name, CG_outputRepr *class_def);
- //bool substitute(clang::Expr *in, std::string sym, clang::Expr* expr, clang::Expr *parent) const;
+ CG_outputRepr *lookup_member_data(CG_outputRepr *scope, std::string varName, CG_outputRepr *instance);
- CG_outputRepr *CreateStruct(const std::string struct_name,
- std::vector<std::string> data_members,
- std::vector<CG_outputRepr *> data_types);
+ CG_outputRepr *CreatePointer(std::string &name) const;
- CG_outputRepr *CreateClassInstance(std::string name , CG_outputRepr *class_def);
- CG_outputRepr *lookup_member_data(CG_outputRepr* scope, std::string varName, CG_outputRepr *instance);
- CG_outputRepr* CreatePointer(std::string &name) const;
- CG_outputRepr* ObtainInspectorRange(const std::string &_s, const std::string &_name) const;
+ CG_outputRepr *ObtainInspectorRange(const std::string &_s, const std::string &_name) const;
-};
+ };
} // namespace omega
diff --git a/lib/chillcg/include/code_gen/CG_chillRepr.h b/lib/chillcg/include/code_gen/CG_chillRepr.h
index ea2048b..a2363c9 100755
--- a/lib/chillcg/include/code_gen/CG_chillRepr.h
+++ b/lib/chillcg/include/code_gen/CG_chillRepr.h
@@ -2,7 +2,6 @@
#ifndef CG_chillRepr_h
#define CG_chillRepr_h
-// Repr using chillAst internally
#include <stdio.h>
#include <string.h>
#include <code_gen/CG_outputRepr.h>
@@ -11,10 +10,8 @@
#define __STDC_CONSTANT_MACROS
#endif
-
#include "chillAST/chillASTs.hh"
-
namespace omega {
class CG_chillRepr : public CG_outputRepr {
@@ -22,16 +19,8 @@ namespace omega {
public:
CG_chillRepr() { stmtclassname = strdup("NOTHING"); }
-
-
char *type() const { return strdup("chill"); };
- //
- std::vector<chillAST_Node *> chillnodes; // TODO make private
- void printChillNodes() const {
- for (int i = 0; i < chillnodes.size(); i++)
- chillnodes[i]->print();
- fflush(stdout);
- };
+ std::vector<chillAST_Node *> chillnodes;
CG_chillRepr(std::vector<chillAST_Node *> cnodes) {
chillnodes = cnodes;
@@ -53,12 +42,11 @@ namespace omega {
void addStatement(chillAST_Node *s) { chillnodes.push_back(s); };
std::vector<chillAST_Node *> getChillCode() const { return chillnodes; };
-
+ //! Return the containing code
chillAST_Node *GetCode();
-
~CG_chillRepr();
-
+ //! Creating a deep copy of this node
CG_outputRepr *clone() const;
void clear();
@@ -67,9 +55,7 @@ namespace omega {
//---------------------------------------------------------------------------
// Dump operations
//---------------------------------------------------------------------------
- void dump() const { printChillNodes(); };
-
- void Dump() const;
+ void dump() const;
private:
char *stmtclassname; // chill
diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc
index e926b64..dc02447 100755
--- a/lib/chillcg/src/CG_chillBuilder.cc
+++ b/lib/chillcg/src/CG_chillBuilder.cc
@@ -17,270 +17,55 @@
#include <iostream>
#include <stack>
#include <code_gen/CG_chillBuilder.h>
+#include <code_gen/CGdebug.h>
+#include <code_gen/codegen_error.h>
namespace omega {
// substitute at chill AST level
- // forward declarations
- chillAST_Node *substituteChill( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubABinaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubUnaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubDeclRefExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubArraySubscriptExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubImplicitCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubCStyleCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubParenExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubCallExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubReturnStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubIfStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubCompoundStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
- chillAST_Node *SubMemberExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent );
-
chillAST_Node *substituteChill( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
if (n == NULL) {
- fprintf(stderr, "substituteChill() pointer n == NULL\n"); // DIE
- int *crash = 0;
- crash[0] = 1;
+ CG_ERROR(" pointer n == NULL\n");
exit(-1);
}
- //fprintf(stderr, "substituteChill() subbing statement of type ");
- //fprintf(stderr, "%s\n", n->getTypeString());
- //if (n->isImplicitCastExpr()) {
- // chillAST_ImplicitCastExpr *ICE = (chillAST_ImplicitCastExpr *) n;
- // fprintf(stderr, "ICE subexpr type %s\n", ICE->subexpr->getTypeString());
- //}
- //fprintf(stderr, "subbing '%s' in statement ", oldvar); n->print(0, stderr); fprintf(stderr, "\n");
-
chillAST_Node *r = n;
- if (n->isBinaryOperator()) {r= SubABinaryOperator(oldvar, newvar, n, parent );
- } else if (n->isUnaryOperator()) {r= SubUnaryOperator(oldvar, newvar, n, parent );
- } else if (n->isDeclRefExpr()) {r= SubDeclRefExpr(oldvar, newvar, n, parent );
- } else if (n->isArraySubscriptExpr()) {r=SubArraySubscriptExpr(oldvar, newvar, n, parent );
- } else if (n->isImplicitCastExpr()) {r= SubImplicitCastExpr(oldvar, newvar, n, parent );
- } else if (n->isParenExpr()) {r= SubParenExpr(oldvar, newvar, n, parent );
- } else if (n->isCStyleCastExpr()) {r= SubCStyleCastExpr(oldvar, newvar, n, parent );
- } else if (n->isReturnStmt()) {r= SubReturnStmt(oldvar, newvar, n, parent );
- } else if (n->isIfStmt()) {r= SubIfStmt(oldvar, newvar, n, parent );
- } else if (n->isCallExpr()) {r= SubCallExpr(oldvar, newvar, n, parent );
- } else if (n->isCompoundStmt()) {r= SubCompoundStmt(oldvar, newvar, n, parent );
- } else if (n->isMemberExpr()) {r= SubMemberExpr(oldvar, newvar, n, parent );
-
- } else if (n->isFloatingLiteral()) { //fprintf(stderr, "sub in FL\n"); // do nothing
- } else if (n->isIntegerLiteral()) { // do nothing
-
- } else {
- fprintf(stderr, "\nCG_chillBuilder.cc substituteChill() UNHANDLED statement of type ");
- n->dump(); printf(" "); n->print(); printf("\n"); fflush(stdout);
- fprintf(stderr, "%s\n", n->getTypeString());
- exit(-1);
+ switch (n->getType()) {
+ case CHILLAST_NODE_BINARYOPERATOR:
+ case CHILLAST_NODE_UNARYOPERATOR:
+ case CHILLAST_NODE_FORSTMT:
+ case CHILLAST_NODE_IFSTMT:
+ case CHILLAST_NODE_COMPOUNDSTMT:
+ case CHILLAST_NODE_RETURNSTMT:
+ case CHILLAST_NODE_PARENEXPR:
+ case CHILLAST_NODE_CALLEXPR:
+ case CHILLAST_NODE_IMPLICITCASTEXPR:
+ case CHILLAST_NODE_CSTYLECASTEXPR:
+ case CHILLAST_NODE_ARRAYSUBSCRIPTEXPR:
+ case CHILLAST_NODE_MEMBEREXPR:
+ for (int i=0;i<n->getNumChildren();++i)
+ n->setChild(i,substituteChill(oldvar, newvar,n->getChild(i)));
+ break;
+ case CHILLAST_NODE_DECLREFEXPR: {
+ chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) n;
+ if (!strcmp( oldvar, DRE->declarationName)) {
+ std::vector<chillAST_Node*> newnodes = newvar->chillnodes;
+ chillAST_Node *firstn = newnodes[0]->clone();
+ r = firstn;
+ }
+ }
+ break;
+ case CHILLAST_NODE_INTEGERLITERAL:
+ case CHILLAST_NODE_FLOATINGLITERAL:
+ // No op
+ break;
+ default:
+ CHILL_ERROR("UNHANDLED statement of type %s %s\n",n->getTypeString());
+ exit(-1);
}
-
- /*
- if (isa<DeclStmt>(s)) { SubDeclStmt(oldvar, newvar, n, parent );
- } else if (isa<UnaryOperator>(s)) { SubUnaryOperator(oldvar, newvar, n, parent );
- } else if (isa<ForStmt>(s)) { SubLoop(oldvar, newvar, n, parent );
- */
-
return r;
}
-
-
- chillAST_Node *SubABinaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- chillAST_BinaryOperator *b = (chillAST_BinaryOperator *) n;
- //fprintf(stderr,"SubABinaryOperator() 0x%x subbing old variable %s in \n", b, oldvar);
-
- //fprintf(stderr,"SubABinaryOperator() subbing old variable %s in \n", oldvar);
- //if (b->lhs!=NULL && b->rhs!=NULL) {
- // b->print(); printf("\n"); fflush(stdout);
- //}
-
- chillAST_Node *lhs = b->getLHS();
- chillAST_Node *rhs = b->getRHS();
-
- //if (!strcmp(b->op, "=") && rhs->isBinaryOperator() ) {
- // chillAST_BinaryOperator *r = (chillAST_BinaryOperator *) rhs;
- // fprintf(stderr, "a(%p) = b(%p) %s c(%p)\n", lhs, r->lhs, r->op, r->rhs );
- //}
-
- //fprintf(stderr, "op %s rhs type ", b->op);
- //fprintf(stderr, "%s\n", rhs->getTypeString());
- //rhs->dump(); printf("\n"); fflush(stdout);
-
-
- b->setLHS(substituteChill( oldvar, newvar, lhs, b));
- b->setRHS(substituteChill( oldvar, newvar, rhs, b));
- return b;
- }
-
-
-
- chillAST_Node *SubUnaryOperator( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- chillAST_UnaryOperator *u = (chillAST_UnaryOperator *) n;
- chillAST_Node *sub = u->getSubExpr();
- u->setSubExpr(substituteChill( oldvar, newvar, sub, u));
- return u;
- }
-
-
- chillAST_Node *SubDeclRefExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- //fprintf(stderr, "SubDeclRefExpr() subbing statement of type %s\n", n->getTypeString());
-
- chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) n;
- //const char *variable = DRE->declarationName; // should be the same as oldvar ??
-
- //fprintf(stderr, "looking for oldvar %s in old DRE code ", oldvar);
- //n->print(); printf("\n"); fflush(stdout);
-
- //fprintf(stderr, "old DRE name was %s\n", DRE->declarationName);
- if (!strcmp( oldvar, DRE->declarationName)) {
- //fprintf(stderr, "yep. replacing\n");
-
-
- //fprintf(stderr, "\nNEED TO REPLACE VARIABLE %s with new thing ", oldvar);
- //newvar->printChillNodes();
-
-
- // newvar->Dump(); printf("\n"); fflush(stdout);
- // //fprintf(stderr, " in statement of type %s\n",s->getTypeString());
- //}
-
- std::vector<chillAST_Node*> newnodes = newvar->chillnodes;
- //fprintf(stderr, "%d nodes in newvar\n", newnodes.size());
- chillAST_Node *firstn = newnodes[0];
- firstn->parent = parent;
- return firstn; // it's that simple!
-
- }
- //else fprintf(stderr, "nope. not the right thing to replace\n\n");
-
-
- return DRE; // unchanged
- } // subdeclrefexpr
-
-
-
-
-
- chillAST_Node *SubArraySubscriptExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- chillAST_ArraySubscriptExpr *ASE = (chillAST_ArraySubscriptExpr *) n;
-
- //fprintf(stderr, "subASE ASE 0x%x\n", ASE);
- //fprintf(stderr, "SubArraySubscriptExpr subbing old variable %s with new thing in ASE 0x%x ", oldvar, ASE);
-
- //ASE->print(); printf("\n"); fflush(stdout);
-
- chillAST_Node *Base = ASE->base;
- chillAST_Node *Index = ASE->index;
- //fprintf(stderr, "Index is of type %s\n", Index->getTypeString());
-
- ASE->base = substituteChill( oldvar, newvar, Base, ASE); // this should not do anything
- ASE->index = substituteChill( oldvar, newvar, Index, ASE); // this should
-
- //if (Index != ASE->index) {
- // fprintf(stderr, "ASE was ");
- // Base->print();
- // printf("[");
- // Index->print();
- // printf("]\n");
- // printf("SWAPPED INDEX ASE 0x%x is ", ASE); ASE->print(); printf("\n"); fflush(stdout);
- //}
- //else fprintf(stderr, "ASE is "); ASE->print(); printf("\n"); fflush(stdout);
- return ASE;
- }
-
-
-
- chillAST_Node *SubImplicitCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- //fprintf(stderr, "SubImplicitCastExpr subbing statement of type %s at 0x%x parent 0x%x\n", n->getTypeString(), n, parent);
- chillAST_ImplicitCastExpr *IC = (chillAST_ImplicitCastExpr *) n;
- chillAST_Node *oldsub = IC->getSubExpr();
- IC->setSubExpr(substituteChill( oldvar, newvar, oldsub, IC));
-
- //if (oldsub != IC->subexpr) {
- //fprintf(stderr, "ImplicitCastExpr has CHANGED\n");
- //IC->print(); printf("\n"); fflush(stdout);
- //fprintf(stderr, "ICE was ");
- //oldsub->print();
- //printf("\nSWAPPED subexpr ICE 0x%x is ", IC); IC->print(); printf("\n"); fflush(stdout);
- //fprintf(stderr, "PARENT 0x%x is now ",IC->parent);
- //IC->parent->print(); printf("\n"); fflush(stdout);
- //}
- return IC;
- }
-
- chillAST_Node *SubCStyleCastExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- //fprintf(stderr, "SubCStyleCastExpr() subexpr is type ");
- chillAST_CStyleCastExpr *CSCE = (chillAST_CStyleCastExpr *) n;
- //fprintf(stderr, "%s\n", CSCE->subexpr->getTypeString());
- CSCE->setSubExpr(substituteChill( oldvar, newvar, CSCE->getSubExpr(), CSCE));
- return CSCE;
- }
-
-
- chillAST_Node *SubParenExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- chillAST_ParenExpr *PE = (chillAST_ParenExpr *) n;
- PE->setSubExpr(substituteChill( oldvar, newvar, PE->getSubExpr(), PE));
- return PE;
- }
-
- chillAST_Node *SubCallExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- chillAST_CallExpr *CE = (chillAST_CallExpr *) n;
-
- int nargs = CE->getNumChildren();
- for (int i=1; i<nargs; i++) {
- CE->setChild(i,substituteChill( oldvar, newvar, CE->getChild(i), CE));
- }
- return CE;
- }
-
-
-
- chillAST_Node *SubReturnStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- chillAST_ReturnStmt *RS = (chillAST_ReturnStmt *)n;
- if (RS->getRetVal()) RS->setRetVal(substituteChill(oldvar, newvar, RS->getRetVal(), RS));
- return RS;
- }
-
-
- chillAST_Node *SubIfStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- //fprintf(stderr, "SubIfStmt()\n");
- chillAST_IfStmt *IS = (chillAST_IfStmt *)n;
- //IS->print(0, stderr); fprintf(stderr, "\n\n");
- chillAST_Node *sub;
- sub = IS->getCond();
- if ( sub ) IS->setCond( substituteChill(oldvar, newvar, sub, IS));
- sub = IS->getThen();
- if ( sub ) IS->setThen( substituteChill(oldvar, newvar, sub, IS));
- sub = IS->getElse();
- if ( sub ) IS->setElse( substituteChill(oldvar, newvar, sub, IS));
-
- return IS;
- }
-
-
- chillAST_Node *SubCompoundStmt( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- chillAST_CompoundStmt *CS = (chillAST_CompoundStmt *)n;
-
- int numchildren = CS->getNumChildren();
- for (int i=0; i<numchildren; i++) {
- CS->setChild( i, substituteChill(oldvar, newvar, CS->getChild(i), CS ));
- }
-
- return CS;
- }
-
-
-
- chillAST_Node *SubMemberExpr( const char *oldvar, CG_chillRepr *newvar, chillAST_Node *n, chillAST_Node *parent = NULL ) {
- chillAST_MemberExpr *ME = (chillAST_MemberExpr *)n;
- ME->base = substituteChill(oldvar, newvar, ME->base, ME );
- return ME;
- }
-
-
-
CG_chillBuilder::CG_chillBuilder() {
toplevel = NULL;
currentfunction = NULL; // not very useful
@@ -370,151 +155,43 @@ namespace omega {
const std::vector<std::string> &vars,
std::vector<CG_outputRepr*> &subs,
bool actuallyPrint) const {
-
- int numvars = vars.size();
+ int numvars = vars.size();
int numsubs = subs.size();
- fflush(stdout);
- fprintf(stderr, "\n\nin CG_xxxxBuilder.cc (OMEGA) CG_xxxxBuilder::CreateSubstitutedStmt()\n");
- fprintf(stderr, "%d vars and %d substitutions\n", numvars, (int)subs.size());
-
-
- if (numvars != numsubs) {
- //fprintf(stderr, "umwut?\n"); exit(-1);
- }
-
-
- //{
- // std::vector<chillAST_Node*> nodes = ((CG_chillRepr *) stmt)->getChillCode();
- // //
- // fprintf(stderr, "%d nodes in old code. was:\n", nodes.size());
- // for(int i=0; i<nodes.size(); i++)
- // {
- // printf("stmt(%d) = ",i);
- // nodes[i]->print();
- // printf("\n");
- // }
- // //printf("\nreally subbing in %d top level statements\n", nodes.size());
- // fflush(stdout);
- //}
-
- //for (int i=0; i< numsubs; i++) {
- // fprintf(stderr, "sub %d ", i);
- // if (subs[i]) { ((CG_chillRepr *)subs[i])->Dump(); fflush( stdout ); }
- // else {
- // //int *crash = NULL; *crash = 1;
- // fprintf(stderr, "(NULL error!)");
- // }
- // //fprintf(stderr, "\n");
- //}
- //fprintf(stderr, "\n");
-
-
+
+ if (numvars != numsubs)
+ throw codegen_error("Unequal number of original vars and subs");
+
if (numsubs == 0) {
-
std::vector<chillAST_Node*> nodes = ((CG_chillRepr *) stmt)->getChillCode();
-
- //
- //fprintf(stderr, "nosubs old code was:\n");
- //for(int i=0; i<nodes.size(); i++)
- // {
- // printf("stmt = ");
- // nodes[i]->print();
- // printf("\n");
- // }
- //printf("\nreally subbing in %d top level statements\n", nodes.size());
- //fflush(stdout);
-
-
-
// no cloning !!
return new CG_chillRepr( nodes );
-
- //fprintf(stderr, "since nothing actually being substituted, this is just a clone\n");
- //fprintf(stderr, "old code was AND new code is:\n");
- //for (int i=0; i<nodes.size(); i++) {
- // fprintf(stderr, "stmt = ");
- // nodes[i]->print(); fflush(stdout);
- // fprintf(stderr, "\n");
- //}
- //fprintf(stderr, "cloning()\n");
- //return stmt->clone();
-
}
-
-
- //fprintf(stderr, "numsubs %d\n", numsubs);
-
- // debugging: print the substitutions we'll do
-
- //if (numsubs > 0) {
- // for (int i=0; i< numsubs; i++) {
- // fprintf(stderr, "subbing ");
- // if (subs[i]) {
- // ((CG_chillRepr *)subs[i])->Dump(); fflush( stdout );
- // fprintf(stderr, "for %s\n", vars[i].c_str() );
- //} else {
- // //int *crash = NULL; *crash = 1;
- // fprintf(stderr, "(NULL error!)");
- // }
- // //fprintf(stderr, "\n");
- // }
- // fprintf(stderr, "\n");
- //}
-
-
-
- //fprintf(stderr, "OK, now to really substitute ...\n");
- //CG_outputRepr *newstmt = stmt->clone();
- //CG_chillRepr *n = (CG_chillRepr *) newstmt;
- //vector<chillAST_Node*> newnodes = n->getChillCode();
-
CG_chillRepr *old = (CG_chillRepr *) stmt;
std::vector<chillAST_Node*> oldnodes = old->getChillCode();
-
-
+
for (int j=0; j<numsubs; j++) {
if (subs[j] != NULL) {
-
- //fprintf(stderr, "substitution %d %s -> ", j,vars[j].c_str());
- //if (subs[j]) { ((CG_chillRepr *)subs[j])->Dump(); fflush( stdout ); }
-
-
// find the type of thing we'll be using to replace the old variable
CG_chillRepr *CRSub = (CG_chillRepr *)(subs[j]);
std::vector<chillAST_Node*> nodes = CRSub->chillnodes;
if (1 != nodes.size() ) { // always just one?
- fprintf(stderr, "CG_chillBuilder::CreateSubstitutedStmt(), replacement is not one statement??\n");
+ CG_ERROR("Replacement is not one statement\n");
exit(-1);
}
- chillAST_Node *node = nodes[0]; // always just one?
-
- for (int i=0; i<oldnodes.size(); i++) {
- //fprintf(stderr, " statement %d ", i);
- //oldnodes[i]->print(); printf("\n\n"); fflush(stdout);
+ for (int i=0; i<oldnodes.size(); i++) {
oldnodes[i] = substituteChill( vars[j].c_str(), CRSub, oldnodes[i]);
}
}
}
-
- //fprintf(stderr, "\ncode after substituting variables:\n");
- //for(int i=0; i<oldnodes.size(); ++i){ printf("stmt = ");oldnodes[i]->print();printf("\n");}
- //fflush(stdout);
-
return new CG_chillRepr( oldnodes );
}
-
-
-
- //-----------------------------------------------------------------------------
- // assignment generation
- //-----------------------------------------------------------------------------
- CG_outputRepr* CG_chillBuilder::CreateAssignment(int indent,
+
+ CG_outputRepr* CG_chillBuilder::CreateAssignment(int indent,
CG_outputRepr *lhs,
CG_outputRepr *rhs) const {
- //fprintf(stderr, "CG_chillBuilder::CreateAssignment()\n");
if(lhs == NULL || rhs == NULL) {
- fprintf(stderr, "Code generation: Missing lhs or rhs\n");
+ CG_ERROR("Code generation: Missing lhs or rhs\n");
return NULL;
}
@@ -535,9 +212,8 @@ namespace omega {
CG_outputRepr* CG_chillBuilder::CreatePlusAssignment(int indent, // +=
CG_outputRepr *lhs,
CG_outputRepr *rhs) const {
- //fprintf(stderr, "CG_chillBuilder::CreatePlusAssignment()\n");
if(lhs == NULL || rhs == NULL) {
- fprintf(stderr, "Code generation: Missing lhs or rhs\n");
+ CHILL_ERROR("Code generation: Missing lhs or rhs\n");
return NULL;
}
@@ -559,107 +235,40 @@ namespace omega {
// function invocation generation
//-----------------------------------------------------------------------------
CG_outputRepr* CG_chillBuilder::CreateInvoke(const std::string &fname,
- std::vector<CG_outputRepr*> &list,
- bool is_array) const { // WHAT is an array?
- fprintf(stderr, "CG_roseBuilder::CreateInvoke( fname %s, ...)\n", fname.c_str());
- //fprintf(stderr, "%d things in list\n", list.size());
-
- // debugging output. print the "call"
- //fprintf(stderr, "%s", fname.c_str());
- //if (is_array) fprintf(stderr, "["); else fprintf(stderr, "(");
- //int numparams = list.size();
- //for (int i=0; i<numparams; i++) {
- // CG_chillRepr *CR = (CG_chillRepr *) list[i];
- // if (i) printf(",");
- // printf(" ");
- // CR->GetCode()->print();
- // fflush(stdout);
- //}
- //if (numparams) printf(" ");
- //if (is_array) printf("]\n"); else printf(")\n");
- //fflush(stdout);
-
+ std::vector<CG_outputRepr*> &list) const {
+ CG_DEBUG_PRINT("CG_roseBuilder::CreateInvoke( fname %s, ...)\n", fname.c_str());
-
- if (is_array) {
- //fprintf(stderr, "CG_chillBuilder::CreateInvoke() %s is_array\n", fname.c_str());
- const char *arrayname = fname.c_str();
-
- CG_chillRepr *CR = (CG_chillRepr *) list[0];
- chillAST_Node *cast = CR->GetCode();
-
- //fprintf(stderr, "%s[", arrayname);
- //cast->print(); printf("] ???\n"); fflush(stdout);
-
- // find the array variable (scope ?? TODO)
- chillAST_VarDecl *array = currentfunction->findArrayDecl( arrayname );
- if (!array) {
- fprintf(stderr, "CG_chillBuilder::CreateInvoke(), can't find array %s\n", fname.c_str());
- }
-
- // make a declrefexpr that refers to vardecl of array ?
- chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr( array );
- chillAST_ArraySubscriptExpr *ASE = new chillAST_ArraySubscriptExpr( DRE, cast, NULL, NULL);
- return new CG_chillRepr( ASE );
- }
-
-
if (fname == std::string("max") || fname == std::string("min")) {
if (list.size() == 0) { return NULL; }
else if (list.size() == 1) { return list[1]; }
else {
- //fprintf(stderr, "else\n");
int last = list.size()-1;
CG_outputRepr *CGOR;
CG_chillRepr *CGCR;
-
- //fprintf(stderr, "going to create call to %s( ", fname.c_str());
- //for (int i=0; i<list.size(); i++) {
- // CGCR = (CG_chillRepr*) list[i];
- // CGCR->chillnodes[0]->print(0, stderr);
- // if (i<(list.size()-1)) fprintf(stderr, ", ");
- //}
- //fprintf(stderr, ")\n");
-
char macroname[32];
char op;
-
if (fname == std::string("max")) op = '>';
else op = '<';
-
- // TODO >, check number of args etc
+ // TODO >, check number of args etc
chillAST_Node *ternary = lessthanmacro( ((CG_chillRepr*) list[0])->chillnodes[0],
((CG_chillRepr*) list[1])->chillnodes[0]);
-
- //fprintf(stderr, "just made ternary ");
- //ternary->print(0, stdout);
-
-
CG_chillRepr *repr = new CG_chillRepr( ternary );
- //fprintf(stderr, "returning callexpr with ternary\n", macroname);
return repr;
}
}
- //else { // special case for reduce?
- //}
else {
- //do a simple function call
- fprintf(stderr, "building a function call expression\n");
-
// try to find the function name, for a function in this file
const char *name = fname.c_str();
- //fprintf(stderr, "fname '%s'\n", name);
chillAST_SourceFile *src = toplevel; // todo don't be dumb
chillAST_Node *def = src->findCall(name);
- if (!def) { // can't find it
- fprintf(stderr, "CG_chillBuilder::CreateInvoke( %s ), can't find a function or macro by that name\n", name);
+ if (!def) {
+ CG_ERROR("CG_chillBuilder::CreateInvoke( %s ), can't find a function or macro by that name\n", name);
exit(-1);
}
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];
@@ -668,8 +277,6 @@ namespace omega {
return new CG_chillRepr( CE );
}
- // chillAST_CallExpr::chillAST_CallExpr(chillAST_Node *function, chillAST_Node *p );
-
// todo addarg()
//int numargs;
//std::vector<class chillAST_Node*> args;
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
diff --git a/lib/codegen/include/code_gen/CG_outputBuilder.h b/lib/codegen/include/code_gen/CG_outputBuilder.h
index cb0cd5d..58f8a2f 100644
--- a/lib/codegen/include/code_gen/CG_outputBuilder.h
+++ b/lib/codegen/include/code_gen/CG_outputBuilder.h
@@ -91,12 +91,10 @@ namespace omega {
* @brief function invoation generation
* @param funcName
* @param argList
- * @param is_array
* @return
*/
virtual CG_outputRepr *CreateInvoke(const std::string &funcName,
- std::vector<CG_outputRepr *> &argList,
- bool is_array = false) const = 0;
+ std::vector<CG_outputRepr *> &argList) const = 0;
/*!
* @brief comment generation
* @param indent
diff --git a/lib/codegen/include/code_gen/CG_stringBuilder.h b/lib/codegen/include/code_gen/CG_stringBuilder.h
index 390039a..ce33bde 100644
--- a/lib/codegen/include/code_gen/CG_stringBuilder.h
+++ b/lib/codegen/include/code_gen/CG_stringBuilder.h
@@ -21,7 +21,7 @@ public:
CG_stringRepr *CreateSubstitutedStmt(int indent, CG_outputRepr *stmt, const std::vector<std::string> &vars, std::vector<CG_outputRepr *> &subs, bool actuallyPrint) const;
CG_stringRepr *CreateAssignment(int indent, CG_outputRepr *lhs, CG_outputRepr *rhs) const;
CG_stringRepr *CreatePlusAssignment(int indent, CG_outputRepr *lhs, CG_outputRepr *rhs) const;
- CG_stringRepr *CreateInvoke(const std::string &funcName, std::vector<CG_outputRepr *> &argList,bool is_array=false) const;
+ CG_stringRepr *CreateInvoke(const std::string &funcName, std::vector<CG_outputRepr *> &argList) const;
CG_stringRepr *CreateComment(int indent, const std::string &commentText) const;
CG_stringRepr* CreateAttribute(CG_outputRepr *control,
const std::string &commentText) const;
diff --git a/lib/codegen/include/code_gen/CGdebug.h b/lib/codegen/include/code_gen/CGdebug.h
new file mode 100644
index 0000000..cf72c36
--- /dev/null
+++ b/lib/codegen/include/code_gen/CGdebug.h
@@ -0,0 +1,31 @@
+#ifndef CGDEBUG_H
+#define CGDEBUG_H
+
+#include <libgen.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef NDEBUG // means that CMAKE_BUILD_TYPE=Debug
+#define DEBUGCODEGEN
+#endif
+// This thing below potentially create leaks
+#define FILENAME basename(strdup(__FILE__))
+
+#ifdef DEBUGCODEGEN
+#define CG_DEBUG_PRINT(format,args...) fprintf(stderr,"%15s | %15s | LN%-4d:\t" format,FILENAME,__FUNCTION__, \
+ __LINE__, ##args )
+#define CG_DEBUG_BEGIN { \
+ fprintf(stderr,"=========\t%15s, %15s, LN%-4d\t=========\n",FILENAME,__FUNCTION__,__LINE__);
+#define CG_DEBUG_END fprintf(stderr,"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");}
+#else
+#define CG_DEBUG_PRINT(format,args...) do {} while(0) /* Don't do anything */
+#define CG_DEBUG_BEGIN while(0) {
+#define CG_DEBUG_END }
+#endif
+
+// TODO below should be substituted by some error throwing? to be more consistent with cpp style
+#define CG_ERROR(format,args...) fprintf(stderr,"ERROR:\t%s, %s, LN%d:\t" format,FILENAME,__FUNCTION__, \
+ __LINE__, ##args )
+
+
+#endif
diff --git a/lib/codegen/src/CG_stringBuilder.cc b/lib/codegen/src/CG_stringBuilder.cc
index d0f6693..7a19f66 100755
--- a/lib/codegen/src/CG_stringBuilder.cc
+++ b/lib/codegen/src/CG_stringBuilder.cc
@@ -182,11 +182,9 @@ namespace omega {
CG_stringRepr *CG_stringBuilder::CreateInvoke(const std::string &funcName,
- std::vector<CG_outputRepr *> &list,
- bool is_array) const {
+ std::vector<CG_outputRepr *> &list) const {
fprintf(stderr, "CG_stringBuilder::CreateInvoke( %s, ..., is_array ", funcName.c_str());
- if (is_array) fprintf(stderr, " true )\n");
- else fprintf(stderr, " false )\n");
+ fprintf(stderr, " false )\n");
std::string listStr = "";