summaryrefslogtreecommitdiff
path: root/src/ir_clang.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir_clang.cc')
-rwxr-xr-xsrc/ir_clang.cc479
1 files changed, 233 insertions, 246 deletions
diff --git a/src/ir_clang.cc b/src/ir_clang.cc
index c8a0c12..628e101 100755
--- a/src/ir_clang.cc
+++ b/src/ir_clang.cc
@@ -1,5 +1,3 @@
-
-
/*****************************************************************************
Copyright (C) 2009-2010 University of Utah
All Rights Reserved.
@@ -21,8 +19,6 @@ History:
#include "loop.hh"
#include "chill_error.hh"
-#define DUMPFUNC(x, y) std::cerr << "In function " << x << "\n"; y->dump();
-
#include "clang/Frontend/FrontendActions.h"
#include <clang/CodeGen/CodeGenAction.h>
#include <clang/Frontend/CompilerInstance.h>
@@ -45,50 +41,58 @@ History:
#include "chillAST.h"
+#define NL_RET(x) {chillAST_NodeList *ret = new chillAST_NodeList(); \
+ ret->push_back(x); \
+ return ret;}
+
// TODO move to ir_clang.hh
-// fwd declarations
-chillAST_node *ConvertVarDecl(clang::VarDecl *D, chillAST_node *);
-chillAST_node *ConvertTypeDefDecl(clang::TypedefDecl *TDD, chillAST_node *);
+chillAST_NodeList* ConvertTypeDefDecl(clang::TypedefDecl *TDD);
-chillAST_node *ConvertRecordDecl(clang::RecordDecl *D, chillAST_node *);
+chillAST_NodeList* ConvertRecordDecl(clang::RecordDecl *D);
-chillAST_node *ConvertDeclStmt(clang::DeclStmt *clangDS, chillAST_node *);
+chillAST_NodeList* ConvertDeclStmt(clang::DeclStmt *clangDS);
-chillAST_node *ConvertCompoundStmt(clang::CompoundStmt *clangCS, chillAST_node *);
+chillAST_NodeList* ConvertCompoundStmt(clang::CompoundStmt *clangCS);
-chillAST_node *ConvertFunctionDecl(clang::FunctionDecl *D, chillAST_node *);
+chillAST_NodeList* ConvertFunctionDecl(clang::FunctionDecl *D);
-chillAST_node *ConvertForStmt(clang::ForStmt *clangFS, chillAST_node *);
+chillAST_NodeList* ConvertForStmt(clang::ForStmt *clangFS);
-chillAST_node *ConvertUnaryOperator(clang::UnaryOperator *clangU, chillAST_node *O);
+chillAST_NodeList* ConvertUnaryOperator(clang::UnaryOperator *clangU);
-chillAST_node *ConvertBinaryOperator(clang::BinaryOperator *clangBO, chillAST_node *B);
+chillAST_NodeList* ConvertBinaryOperator(clang::BinaryOperator *clangBO);
-chillAST_node *ConvertArraySubscriptExpr(clang::ArraySubscriptExpr *clangASE, chillAST_node *);
+chillAST_NodeList* ConvertArraySubscriptExpr(clang::ArraySubscriptExpr *clangASE);
-chillAST_node *ConvertDeclRefExpr(clang::DeclRefExpr *clangDRE, chillAST_node *);
+chillAST_NodeList* ConvertDeclRefExpr(clang::DeclRefExpr *clangDRE);
-chillAST_node *ConvertIntegerLiteral(clang::IntegerLiteral *clangIL, chillAST_node *);
+chillAST_NodeList* ConvertIntegerLiteral(clang::IntegerLiteral *clangIL);
-chillAST_node *ConvertFloatingLiteral(clang::FloatingLiteral *clangFL, chillAST_node *);
+chillAST_NodeList* ConvertFloatingLiteral(clang::FloatingLiteral *clangFL);
-chillAST_node *ConvertImplicitCastExpr(clang::ImplicitCastExpr *clangICE, chillAST_node *);
+chillAST_NodeList* ConvertImplicitCastExpr(clang::ImplicitCastExpr *clangICE);
-chillAST_node *ConvertCStyleCastExpr(clang::CStyleCastExpr *clangICE, chillAST_node *);
+chillAST_NodeList* ConvertCStyleCastExpr(clang::CStyleCastExpr *clangICE);
-chillAST_node *ConvertReturnStmt(clang::ReturnStmt *clangRS, chillAST_node *);
+chillAST_NodeList* ConvertReturnStmt(clang::ReturnStmt *clangRS);
-chillAST_node *ConvertCallExpr(clang::CallExpr *clangCE, chillAST_node *);
+chillAST_NodeList* ConvertCallExpr(clang::CallExpr *clangCE);
-chillAST_node *ConvertIfStmt(clang::IfStmt *clangIS, chillAST_node *);
+chillAST_NodeList* ConvertIfStmt(clang::IfStmt *clangIS);
-chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *);
+chillAST_NodeList* ConvertMemberExpr(clang::MemberExpr *clangME);
-chillAST_node *ConvertTranslationUnit(clang::TranslationUnitDecl *TUD, char *filename);
+chillAST_NodeList* ConvertTranslationUnit(clang::TranslationUnitDecl *TUD, char *filename);
-chillAST_node *ConvertGenericClangAST(clang::Stmt *s, chillAST_node *);
+/*!
+ * \brief Convert fon Clang AST to CHiLL AST also append to parent node p if necessary
+ *
+ * @param s Clang statement
+ * @return A set of new statements
+ */
+chillAST_NodeList* ConvertGenericClangAST(clang::Stmt *s);
std::vector<chillAST_VarDecl *> VariableDeclarations;
@@ -170,6 +174,11 @@ void PrintTypeDefDecl(TypedefDecl *D, SourceManager *SRCMAN, int level);
void PrintVarDecl(VarDecl *D, SourceManager *SRCMAN, int level);
+chillAST_Node* unwrap(chillAST_NodeList* nl){
+ chillAST_Node* n = (*nl)[0];
+ delete nl;
+ return n;
+}
void printlines(SourceLocation &S, SourceLocation &E, SourceManager *SRCMAN) {
unsigned int startlineno = SRCMAN->getPresumedLineNumber(S);
@@ -382,28 +391,27 @@ void PrintCompoundStmt(Stmt *s, SourceManager *SRCMAN, int level) {
//fprintf(stderr, "CompoundStmt has %d children\n", numchildren);
-#ifdef DEBUGGING
- BUH
- for (Stmt::child_range I = cs->children(); I; ++I) {
- const char *classname = I->getStmtClassName();
- if (!strcmp(classname, "BinaryOperator")) {
- BinaryOperator *b = cast<BinaryOperator>(*I);
- BinaryOperator::Opcode op = b->getOpcode();
- if (op == BO_Assign) {
- fprintf(stderr, "compound statement has child of type ASSIGNMENT STATEMENT ");
- SourceLocation S = I->getLocStart();
- SourceLocation E = I->getLocEnd();
- unsigned int startlineno = SRCMAN->getPresumedLineNumber( S );
- unsigned int endlineno = SRCMAN->getPresumedLineNumber( E );
- fprintf(stderr, "(%d-%d)\n", startlineno, endlineno );
- }
- else
- fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName());
+ CHILL_DEBUG_BEGIN
+ for (Stmt::child_iterator I = cs->child_begin(); I!=cs->child_end(); ++I) {
+ const char *classname = I->getStmtClassName();
+ if (!strcmp(classname, "BinaryOperator")) {
+ BinaryOperator *b = cast<BinaryOperator>(*I);
+ BinaryOperator::Opcode op = b->getOpcode();
+ if (op == BO_Assign) {
+ fprintf(stderr, "compound statement has child of type ASSIGNMENT STATEMENT ");
+ SourceLocation S = I->getLocStart();
+ SourceLocation E = I->getLocEnd();
+ unsigned int startlineno = SRCMAN->getPresumedLineNumber( S );
+ unsigned int endlineno = SRCMAN->getPresumedLineNumber( E );
+ fprintf(stderr, "(%d-%d)\n", startlineno, endlineno );
}
else
fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName());
}
-#endif // debugging
+ else
+ fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName());
+ }
+ CHILL_DEBUG_END
for (auto I = cs->child_begin(); I != cs->child_end(); ++I) {
@@ -615,7 +623,7 @@ void PrintVarDecl(VarDecl *D, SourceManager *SRCMAN, int level) {
-chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) {
+chillAST_NodeList* ConvertVarDecl(VarDecl *D) {
//fprintf(stderr, "\nConvertVarDecl()\n");
//fprintf(stderr, "Decl has type %s\n", D->getDeclKindName());
//PrintVarDecl( D, globalSRCMAN, 0 );
@@ -639,7 +647,7 @@ chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) {
char *varname = strdup(D->getName().str().c_str());
//fprintf(stderr, "VarDecl (clang 0x%x) for %s %s%s\n", D, vartype, varname, arraypart);
- chillAST_VarDecl *chillVD = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, p /* , initializer */ );
+ chillAST_VarDecl *chillVD = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, NULL);
chillVD->isAParameter = isParm;
//fprintf(stderr, "\nthis is the vardecl\n");
@@ -730,11 +738,12 @@ chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) {
// store this away for declrefexpr that references it!
VariableDeclarations.push_back(chillVD);
- return chillVD;
+
+ NL_RET(chillVD);
}
-chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // for structs and unions
+chillAST_NodeList* ConvertRecordDecl(clang::RecordDecl *RD) { // for structs and unions
//fprintf(stderr, "ConvertRecordDecl( )\n\nclang sees\n");
//RD->dump();
@@ -753,7 +762,7 @@ chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // f
sprintf(blurb, "struct %s", RD->getNameAsString().c_str());
fprintf(stderr, "blurb is '%s'\n", blurb);
- chillAST_TypedefDecl *astruct = new chillAST_TypedefDecl(blurb, "", p);
+ chillAST_TypedefDecl *astruct = new chillAST_TypedefDecl(blurb, "", NULL);
astruct->setStruct(true);
astruct->setStructName(RD->getNameAsString().c_str());
@@ -779,11 +788,11 @@ chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // f
fprintf(stderr, "I just defined a struct\n");
astruct->print(0, stderr);
- return astruct;
+ NL_RET(astruct);
}
-chillAST_node *ConvertTypeDefDecl(TypedefDecl *TDD, chillAST_node *p) {
+chillAST_NodeList* ConvertTypeDefDecl(TypedefDecl *TDD) {
//fprintf(stderr, "ConvertTypedefDecl( ) \n");
//fprintf(stderr, "TDD has type %s\n", TDD->getDeclKindName());
//TDD->dump(); fprintf(stderr, "\n");
@@ -796,23 +805,24 @@ chillAST_node *ConvertTypeDefDecl(TypedefDecl *TDD, chillAST_node *p) {
char *alias = strdup(TDD->getName().str().c_str());
//fprintf(stderr, "underlying type %s arraypart '%s' name %s\n", under, arraypart, TDD->getName().str().c_str() );
- chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl(under, alias, arraypart, p);
+ chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl(under, alias, arraypart, NULL);
free(under);
free(arraypart);
- return CTDD;
+ NL_RET(CTDD);
}
-chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) {
+chillAST_NodeList* ConvertDeclStmt(DeclStmt *clangDS) {
//fprintf(stderr, "ConvertDeclStmt()\n");
chillAST_VarDecl *chillvardecl; // the thing we'll return if this is a single declaration
bool multiples = !clangDS->isSingleDecl();
if (multiples) {
- //fprintf(stderr, "ir_clang.cc multiple declarations in a single CLANG DeclStmt not really handled! (??)\n");
+ // TODO unhandled case
+ CHILL_ERROR("multiple declarations in a single CLANG DeclStmt not really handled! (??)\n");
// for now, try to make the multiple decls into a compoundstmt with them inside.
// if we don't get scoping problems, this might work
}
@@ -840,15 +850,13 @@ chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) {
//fprintf(stderr, "%s %s\n", td, varname);
char *arraypart = splitTypeInfo(vartype);
- chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, p);
+ chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, NULL);
//fprintf(stderr, "DeclStmt (clang 0x%x) for %s %s%s\n", D, vartype, varname, arraypart);
// store this away for declrefexpr that references it!
VariableDeclarations.push_back(chillvardecl);
- if (multiples) p->addChild(chillvardecl);
-
- // TODO
+ // TODO
if (V->hasInit()) {
CHILL_ERROR(" ConvertDeclStmt() UNHANDLED initialization\n");
exit(-1);
@@ -856,35 +864,34 @@ chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) {
}
} // for each of possibly multiple decls
- if (multiples) return NULL; // multiple decls added themselves already
- return chillvardecl; // OR a single decl
+ NL_RET(chillvardecl); // OR a single decl
}
-chillAST_node *ConvertCompoundStmt(CompoundStmt *clangCS, chillAST_node *p) {
+chillAST_NodeList* ConvertCompoundStmt(CompoundStmt *clangCS) {
//fprintf(stderr, "ConvertCompoundStmt( )\n");
int numchildren = clangCS->size();
//fprintf(stderr, "clang CompoundStmt has %d children\n", numchildren);
// make an empty CHILL compound statement
chillAST_CompoundStmt *chillCS = new chillAST_CompoundStmt;
- chillCS->setParent(p);
// for each clang child
for (auto I = clangCS->child_begin(); I != clangCS->child_end(); ++I) { // ?? loop looks WRONG
// create the chill ast for each child
Stmt *child = *I;
- chillAST_node *n = ConvertGenericClangAST(child, chillCS);
+ chillAST_NodeList* nl = ConvertGenericClangAST(child);
// usually n will be a statement. We just add it as a child.
// SOME DeclStmts have multiple declarations. They will add themselves and return NULL
- if (n) chillCS->addChild(n);
+ chillCS->addChildren(*nl);
+ delete nl;
}
- return chillCS;
+ NL_RET(chillCS);
}
-chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) {
+chillAST_NodeList* ConvertFunctionDecl(FunctionDecl *D) {
//fprintf(stderr, "\nConvertFunctionDecl( )\n");
QualType QT = D->getReturnType();
string ReturnTypeStr = QT.getAsString();
@@ -895,7 +902,7 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) {
//fprintf(stderr, "function %s has type %s ", FuncName.c_str(), ReturnTypeStr.c_str());
//fprintf(stderr, "\n%s %s()\n", ReturnTypeStr.c_str(), FuncName.c_str());
- chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl(ReturnTypeStr.c_str(), FuncName.c_str(), p, D);
+ chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl(ReturnTypeStr.c_str(), FuncName.c_str(), NULL, D);
int numparams = D->getNumParams();
@@ -907,14 +914,15 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) {
QualType T = pvd->getOriginalType();
CHILL_DEBUG_PRINT("OTYPE %s\n", T.getAsString().c_str());
- chillAST_VarDecl *chillPVD = (chillAST_VarDecl *) ConvertVarDecl(clangvardecl, chillFD);
+ chillAST_NodeList* nl = ConvertVarDecl(clangvardecl);
+ chillAST_VarDecl* decl = (chillAST_VarDecl*)unwrap(nl);
//chillPVD->print(); fflush(stdout);
//chillPVD->isAParameter = 1;
- VariableDeclarations.push_back(chillPVD);
+ VariableDeclarations.push_back(decl);
- chillFD->addParameter(chillPVD);
- CHILL_DEBUG_PRINT("chillAST ParmVarDecl for %s from chill location 0x%x\n", chillPVD->varname, clangvardecl);
+ chillFD->addParameter(decl);
+ CHILL_DEBUG_PRINT("chillAST ParmVarDecl for %s from chill location 0x%x\n", decl->varname, clangvardecl);
} // for each parameter
@@ -929,76 +937,63 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) {
Stmt *clangbody = D->getBody();
if (clangbody) { // may just be fwd decl or external, without an actual body
//fprintf(stderr, "body of type %s\n", clangbody->getStmtClassName());
- //chillAST_node *CB = ConvertCompoundStmt( dyn_cast<CompoundStmt>(clangbody) ); // always a compound statement?
- chillAST_node *CB = ConvertGenericClangAST(clangbody, chillFD);
+ //chillAST_Node *CB = ConvertCompoundStmt( dyn_cast<CompoundStmt>(clangbody) ); // always a compound statement?
+ chillAST_NodeList* nl = ConvertGenericClangAST(clangbody);
//fprintf(stderr, "FunctionDecl body = 0x%x of type %s\n", CB, CB->getTypeString());
- chillFD->setBody(CB);
+ chillFD->setBody(unwrap(nl));
}
//fprintf(stderr, "adding function %s 0x%x to FunctionDeclarations\n", chillFD->functionName, chillFD);
FunctionDeclarations.push_back(chillFD);
- return chillFD;
+ NL_RET(chillFD);
}
-chillAST_node *ConvertForStmt(ForStmt *clangFS, chillAST_node *p) {
-
- Stmt *init = clangFS->getInit();
- Expr *cond = clangFS->getCond();
- Expr *incr = clangFS->getInc();
- Stmt *body = clangFS->getBody();
+chillAST_NodeList* ConvertForStmt(ForStmt *clangFS) {
- chillAST_node *ini = ConvertGenericClangAST(init, NULL);
- chillAST_node *con = ConvertGenericClangAST(cond, NULL);
- chillAST_node *inc = ConvertGenericClangAST(incr, NULL);
- chillAST_node *bod = ConvertGenericClangAST(body, NULL);
- if (bod->asttype != CHILLAST_NODETYPE_COMPOUNDSTMT) {
- //fprintf(stderr, "ForStmt body of type %s\n", bod->getTypeString());
+ chillAST_Node *init = unwrap(ConvertGenericClangAST(clangFS->getInit()));
+ chillAST_Node *cond = unwrap(ConvertGenericClangAST(clangFS->getCond()));
+ chillAST_Node *incr = unwrap(ConvertGenericClangAST(clangFS->getInc()));
+ chillAST_Node *body = unwrap(ConvertGenericClangAST(clangFS->getBody()));
+ if (body->getType() != CHILLAST_NODE_COMPOUNDSTMT) {
// make single statement loop bodies loop like other loops
+ CHILL_DEBUG_PRINT("ForStmt body of type %s\n", body->getTypeString());
chillAST_CompoundStmt *cs = new chillAST_CompoundStmt();
- cs->addChild(bod);
- bod = cs;
+ cs->addChild(body);
+ body = cs;
}
-
-
- chillAST_ForStmt *chill_loop = new chillAST_ForStmt(ini, con, inc, bod, p);
- ini->setParent(chill_loop);
- con->setParent(chill_loop);
- inc->setParent(chill_loop);
- bod->setParent(chill_loop);
-
- return chill_loop;
+ chillAST_ForStmt *chill_loop = new chillAST_ForStmt(init, cond, incr, body, NULL);
+ NL_RET(chill_loop);
}
-chillAST_node *ConvertIfStmt(IfStmt *clangIS, chillAST_node *p) {
+chillAST_NodeList* ConvertIfStmt(IfStmt *clangIS) {
Expr *cond = clangIS->getCond();
Stmt *thenpart = clangIS->getThen();
Stmt *elsepart = clangIS->getElse();
- chillAST_node *con = ConvertGenericClangAST(cond, NULL);
- chillAST_node *thn = NULL;
- if (thenpart) thn = ConvertGenericClangAST(thenpart, NULL);
- chillAST_node *els = NULL;
- if (elsepart) els = ConvertGenericClangAST(elsepart, NULL);
+ chillAST_Node *con = unwrap(ConvertGenericClangAST(cond));
+ chillAST_Node *thn = NULL;
+ if (thenpart) thn = unwrap(ConvertGenericClangAST(thenpart));
+ chillAST_Node *els = NULL;
+ if (elsepart) els = unwrap(ConvertGenericClangAST(elsepart));
chillAST_IfStmt *ifstmt = new chillAST_IfStmt(con, thn, els, NULL);
- return ifstmt;
+ NL_RET(ifstmt);
}
-chillAST_node *ConvertUnaryOperator(UnaryOperator *clangUO, chillAST_node *p) {
+chillAST_NodeList* ConvertUnaryOperator(UnaryOperator *clangUO) {
const char *op = unops[clangUO->getOpcode()].c_str();
bool pre = clangUO->isPrefix();
- chillAST_node *sub = ConvertGenericClangAST(clangUO->getSubExpr(), NULL);
+ chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangUO->getSubExpr()));
- chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub, p);
- sub->setParent(chillUO);
- return chillUO;
+ chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub, NULL);
+ NL_RET(chillUO);
}
-chillAST_node *ConvertBinaryOperator(BinaryOperator *clangBO, chillAST_node *p) {
+chillAST_NodeList* ConvertBinaryOperator(BinaryOperator *clangBO) {
// get the clang parts
Expr *lhs = clangBO->getLHS();
@@ -1007,37 +1002,34 @@ chillAST_node *ConvertBinaryOperator(BinaryOperator *clangBO, chillAST_node *p)
// convert to chill equivalents
- chillAST_node *l = ConvertGenericClangAST(lhs, NULL);
+ chillAST_Node *l = unwrap(ConvertGenericClangAST(lhs));
const char *opstring = binops[op].c_str();
- chillAST_node *r = ConvertGenericClangAST(rhs, NULL);
+ chillAST_Node *r = unwrap(ConvertGenericClangAST(rhs));
// TODO chill equivalent for numeric op.
// build up the chill Binary Op AST node
- chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r, p);
- l->setParent(binop);
- r->setParent(binop);
+ chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r, NULL);
- return binop;
+ NL_RET(binop);
}
-chillAST_node *ConvertArraySubscriptExpr(ArraySubscriptExpr *clangASE, chillAST_node *p) {
+chillAST_NodeList* ConvertArraySubscriptExpr(ArraySubscriptExpr *clangASE) {
Expr *clangbase = clangASE->getBase();
Expr *clangindex = clangASE->getIdx();
//fprintf(stderr, "clang base: "); clangbase->dump(); fprintf(stderr, "\n");
- chillAST_node *bas = ConvertGenericClangAST(clangbase, NULL);
- chillAST_node *indx = ConvertGenericClangAST(clangindex, NULL);
+ chillAST_Node *bas = unwrap(ConvertGenericClangAST(clangbase));
+ chillAST_Node *indx = unwrap(ConvertGenericClangAST(clangindex));
- chillAST_ArraySubscriptExpr *chillASE = new chillAST_ArraySubscriptExpr(bas, indx, p, clangASE);
- bas->setParent(chillASE);
- indx->setParent(chillASE);
- return chillASE;
+ // TODO clangAST contamination
+ chillAST_ArraySubscriptExpr *chillASE = new chillAST_ArraySubscriptExpr(bas, indx, NULL, clangASE);
+ NL_RET(chillASE);
}
-chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) {
+chillAST_NodeList* ConvertDeclRefExpr(DeclRefExpr *clangDRE) {
DeclarationNameInfo DNI = clangDRE->getNameInfo();
ValueDecl *vd = static_cast<ValueDecl *>(clangDRE->getDecl()); // ValueDecl ?? VarDecl ??
@@ -1049,7 +1041,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) {
DeclarationName DN = DNI.getName();
const char *varname = DN.getAsString().c_str();
- chillAST_DeclRefExpr *chillDRE = new chillAST_DeclRefExpr(TypeStr.c_str(), varname, p);
+ chillAST_DeclRefExpr *chillDRE = new chillAST_DeclRefExpr(TypeStr.c_str(), varname, NULL);
//fprintf(stderr, "clang DeclRefExpr refers to declaration of %s @ 0x%x\n", varname, vd);
//fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName());
@@ -1082,7 +1074,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) {
exit(-1);
}
- chillDRE->decl = (chillAST_node *) chillvd; // start of spaghetti pointers ...
+ chillDRE->decl = (chillAST_Node *) chillvd; // start of spaghetti pointers ...
} else if (!strcmp("Function", vd->getDeclKindName())) {
//fprintf(stderr, "declrefexpr of type Function\n");
int numfuncs = FunctionDeclarations.size();
@@ -1098,7 +1090,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) {
exit(-1);
}
- chillDRE->decl = (chillAST_node *) chillfd; // start of spaghetti pointers ...
+ chillDRE->decl = (chillAST_Node *) chillfd; // start of spaghetti pointers ...
} else {
fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName());
@@ -1106,23 +1098,23 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) {
exit(-1);
}
- //fprintf(stderr, "%s\n", DN.getAsString().c_str());
- return chillDRE;
+ //fprintf(stderr, "%s\n", DN.getAsString().c_str());
+ NL_RET(chillDRE);
}
-chillAST_node *ConvertIntegerLiteral(IntegerLiteral *clangIL, chillAST_node *p) {
+chillAST_NodeList* ConvertIntegerLiteral(IntegerLiteral *clangIL) {
bool isSigned = clangIL->getType()->isSignedIntegerType();
//int val = clangIL->getIntValue();
const char *printable = clangIL->getValue().toString(10, isSigned).c_str();
int val = atoi(printable);
//fprintf(stderr, "int value %s (%d)\n", printable, val);
- chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral(val, p);
- return chillIL;
+ chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral(val, NULL);
+ NL_RET(chillIL);
}
-chillAST_node *ConvertFloatingLiteral(FloatingLiteral *clangFL, chillAST_node *p) {
+chillAST_NodeList* ConvertFloatingLiteral(FloatingLiteral *clangFL) {
//fprintf(stderr, "\nConvertFloatingLiteral()\n");
float val = clangFL->getValueAsApproximateDouble(); // TODO approx is a bad idea!
string WHAT;
@@ -1186,30 +1178,29 @@ chillAST_node *ConvertFloatingLiteral(FloatingLiteral *clangFL, chillAST_node *p
buf[len] = '\0';
//fprintf(stderr, "'%s'\n", buf);
- chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf, p);
+ chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf, NULL);
- //chillFL->print(); printf("\n"); fflush(stdout);
- return chillFL;
+ //chillFL->print(); printf("\n"); fflush(stdout);
+ NL_RET(chillFL);
}
-chillAST_node *ConvertImplicitCastExpr(ImplicitCastExpr *clangICE, chillAST_node *p) {
+chillAST_NodeList* ConvertImplicitCastExpr(ImplicitCastExpr *clangICE) {
//fprintf(stderr, "ConvertImplicitCastExpr()\n");
CastExpr *CE = dyn_cast<ImplicitCastExpr>(clangICE);
//fprintf(stderr, "implicit cast of type %s\n", CE->getCastKindName());
- chillAST_node *sub = ConvertGenericClangAST(clangICE->getSubExpr(), p);
- chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub, p);
+ chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangICE->getSubExpr()));
+ chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub, NULL);
//sub->setParent( chillICE ); // these 2 lines work
//return chillICE;
- //sub->setParent(p); // ignore the ImplicitCastExpr !! TODO (probably a bad idea)
- return sub;
-
+ //sub->setParent(p); // ignore the ImplicitCastExpr !! TODO (probably a bad idea)
+ NL_RET(chillICE);
}
-chillAST_node *ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE, chillAST_node *p) {
+chillAST_NodeList* ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE) {
//fprintf(stderr, "ConvertCStyleCastExpr()\n");
//fprintf(stderr, "C Style cast of kind ");
CastExpr *CE = dyn_cast<CastExpr>(clangCSCE);
@@ -1219,58 +1210,54 @@ chillAST_node *ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE, chillAST_node *p
const char *towhat = strdup(clangCSCE->getTypeAsWritten().getAsString().c_str());
//fprintf(stderr, "before sub towhat (%s)\n", towhat);
- chillAST_node *sub = ConvertGenericClangAST(clangCSCE->getSubExprAsWritten(), NULL);
+ chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangCSCE->getSubExprAsWritten()));
//fprintf(stderr, "after sub towhat (%s)\n", towhat);
- chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub, p);
+ chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub, NULL);
//fprintf(stderr, "after CSCE towhat (%s)\n", towhat);
- sub->setParent(chillCSCE);
- return chillCSCE;
+ NL_RET(chillCSCE);
}
-chillAST_node *ConvertReturnStmt(ReturnStmt *clangRS, chillAST_node *p) {
- chillAST_node *retval = ConvertGenericClangAST(clangRS->getRetValue(), NULL); // NULL is handled
+chillAST_NodeList* ConvertReturnStmt(ReturnStmt *clangRS) {
+ chillAST_Node *retval = unwrap(ConvertGenericClangAST(clangRS->getRetValue())); // NULL is handled
//if (retval == NULL) fprintf(stderr, "return stmt returns nothing\n");
- chillAST_ReturnStmt *chillRS = new chillAST_ReturnStmt(retval, p);
- if (retval) retval->setParent(chillRS);
- return chillRS;
+ chillAST_ReturnStmt *chillRS = new chillAST_ReturnStmt(retval, NULL);
+ NL_RET(chillRS);
}
-chillAST_node *ConvertCallExpr(CallExpr *clangCE, chillAST_node *p) {
+chillAST_NodeList* ConvertCallExpr(CallExpr *clangCE) {
//fprintf(stderr, "ConvertCallExpr()\n");
- chillAST_node *callee = ConvertGenericClangAST(clangCE->getCallee(), NULL);
+ chillAST_Node *callee = unwrap(ConvertGenericClangAST(clangCE->getCallee()));
//fprintf(stderr, "callee is of type %s\n", callee->getTypeString());
- //chillAST_node *next = ((chillAST_ImplicitCastExpr *)callee)->subexpr;
+ //chillAST_Node *next = ((chillAST_ImplicitCastExpr *)callee)->subexpr;
//fprintf(stderr, "callee is of type %s\n", next->getTypeString());
- chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee, p);
- callee->setParent(chillCE);
+ chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee, NULL);
int numargs = clangCE->getNumArgs();
//fprintf(stderr, "CallExpr has %d args\n", numargs);
Expr **clangargs = clangCE->getArgs();
for (int i = 0; i < numargs; i++) {
- chillCE->addArg(ConvertGenericClangAST(clangargs[i], chillCE));
+ chillCE->addArg(unwrap(ConvertGenericClangAST(clangargs[i])));
}
- return chillCE;
+ NL_RET(chillCE);
}
-chillAST_node *ConvertParenExpr(ParenExpr *clangPE, chillAST_node *p) {
- chillAST_node *sub = ConvertGenericClangAST(clangPE->getSubExpr(), NULL);
- chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub, p);
- sub->setParent(chillPE);
+chillAST_NodeList* ConvertParenExpr(ParenExpr *clangPE) {
+ chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangPE->getSubExpr()));
+ chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub, NULL);
- return chillPE;
+ NL_RET(chillPE);
}
-chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) {
+chillAST_NodeList* ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) {
//fprintf(stderr, "ConvertTranslationUnit( filename %s )\n\n", filename);
// TUD derived from Decl and DeclContext
static DeclContext *DC = TUD->castToDeclContext(TUD);
@@ -1297,20 +1284,20 @@ chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename)
Decl *D = *DI;
if (isa<FunctionDecl>(D)) { //fprintf(stderr, "\nTUD FunctionDecl\n");
- topnode->addChild(ConvertFunctionDecl(dyn_cast<FunctionDecl>(D), topnode));
+ topnode->addChild(unwrap(ConvertFunctionDecl(dyn_cast<FunctionDecl>(D))));
} else if (isa<VarDecl>(D)) { //fprintf(stderr, "\nTUD VarDecl\n");
- topnode->addChild(ConvertVarDecl(dyn_cast<VarDecl>(D), topnode));
+ topnode->addChild(unwrap(ConvertVarDecl(dyn_cast<VarDecl>(D))));
//fflush(stdout); fprintf(stderr, "\nTUD VarDecl DONE\n");
} else if (isa<TypedefDecl>(D)) { //fprintf(stderr, "\nTUD TypedefDecl\n");
- topnode->addChild(ConvertTypeDefDecl(dyn_cast<TypedefDecl>(D), topnode));
+ topnode->addChild(unwrap(ConvertTypeDefDecl(dyn_cast<TypedefDecl>(D))));
} else if (isa<RecordDecl>(D)) {
- fprintf(stderr, "\nTUD RecordDecl\n");
- topnode->addChild(ConvertRecordDecl(dyn_cast<RecordDecl>(D), topnode));
+ CHILL_DEBUG_PRINT("\nTUD RecordDecl\n");
+ topnode->addChild(unwrap(ConvertRecordDecl(dyn_cast<RecordDecl>(D))));
} else if (isa<TypeAliasDecl>(D)) {
- fprintf(stderr, "TUD TypeAliasDecl TODO \n");
+ CHILL_ERROR("TUD TypeAliasDecl TODO \n");
exit(-1);
} else {
- fprintf(stderr, "\nTUD a declaration of type %s (%d) which I can't handle\n", D->getDeclKindName(), D->getKind());
+ CHILL_ERROR("\nTUD a declaration of type %s (%d) which I can't handle\n", D->getDeclKindName(), D->getKind());
exit(-1);
}
}
@@ -1318,11 +1305,11 @@ chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename)
//fprintf(stderr, "in ConvertTranslationUnit(), dumping the file\n");
//topnode->dump();
- return (chillAST_node *) topnode;
+ NL_RET(topnode);
}
-chillAST_node *ConvertGenericClangAST(Stmt *s, chillAST_node *p) {
+chillAST_NodeList* ConvertGenericClangAST(Stmt *s) {
if (s == NULL) return NULL;
//fprintf(stderr, "\nConvertGenericClangAST() Stmt of type %d (%s)\n", s->getStmtClass(),s->getStmtClassName());
@@ -1330,40 +1317,40 @@ chillAST_node *ConvertGenericClangAST(Stmt *s, chillAST_node *p) {
//if (isa<Decl>(D)) fprintf(stderr, "Decl of kind %d (%s)\n", D->getKind(),D->getDeclKindName() );
- chillAST_node *ret = NULL;
+ chillAST_NodeList *ret = NULL; // find the SINGLE constant or data reference at this node or below
if (isa<CompoundStmt>(s)) {
- ret = ConvertCompoundStmt(dyn_cast<CompoundStmt>(s), p);
+ ret = ConvertCompoundStmt(dyn_cast<CompoundStmt>(s));
} else if (isa<DeclStmt>(s)) {
- ret = ConvertDeclStmt(dyn_cast<DeclStmt>(s), p);
+ ret = ConvertDeclStmt(dyn_cast<DeclStmt>(s));
} else if (isa<ForStmt>(s)) {
- ret = ConvertForStmt(dyn_cast<ForStmt>(s), p);
+ ret = ConvertForStmt(dyn_cast<ForStmt>(s));
} else if (isa<BinaryOperator>(s)) {
- ret = ConvertBinaryOperator(dyn_cast<BinaryOperator>(s), p);
+ ret = ConvertBinaryOperator(dyn_cast<BinaryOperator>(s));
} else if (isa<ArraySubscriptExpr>(s)) {
- ret = ConvertArraySubscriptExpr(dyn_cast<ArraySubscriptExpr>(s), p);
+ ret = ConvertArraySubscriptExpr(dyn_cast<ArraySubscriptExpr>(s));
} else if (isa<DeclRefExpr>(s)) {
- ret = ConvertDeclRefExpr(dyn_cast<DeclRefExpr>(s), p);
+ ret = ConvertDeclRefExpr(dyn_cast<DeclRefExpr>(s));
} else if (isa<FloatingLiteral>(s)) {
- ret = ConvertFloatingLiteral(dyn_cast<FloatingLiteral>(s), p);
+ ret = ConvertFloatingLiteral(dyn_cast<FloatingLiteral>(s));
} else if (isa<IntegerLiteral>(s)) {
- ret = ConvertIntegerLiteral(dyn_cast<IntegerLiteral>(s), p);
+ ret = ConvertIntegerLiteral(dyn_cast<IntegerLiteral>(s));
} else if (isa<UnaryOperator>(s)) {
- ret = ConvertUnaryOperator(dyn_cast<UnaryOperator>(s), p);
+ ret = ConvertUnaryOperator(dyn_cast<UnaryOperator>(s));
} else if (isa<ImplicitCastExpr>(s)) {
- ret = ConvertImplicitCastExpr(dyn_cast<ImplicitCastExpr>(s), p);
+ ret = ConvertImplicitCastExpr(dyn_cast<ImplicitCastExpr>(s));
} else if (isa<CStyleCastExpr>(s)) {
- ret = ConvertCStyleCastExpr(dyn_cast<CStyleCastExpr>(s), p);
+ ret = ConvertCStyleCastExpr(dyn_cast<CStyleCastExpr>(s));
} else if (isa<ReturnStmt>(s)) {
- ret = ConvertReturnStmt(dyn_cast<ReturnStmt>(s), p);
+ ret = ConvertReturnStmt(dyn_cast<ReturnStmt>(s));
} else if (isa<CallExpr>(s)) {
- ret = ConvertCallExpr(dyn_cast<CallExpr>(s), p);
+ ret = ConvertCallExpr(dyn_cast<CallExpr>(s));
} else if (isa<ParenExpr>(s)) {
- ret = ConvertParenExpr(dyn_cast<ParenExpr>(s), p);
+ ret = ConvertParenExpr(dyn_cast<ParenExpr>(s));
} else if (isa<IfStmt>(s)) {
- ret = ConvertIfStmt(dyn_cast<IfStmt>(s), p);
+ ret = ConvertIfStmt(dyn_cast<IfStmt>(s));
} else if (isa<MemberExpr>(s)) {
- ret = ConvertMemberExpr(dyn_cast<MemberExpr>(s), p);
+ ret = ConvertMemberExpr(dyn_cast<MemberExpr>(s));
// these can only happen at the top level?
@@ -1611,7 +1598,7 @@ IR_ArraySymbol *IR_chillArrayRef::symbol() const {
//fprintf(stderr, "base: "); chillASE->base->print(); printf("\n"); fflush(stdout);
- chillAST_node *mb = chillASE->multibase();
+ chillAST_Node *mb = chillASE->multibase();
chillAST_VarDecl *vd = (chillAST_VarDecl *) mb;
//fprintf(stderr, "symbol: '%s'\n", vd->varname);
@@ -1621,22 +1608,22 @@ IR_ArraySymbol *IR_chillArrayRef::symbol() const {
//fprintf(stderr, "ir_clang.cc returning IR_chillArraySymbol 0x%x\n", AS);
return AS;
/*
- chillAST_node *b = chillASE->base;
+ chillAST_Node *b = chillASE->base;
fprintf(stderr, "base of type %s\n", b->getTypeString());
//b->print(); printf("\n"); fflush(stdout);
- if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) {
+ if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) {
b = ((chillAST_ImplicitCastExpr*)b)->subexpr;
fprintf(stderr, "base of type %s\n", b->getTypeString());
}
- if (b->asttype == CHILLAST_NODETYPE_DECLREFEXPR) {
+ if (b->getType() == CHILLAST_NODE_DECLREFEXPR) {
if (NULL == ((chillAST_DeclRefExpr*)b)->decl) {
fprintf(stderr, "IR_chillArrayRef::symbol() var decl = 0x%x\n", ((chillAST_DeclRefExpr*)b)->decl);
exit(-1);
}
return new IR_chillArraySymbol(ir_, ((chillAST_DeclRefExpr*)b)->decl); // -> decl?
}
- if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { // multidimensional array
+ if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { // multidimensional array
return (
}
fprintf(stderr, "IR_chillArrayRef::symbol() can't handle\n");
@@ -1726,25 +1713,25 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
chillupperbound = cond->getRHS();
conditionoperator = achillforstmt->conditionoperator;
- chillAST_node *inc = chillforstmt->getInc();
+ chillAST_Node *inc = chillforstmt->getInc();
// check the increment
//fprintf(stderr, "increment is of type %s\n", inc->getTypeString());
//inc->print(); printf("\n"); fflush(stdout);
- if (inc->asttype == CHILLAST_NODETYPE_UNARYOPERATOR) {
+ if (inc->getType() == CHILLAST_NODE_UNARYOPERATOR) {
if (!strcmp(((chillAST_UnaryOperator *) inc)->op, "++")) step_size_ = 1;
else step_size_ = -1;
- } else if (inc->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) {
+ } else if (inc->getType() == CHILLAST_NODE_BINARYOPERATOR) {
int beets = false; // slang
chillAST_BinaryOperator *bop = (chillAST_BinaryOperator *) inc;
if (bop->isAssignmentOp()) { // I=I+1 or similar
- chillAST_node *rhs = bop->getRHS(); // (I+1)
+ chillAST_Node *rhs = bop->getRHS(); // (I+1)
// TODO looks like this will fail for I=1+I or I=J+1 etc. do more checking
char *assop = bop->getOp();
//fprintf(stderr, "'%s' is an assignment op\n", bop->getOp());
if (streq(assop, "+=") || streq(assop, "-=")) {
- chillAST_node *stride = rhs;
+ chillAST_Node *stride = rhs;
//fprintf(stderr, "stride is of type %s\n", stride->getTypeString());
if (stride->isIntegerLiteral()) {
int val = ((chillAST_IntegerLiteral *) stride)->value;
@@ -1754,7 +1741,7 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) {
} else beets = true; // += or -= but not constant stride
} else if (rhs->isBinaryOperator()) {
chillAST_BinaryOperator *binoprhs = (chillAST_BinaryOperator *) rhs;
- chillAST_node *intlit = binoprhs->getRHS();
+ chillAST_Node *intlit = binoprhs->getRHS();
if (intlit->isIntegerLiteral()) {
int val = ((chillAST_IntegerLiteral *) intlit)->value;
if (!strcmp(binoprhs->getOp(), "+")) step_size_ = val;
@@ -1881,13 +1868,13 @@ void IR_chillBlock::dump() const {
}
//StmtList
-vector<chillAST_node *> IR_chillBlock::getStmtList() const {
+vector<chillAST_Node *> IR_chillBlock::getStmtList() const {
fprintf(stderr, "IR_xxxxBlock::getStmtList()\n");
return statements; // ??
}
-void IR_chillBlock::addStatement(chillAST_node *s) {
+void IR_chillBlock::addStatement(chillAST_Node *s) {
statements.push_back(s);
}
@@ -1921,10 +1908,10 @@ class NULLASTConsumer : public ASTConsumer {
};
-void findmanually(chillAST_node *node, char *procname, std::vector<chillAST_node *> &procs) {
+void findmanually(chillAST_Node *node, char *procname, std::vector<chillAST_Node *> &procs) {
//fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString());
- if (node->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) {
+ if (node->getType() == CHILLAST_NODE_FUNCTIONDECL) {
char *name = ((chillAST_FunctionDecl *) node)->functionName;
//fprintf(stderr, "node name 0x%x ", name);
//fprintf(stderr, "%s procname ", name);
@@ -2078,7 +2065,7 @@ aClangCompiler::aClangCompiler(char *filename) {
// create another AST, very similar to the clang AST but not written by idiots
CHILL_DEBUG_PRINT("converting entire clang AST into chill AST (ir_clang.cc)\n");
- chillAST_node *wholefile = ConvertTranslationUnit(TUD, filename);
+ chillAST_Node *wholefile = unwrap(ConvertTranslationUnit(TUD, filename));
fflush(stdout);
//fprintf(stderr, "printing whole file\n");
@@ -2140,7 +2127,7 @@ chillAST_FunctionDecl *aClangCompiler::findprocedurebyname(char *procname) {
//fprintf(stderr, "searching through files in the clang AST\n\n");
//fprintf(stderr, "astContext_ 0x%x\n", astContext_);
- std::vector<chillAST_node *> procs;
+ std::vector<chillAST_Node *> procs;
findmanually(entire_file_AST, procname, procs);
//fprintf(stderr, "procs has %d members\n", procs.size());
@@ -2267,7 +2254,7 @@ IR_clangCode::IR_clangCode(const char *fname, const char *proc_name) : IR_Code()
pInstance->setCurrentFunction(localFD);
- chillAST_node *b = localFD->getBody(); // we do this just because it will get done next
+ chillAST_Node *b = localFD->getBody(); // we do this just because it will get done next
CHILL_DEBUG_PRINT("calling new CG_chillBuilder() umwut?\n");
ocg_ = new omega::CG_chillBuilder(); // ocg == omega code gen
@@ -2300,7 +2287,7 @@ IR_clangCode::~IR_clangCode() {
// TODO should output the entire file, not just the function we're working on
chillAST_SourceFile *src = chillfunc->getSourceFile();
- //chillAST_node *p = chillfunc->parent; // should be translationDeclUnit
+ //chillAST_Node *p = chillfunc->parent; // should be translationDeclUnit
if (src) {
//src->print(); // tmp
if (src->isSourceFile()) src->printToFile();
@@ -2319,7 +2306,7 @@ IR_ScalarSymbol *IR_clangCode::CreateScalarSymbol(const IR_Symbol *sym, int i) {
// do we have to check to see if it's already there?
VariableDeclarations.push_back(vd);
- chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ??
+ chillAST_Node *bod = chillfunc->getBody(); // always a compoundStmt ??
bod->insertChild(0, vd);
fprintf(stderr, "returning ... really\n");
return new IR_chillScalarSymbol(this, CSS->chillvd); // CSS->clone();
@@ -2392,7 +2379,7 @@ IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outp
exit(-1);
}
- chillAST_node *nodezero = CR->chillnodes[0];
+ chillAST_Node *nodezero = CR->chillnodes[0];
if (!nodezero->isIntegerLiteral()) {
fprintf(stderr, "IR_clangCode::CreateArraySymbol() array dimension %d not an IntegerLiteral\n", i);
exit(-1);
@@ -2410,7 +2397,7 @@ IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outp
// put decl in some symbol table
VariableDeclarations.push_back(vd);
// insert decl in the IR_code body
- chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ??
+ chillAST_Node *bod = chillfunc->getBody(); // always a compoundStmt ??
bod->insertChild(0, vd);
return new IR_chillArraySymbol(this, vd);
@@ -2449,7 +2436,7 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector
const IR_chillArraySymbol *c_sym = static_cast<const IR_chillArraySymbol *>(sym);
chillAST_VarDecl *vd = c_sym->chillvd;
- std::vector<chillAST_node *> inds;
+ std::vector<chillAST_Node *> inds;
//fprintf(stderr, "%d array indeces\n", sym->n_dim());
for (int i = 0; i < index.size(); i++) {
@@ -2466,7 +2453,7 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector
inds.push_back(CR->chillnodes[0]);
/*
- chillAST_node *nodezero = CR->chillnodes[0];
+ chillAST_Node *nodezero = CR->chillnodes[0];
if (!nodezero->isIntegerLiteral()) {
fprintf(stderr,"IR_clangCode::CreateArrayRef() array dimension %d not an IntegerLiteral\n",i);
fprintf(stderr, "it is a %s\n", nodezero->getTypeString());
@@ -2495,7 +2482,7 @@ std::vector<IR_ArrayRef *> IR_clangCode::FindArrayRef(const omega::CG_outputRepr
//fprintf(stderr, "FindArrayRef()\n");
std::vector<IR_ArrayRef *> arrays;
const omega::CG_chillRepr *crepr = static_cast<const omega::CG_chillRepr *>(repr);
- std::vector<chillAST_node *> chillstmts = crepr->getChillCode();
+ std::vector<chillAST_Node *> chillstmts = crepr->getChillCode();
//fprintf(stderr, "there are %d chill statements in this repr\n", chillstmts.size());
@@ -2591,7 +2578,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
std::vector<IR_Control *> controls;
- chillAST_node *blockast = NULL;
+ chillAST_Node *blockast = NULL;
int numstmts = CB->statements.size();
CHILL_DEBUG_PRINT("%d statements\n", numstmts);
@@ -2609,7 +2596,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
CHILL_DEBUG_END
- //vector<chillAST_node *> funcchildren = chillfunc->getChildren();
+ //vector<chillAST_Node *> funcchildren = chillfunc->getChildren();
//fprintf(stderr, "%d children of clangcode\n", funcchildren.size()); // includes parameters
// build up a vector of "controls".
@@ -2617,10 +2604,10 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
// bundled up into an IR_Block
// ifs and loops will get their own entry
- std::vector<chillAST_node *> children;
+ std::vector<chillAST_Node *> children;
- if (blockast->asttype == CHILLAST_NODETYPE_FORSTMT) {
+ if (blockast->getType() == CHILLAST_NODE_FORSTMT) {
CHILL_DEBUG_BEGIN
fflush(stdout);
fprintf(stderr, "found a top level For statement (Loop)\n");
@@ -2631,17 +2618,17 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) blockast));
}
- //else if (blockast->asttype == CHILLAST_NODETYPE_IFSTMT) {
+ //else if (blockast->getType() == CHILLAST_NODE_IFSTMT) {
// controls.push_back( new IR_clangIf( this, (chillAST_IfStmt *)blockast));
//}
- else if (blockast->asttype == CHILLAST_NODETYPE_COMPOUNDSTMT ||
- blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) {
+ else if (blockast->getType() == CHILLAST_NODE_COMPOUNDSTMT ||
+ blockast->getType() == CHILLAST_NODE_FUNCTIONDECL) {
- if (blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) {
- //fprintf(stderr, "ir_clanc.cc blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL\n");
+ if (blockast->getType() == CHILLAST_NODE_FUNCTIONDECL) {
+ //fprintf(stderr, "ir_clanc.cc blockast->getType() == CHILLAST_NODE_FUNCTIONDECL\n");
chillAST_FunctionDecl *FD = (chillAST_FunctionDecl *) blockast;
- chillAST_node *bod = FD->getBody();
+ chillAST_Node *bod = FD->getBody();
//fprintf(stderr, "bod 0x%x\n", bod);
children = bod->getChildren();
@@ -2667,8 +2654,8 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
IR_chillBlock *basicblock = new IR_chillBlock(this); // no statements
for (int i = 0; i < numchildren; i++) {
//fprintf(stderr, "child %d is of type %s\n", i, children[i]->getTypeString());
- CHILL_ASTNODE_TYPE typ = children[i]->asttype;
- if (typ == CHILLAST_NODETYPE_LOOP) {
+ CHILLAST_NODE_TYPE typ = children[i]->getType();
+ if (typ == CHILLAST_NODE_LOOP) {
if (numchildren == 1) {
CHILL_DEBUG_PRINT("found a For statement (Loop)\n");
} else {
@@ -2687,7 +2674,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) children[i]));
}
- //else if (typ == CHILLAST_NODETYPE_IFSTMT ) // TODO
+ //else if (typ == CHILLAST_NODE_IFSTMT ) // TODO
else { // straight line code
basicblock->addStatement(children[i]);
CHILL_DEBUG_BEGIN
@@ -2730,8 +2717,8 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C
IR_chillBlock *CBlock = new IR_chillBlock(controls[0]->ir_); // the thing we're building
- std::vector<chillAST_node *> statements;
- chillAST_node *parent = NULL;
+ std::vector<chillAST_Node *> statements;
+ chillAST_Node *parent = NULL;
for (int i = 0; i < controls.size(); i++) {
switch (controls[i]->type()) {
case IR_CONTROL_LOOP: {
@@ -2750,7 +2737,7 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C
case IR_CONTROL_BLOCK: {
CHILL_DEBUG_PRINT("control %d is IR_CONTROL_BLOCK\n", i);
IR_chillBlock *CB = static_cast<IR_chillBlock *>(controls[i]);
- std::vector<chillAST_node *> blockstmts = CB->statements;
+ std::vector<chillAST_Node *> blockstmts = CB->statements;
for (int j = 0; j < blockstmts.size(); j++) {
if (parent == NULL) {
parent = blockstmts[j]->parent;
@@ -2778,7 +2765,7 @@ IR_Block *IR_clangCode::GetCode() const { // return IR_Block corresponding to
//Stmt *s = func_->getBody(); // clang statement, and clang getBody
//fprintf(stderr, "chillfunc 0x%x\n", chillfunc);
- //chillAST_node *bod = chillfunc->getBody(); // chillAST
+ //chillAST_Node *bod = chillfunc->getBody(); // chillAST
//fprintf(stderr, "printing the function getBody()\n");
//fprintf(stderr, "sourceManager 0x%x\n", sourceManager);
//bod->print();
@@ -2792,7 +2779,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
fprintf(stderr, "IR_xxxxCode::ReplaceCode( old, *repr)\n");
CG_chillRepr *chillrepr = (CG_chillRepr *) repr;
- std::vector<chillAST_node *> newcode = chillrepr->getChillCode();
+ std::vector<chillAST_Node *> newcode = chillrepr->getChillCode();
int numnew = newcode.size();
//fprintf(stderr, "new code (%d) is\n", numnew);
@@ -2855,7 +2842,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
}
}
- chillAST_node *par;
+ chillAST_Node *par;
switch (old->type()) {
case IR_CONTROL_LOOP: {
//fprintf(stderr, "old is IR_CONTROL_LOOP\n");
@@ -2886,7 +2873,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
fflush(stdout);
fprintf(stderr, "\n}\n");
- std::vector<chillAST_node *> oldparentcode = par->getChildren(); // probably only works for compoundstmts
+ std::vector<chillAST_Node *> oldparentcode = par->getChildren(); // probably only works for compoundstmts
//fprintf(stderr, "ir_clang.cc oldparentcode\n");
// find loop in the parent
@@ -2940,7 +2927,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) {
//fprintf(stderr, "\nafter inserting %d statements into the Clang IR,", numnew);
CHILL_DEBUG_BEGIN
fprintf(stderr, "new parent2 is\n\n{\n");
- std::vector<chillAST_node *> newparentcode = par->getChildren();
+ std::vector<chillAST_Node *> newparentcode = par->getChildren();
for (int i = 0; i < newparentcode.size(); i++) {
fflush(stdout);
//fprintf(stderr, "%d ", i);
@@ -2973,7 +2960,7 @@ void IR_clangCode::ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) {
//exit(-1);
}
- chillAST_node *newthing = crepr->chillnodes[0];
+ chillAST_Node *newthing = crepr->chillnodes[0];
fprintf(stderr, "with new ");
newthing->print();
printf("\n\n");
@@ -3032,7 +3019,7 @@ IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *re
//fprintf(stderr, "IR_clangCode::QueryExpOperation()\n");
CG_chillRepr *crepr = (CG_chillRepr *) repr;
- chillAST_node *node = crepr->chillnodes[0];
+ chillAST_Node *node = crepr->chillnodes[0];
//fprintf(stderr, "chillAST node type %s\n", node->getTypeString());
// really need to be more rigorous than this hack // TODO
@@ -3104,7 +3091,7 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C
CG_chillRepr *crepr = (CG_chillRepr *) repr;
//Expr *e = static_cast<const omega::CG_chillRepr *>(repr)->GetExpression(); wrong.. CLANG
- chillAST_node *e = crepr->chillnodes[0]; // ??
+ chillAST_Node *e = crepr->chillnodes[0]; // ??
//e->print(); printf("\n"); fflush(stdout);
// really need to be more rigorous than this hack // TODO
@@ -3200,7 +3187,7 @@ Expr *op1, *op2;
IR_Ref *IR_clangCode::Repr2Ref(const omega::CG_outputRepr *repr) const {
CG_chillRepr *crepr = (CG_chillRepr *) repr;
- chillAST_node *node = crepr->chillnodes[0];
+ chillAST_Node *node = crepr->chillnodes[0];
//Expr *e = static_cast<const omega::CG_chillRep *>(repr)->GetExpression();
@@ -3221,13 +3208,13 @@ IR_Ref *IR_clangCode::Repr2Ref(const omega::CG_outputRepr *repr) const {
}
}
-chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *) {
+chillAST_NodeList* ConvertMemberExpr(clang::MemberExpr *clangME) {
fprintf(stderr, "ConvertMemberExpr()\n");
clang::Expr *E = clangME->getBase();
E->dump();
- chillAST_node *base = ConvertGenericClangAST(clangME->getBase(), NULL);
+ chillAST_Node *base = unwrap(ConvertGenericClangAST(clangME->getBase()));
DeclarationNameInfo memnameinfo = clangME->getMemberNameInfo();
DeclarationName DN = memnameinfo.getName();
@@ -3240,6 +3227,6 @@ chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *) {
ME->print();
fprintf(stderr, "\n");
- return ME;
+ NL_RET(ME);
}