summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/chillAST/chillAST_node.hh5
-rw-r--r--include/chillAST/chillASTs.hh86
-rwxr-xr-xinclude/ir_clang.hh4
-rwxr-xr-xlib/chillcg/src/CG_chillBuilder.cc8
-rw-r--r--src/ast/node.cpp10
-rw-r--r--src/chillASTs.cc285
-rwxr-xr-xsrc/ir_clang.cc6
-rw-r--r--src/printer/cfamily.cpp10
-rw-r--r--src/printer/dump.cpp10
9 files changed, 97 insertions, 327 deletions
diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh
index 255c07a..4db00ce 100644
--- a/include/chillAST/chillAST_node.hh
+++ b/include/chillAST/chillAST_node.hh
@@ -315,9 +315,8 @@ public:
fprintf(stderr, "(%s) forgot to implement gatherVarDeclsMore()\n", getTypeString());
};
- virtual void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls) { // ACTUAL Declaration
- fprintf(stderr, "(%s) forgot to implement gatherScalarVarDecls()\n", getTypeString());
- };
+ //! Actual declaration
+ virtual void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
virtual void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh
index ea8feaa..795f12b 100644
--- a/include/chillAST/chillASTs.hh
+++ b/include/chillAST/chillASTs.hh
@@ -550,16 +550,16 @@ public:
void removeSyncComment();
- chillAST_Node *getInit() { return children[0]; };
+ chillAST_Node *getInit() { return getChild(0); };
void setInit(chillAST_Node *i) { setChild(0,i); }
- chillAST_Node *getCond() { return children[1]; };
+ chillAST_Node *getCond() { return getChild(1); };
void setCond(chillAST_Node *c) { setChild(1,c); }
- chillAST_Node *getInc() { return children[2]; };
+ chillAST_Node *getInc() { return getChild(2); };
void setInc(chillAST_Node *i) { setChild(2,i); }
- chillAST_Node *getBody() { return children[3]; };
+ chillAST_Node *getBody() { return getChild(3); };
void setBody(chillAST_Node *b) { setChild(3,b); };
@@ -626,10 +626,6 @@ public:
// variables that are special for this type of node
char *op; // TODO need enum so far, only "?" conditional operator
- chillAST_Node *condition;
- chillAST_Node *lhs; // keep name from binary
- chillAST_Node *rhs;
-
// constructors
chillAST_TernaryOperator();
@@ -641,57 +637,29 @@ public:
bool isLeaf() { return false; };
-
char *getOp() { return op; }; // dangerous. could get changed!
- chillAST_Node *getCond() { return condition; };
- chillAST_Node *getRHS() { return rhs; };
+ chillAST_Node *getCond() { return getChild(0); };
- chillAST_Node *getLHS() { return lhs; };
+ chillAST_Node *getRHS() { return getChild(1); };
- void setCond(chillAST_Node *newc) {
- condition = newc;
- newc->setParent(this);
- }
+ chillAST_Node *getLHS() { return getChild(2); };
- void setLHS(chillAST_Node *newlhs) {
- lhs = newlhs;
- newlhs->setParent(this);
- }
+ void setCond(chillAST_Node *newc) { setChild(0,newc); }
- void setRHS(chillAST_Node *newrhs) {
- rhs = newrhs;
- newrhs->setParent(this);
- }
+ void setLHS(chillAST_Node *newlhs) { setChild(1,newlhs); }
+ void setRHS(chillAST_Node *newrhs) { setChild(2,newrhs); }
// required methods that I can't seem to get to inherit
chillAST_Node *constantFold();
chillAST_Node *clone();
- void replaceChild(chillAST_Node *old, chillAST_Node *newchild);
-
- void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
-
- void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
-
- void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
-
void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
-
- void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
-
- void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
-
- void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
-
void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls);
- void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
-
bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
bool forcesync = false) { return false; }; // no loops under here
void loseLoopWithLoopVar(char *var) {}; // ternop can't have loop as child?
@@ -703,11 +671,9 @@ public:
// variables that are special for this type of node
char *op; // TODO need enum
- chillAST_Node *lhs;
- chillAST_Node *rhs;
-
// constructors
+ chillAST_BinaryOperator();
chillAST_BinaryOperator(chillAST_Node *lhs, const char *op, chillAST_Node *rhs);
// other methods particular to this type of node
@@ -719,19 +685,13 @@ public:
bool isLeaf() { return false; };
- chillAST_Node *getRHS() { return rhs; };
+ chillAST_Node *getLHS() { return getChild(0); };
- chillAST_Node *getLHS() { return lhs; };
+ chillAST_Node *getRHS() { return getChild(1); };
- void setLHS(chillAST_Node *newlhs) {
- lhs = newlhs;
- newlhs->setParent(this);
- }
+ void setLHS(chillAST_Node *newlhs) { setChild(0,newlhs); }
- void setRHS(chillAST_Node *newrhs) {
- rhs = newrhs;
- newrhs->setParent(this);
- }
+ void setRHS(chillAST_Node *newrhs) { setChild(1,newrhs); }
char *getOp() { return op; }; // dangerous. could get changed!
bool isAugmentedAssignmentOp() {
@@ -776,33 +736,17 @@ public:
chillAST_Node *clone();
- void replaceChild(chillAST_Node *old, chillAST_Node *newchild);
-
void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento); // chillAST_BinaryOperator
void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
- void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls);
-
void gatherVarDeclsMore(std::vector<chillAST_VarDecl *> &decls) { gatherVarDecls(decls); };
- void gatherScalarVarDecls(std::vector<chillAST_VarDecl *> &decls);
-
- void gatherArrayVarDecls(std::vector<chillAST_VarDecl *> &decls);
-
- void gatherVarUsage(std::vector<chillAST_VarDecl *> &decls);
-
- void gatherDeclRefExprs(std::vector<chillAST_DeclRefExpr *> &refs);
-
void gatherVarLHSUsage(std::vector<chillAST_VarDecl *> &decls);
- void replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
-
bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab,
bool forcesync = false) { return false; }; // no loops under here
void loseLoopWithLoopVar(char *var) {}; // binop can't have loop as child?
- void gatherStatements(std::vector<chillAST_Node *> &statements); //
-
};
class chillAST_ArraySubscriptExpr : public chillAST_Node {
diff --git a/include/ir_clang.hh b/include/ir_clang.hh
index 81a6fde..9b9e4be 100755
--- a/include/ir_clang.hh
+++ b/include/ir_clang.hh
@@ -149,7 +149,7 @@ struct IR_chillScalarRef : public IR_ScalarRef {
dre = NULL;
//bop = ins; // do we need this?
if (pos == OP_LEFT) {
- chillAST_Node *lhs = ins->lhs;
+ chillAST_Node *lhs = ins->getLHS();
if (lhs->isDeclRefExpr()) {
chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) lhs;
dre = DRE;
@@ -161,7 +161,7 @@ struct IR_chillScalarRef : public IR_ScalarRef {
exit(-1);
}
} else {
- chillAST_Node *rhs = ins->rhs;
+ chillAST_Node *rhs = ins->getRHS();
if (rhs->isDeclRefExpr()) {
chillAST_DeclRefExpr *DRE = (chillAST_DeclRefExpr *) rhs;
dre = DRE;
diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc
index 7f13334..27d0af2 100755
--- a/lib/chillcg/src/CG_chillBuilder.cc
+++ b/lib/chillcg/src/CG_chillBuilder.cc
@@ -103,8 +103,8 @@ namespace omega {
// b->print(); printf("\n"); fflush(stdout);
//}
- chillAST_Node *lhs = b->lhs;
- chillAST_Node *rhs = b->rhs;
+ chillAST_Node *lhs = b->getLHS();
+ chillAST_Node *rhs = b->getRHS();
//if (!strcmp(b->op, "=") && rhs->isBinaryOperator() ) {
// chillAST_BinaryOperator *r = (chillAST_BinaryOperator *) rhs;
@@ -116,8 +116,8 @@ namespace omega {
//rhs->dump(); printf("\n"); fflush(stdout);
- b->lhs = substituteChill( oldvar, newvar, lhs, b);
- b->rhs = substituteChill( oldvar, newvar, rhs, b);
+ b->setLHS(substituteChill( oldvar, newvar, lhs, b));
+ b->setRHS(substituteChill( oldvar, newvar, rhs, b));
return b;
}
diff --git a/src/ast/node.cpp b/src/ast/node.cpp
index d0a80e9..deee5ba 100644
--- a/src/ast/node.cpp
+++ b/src/ast/node.cpp
@@ -264,7 +264,7 @@ chillAST_Node* chillAST_Node::constantFold(){
CHILL_DEBUG_PRINT("Using generic\n");
for (int i = 0;i<getNumChildren();++i) {
if (getChild(i))
- getChild(i)->constantFold();
+ setChild(i,getChild(i)->constantFold());
}
return this;
};
@@ -326,7 +326,13 @@ void chillAST_Node::replaceVarDecls(chillAST_VarDecl* olddecl, chillAST_VarDecl
}
}
-
+void chillAST_Node::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
+ CHILL_DEBUG_PRINT("using generic\n");
+ for (int i = 0;i<getNumChildren();++i) {
+ if (getChild(i))
+ getChild(i)->gatherScalarVarDecls(decls);
+ }
+}
diff --git a/src/chillASTs.cc b/src/chillASTs.cc
index 7ac8426..2f57197 100644
--- a/src/chillASTs.cc
+++ b/src/chillASTs.cc
@@ -689,14 +689,14 @@ bool chillAST_ForStmt::lowerBound(int &l) { // l is an output (passed as referen
}
//fprintf(stderr, "rhs "); bo->rhs->print(0,stderr); fprintf(stderr, " ");
- l = bo->rhs->evalAsInt(); // float could be legal I suppose
+ l = bo->getRHS()->evalAsInt(); // float could be legal I suppose
//fprintf(stderr, " %d\n", l);
return true;
} else if (conditionoperator == IR_COND_GT ||
conditionoperator == IR_COND_GE) { // decrementing
// lower bound is rhs of cond (not init)
chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *) getCond();
- l = bo->rhs->evalAsInt(); // float could be legal I suppose
+ l = bo->getLHS()->evalAsInt(); // float could be legal I suppose
return true;
}
@@ -726,7 +726,7 @@ bool chillAST_ForStmt::upperBound(int &u) { // u is an output (passed as referen
exit(-1);
}
- u = bo->rhs->evalAsInt(); // float could be legal I suppose
+ u = bo->getRHS()->evalAsInt(); // float could be legal I suppose
return true;
} else if (conditionoperator == IR_COND_LT ||
conditionoperator == IR_COND_LE) {
@@ -734,7 +734,7 @@ bool chillAST_ForStmt::upperBound(int &u) { // u is an output (passed as referen
// upper bound is rhs of cond (not init)
chillAST_BinaryOperator *bo = (chillAST_BinaryOperator *) getCond();
//bo->rhs->print(0,stderr);
- u = bo->rhs->evalAsInt(); // float could be legal I suppose
+ u = bo->getRHS()->evalAsInt(); // float could be legal I suppose
if (conditionoperator == IR_COND_LT) u -= 1;
@@ -1063,16 +1063,16 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) {
// ACTUALLY, if I am being replaced, and my loop conditional is a min (Ternary), then wrap my loop body in an if statement
if (getCond()->isBinaryOperator()) { // what else could it be?
chillAST_BinaryOperator *BO = (chillAST_BinaryOperator *) getCond();
- if (BO->rhs->isTernaryOperator()) {
+ if (BO->getRHS()->isTernaryOperator()) {
- chillAST_TernaryOperator *TO = (chillAST_TernaryOperator *) BO->rhs;
- chillAST_BinaryOperator *C = (chillAST_BinaryOperator *) TO->condition;
+ chillAST_TernaryOperator *TO = (chillAST_TernaryOperator *) BO->getRHS();
+ chillAST_BinaryOperator *C = (chillAST_BinaryOperator *) TO->getCond();
//fprintf(stderr, "loop condition RHS is ternary\nCondition RHS");
C->print();
- chillAST_Node *l = C->lhs;
+ chillAST_Node *l = C->getLHS();
if (l->isParenExpr()) l = ((chillAST_ParenExpr *) l)->subexpr;
- chillAST_Node *r = C->rhs;
+ chillAST_Node *r = C->getRHS();
if (r->isParenExpr()) r = ((chillAST_ParenExpr *) r)->subexpr;
//fprintf(stderr, "lhs is %s rhs is %s\n", l->getTypeString(), r->getTypeString());
@@ -1107,8 +1107,13 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) {
}
+chillAST_BinaryOperator::chillAST_BinaryOperator() {
+ children.push_back(NULL);
+ children.push_back(NULL);
+}
-chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_Node *l, const char *oper, chillAST_Node *r) {
+chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_Node *l, const char *oper, chillAST_Node *r)
+ :chillAST_BinaryOperator() {
//fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator( l %p %s r %p, parent %p) this %p\n", l, oper, r, par, this);
CHILL_DEBUG_PRINT("( l %s r )\n", oper);
@@ -1116,25 +1121,23 @@ chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_Node *l, const char *o
// fprintf(stderr, "("); l->print(0,stderr); fprintf(stderr, ") %s (", oper); r->print(0,stderr); fprintf(stderr, ")\n\n");
//}
- lhs = l;
- rhs = r;
+ setLHS(l);
+ setRHS(r);
- if (lhs) lhs->setParent(this);
- if (rhs) rhs->setParent(this); // may only have part of the lhs and rhs when binop is created
if (oper) op = strdup(oper);
// if this writes to lhs and lhs type has an 'imwrittento' concept, set that up
if (isAssignmentOp()) {
- if (lhs && lhs->isArraySubscriptExpr()) {
- ((chillAST_ArraySubscriptExpr *) lhs)->imwrittento = true;
+ if (l && l->isArraySubscriptExpr()) {
+ ((chillAST_ArraySubscriptExpr *) l)->imwrittento = true;
//fprintf(stderr, "chillAST_BinaryOperator, op '=', lhs is an array reference LVALUE\n");
}
}
if (isAugmentedAssignmentOp()) { // += etc
//fprintf(stderr, "isAugmentedAssignmentOp() "); print(); fflush(stdout);
- if (lhs && lhs->isArraySubscriptExpr()) {
+ if (l && l->isArraySubscriptExpr()) {
//fprintf(stderr, "lhs is also read from "); lhs->print(); fflush(stdout);
- ((chillAST_ArraySubscriptExpr *) lhs)->imreadfrom = true; // note will ALSO have imwrittento true
+ ((chillAST_ArraySubscriptExpr *) l)->imreadfrom = true; // note will ALSO have imwrittento true
}
}
@@ -1145,15 +1148,15 @@ chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_Node *l, const char *o
int chillAST_BinaryOperator::evalAsInt() {
// very limited. allow +-*/ and integer literals ...
- if (isAssignmentOp()) return rhs->evalAsInt(); // ?? ignores/loses lhs info
+ if (isAssignmentOp()) return getRHS()->evalAsInt(); // ?? ignores/loses lhs info
if (!strcmp("+", op)) {
//fprintf(stderr, "chillAST_BinaryOperator::evalAsInt() %d + %d\n", lhs->evalAsInt(), rhs->evalAsInt());
- return lhs->evalAsInt() + rhs->evalAsInt();
+ return getLHS()->evalAsInt() + getRHS()->evalAsInt();
}
- if (!strcmp("-", op)) return lhs->evalAsInt() - rhs->evalAsInt();
- if (!strcmp("*", op)) return lhs->evalAsInt() * rhs->evalAsInt();
- if (!strcmp("/", op)) return lhs->evalAsInt() / rhs->evalAsInt();
+ if (!strcmp("-", op)) return getLHS()->evalAsInt() - getRHS()->evalAsInt();
+ if (!strcmp("*", op)) return getLHS()->evalAsInt() * getRHS()->evalAsInt();
+ if (!strcmp("/", op)) return getLHS()->evalAsInt() / getRHS()->evalAsInt();
fprintf(stderr, "chillAST_BinaryOperator::evalAsInt() unhandled op '%s'\n", op);
exit(-1);
@@ -1164,21 +1167,17 @@ chillAST_IntegerLiteral *chillAST_BinaryOperator::evalAsIntegerLiteral() {
}
class chillAST_Node *chillAST_BinaryOperator::constantFold() {
- //fprintf(stderr, "\nchillAST_BinaryOperator::constantFold() ");
- //print(0,stderr); fprintf(stderr, "\n");
-
- lhs = lhs->constantFold();
- rhs = rhs->constantFold();
+ chillAST_Node::constantFold();
chillAST_Node *returnval = this;
- if (lhs->isConstant() && rhs->isConstant()) {
+ if (getLHS()->isConstant() && getRHS()->isConstant()) {
//fprintf(stderr, "binop folding constants\n"); print(0,stderr); fprintf(stderr, "\n");
if (!strcmp(op, "+") || !strcmp(op, "-") || !strcmp(op, "*")) {
- if (lhs->isIntegerLiteral() && rhs->isIntegerLiteral()) {
- chillAST_IntegerLiteral *l = (chillAST_IntegerLiteral *) lhs;
- chillAST_IntegerLiteral *r = (chillAST_IntegerLiteral *) rhs;
+ if (getLHS()->isIntegerLiteral() && getRHS()->isIntegerLiteral()) {
+ chillAST_IntegerLiteral *l = (chillAST_IntegerLiteral *) getLHS();
+ chillAST_IntegerLiteral *r = (chillAST_IntegerLiteral *) getRHS();
chillAST_IntegerLiteral *I;
if (!strcmp(op, "+")) I = new chillAST_IntegerLiteral(l->value + r->value);
@@ -1228,8 +1227,8 @@ class chillAST_Node *chillAST_BinaryOperator::constantFold() {
class chillAST_Node *chillAST_BinaryOperator::clone() {
//fprintf(stderr, "chillAST_BinaryOperator::clone() "); print(); printf("\n"); fflush(stdout);
- chillAST_Node *l = lhs->clone();
- chillAST_Node *r = rhs->clone();
+ chillAST_Node *l = getLHS()->clone();
+ chillAST_Node *r = getRHS()->clone();
chillAST_BinaryOperator *bo = new chillAST_BinaryOperator(l, op, r);
l->setParent(bo);
r->setParent(bo);
@@ -1239,207 +1238,44 @@ class chillAST_Node *chillAST_BinaryOperator::clone() {
}
void chillAST_BinaryOperator::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
- //fprintf(stderr, "chillAST_BinaryOperator::gatherArrayRefs()\n");
- //print(); fflush(stdout); fprintf(stderr, "\n");
- //if (isAugmentedAssignmentOp()) {
- // fprintf(stderr, "%s is augmented assignment\n", op);
- //}
-
- //if (isAssignmentOp()) {
- // fprintf(stderr, "%s is assignment\n", op);
- //}
-
- //if (isAugmentedAssignmentOp()) { // lhs is ALSO on the RHS, NOT as a write
- // if (lhs->isArraySubscriptExpr()) { // probably some case where this fails
- // ((chillAST_ArraySubscriptExpr *) lhs)->imreadfrom = true;
- // //lhs->&gatherArrayRefs( refs, 0 );
- // }
- //}
-
- //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &arrayrefs before\n", refs.size());
- lhs->gatherArrayRefs(refs, isAssignmentOp());
- //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &arrayrefs after lhs\n", refs.size());
- rhs->gatherArrayRefs(refs, 0);
- //fprintf(stderr, "in chillAST_BinaryOperator::gatherArrayRefs(), %d &refs\n", refs.size());
-
- //for (int i=0; i<refs.size(); i++) {
- // fprintf(stderr, "%s\n", (*refs)[i]->basedecl->varname);
- //}
-
+ getLHS()->gatherArrayRefs(refs, isAssignmentOp());
+ getRHS()->gatherArrayRefs(refs, 0);
}
void chillAST_BinaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
- lhs->gatherScalarRefs(refs, isAssignmentOp());
- rhs->gatherScalarRefs(refs, 0);
-}
-
-
-void chillAST_BinaryOperator::replaceChild(chillAST_Node *old, chillAST_Node *newchild) {
- //fprintf(stderr, "\nbinop::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs);
-
- // will pointers match??
- if (lhs == old) setLHS(newchild);
- else if (rhs == old) setRHS(newchild);
-
- // silently ignore?
- //else {
- // fprintf(stderr, "\nERROR chillAST_BinaryOperator::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs);
- // fprintf(stderr, "old is not a child of this BinaryOperator\n");
- // print();
- // dump();
- // exit(-1);
- //}
-}
-
-
-void chillAST_BinaryOperator::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
- //fprintf(stderr, "chillAST_BinaryOperator::gatherVarDecls()\n");
-
- //fprintf(stderr, "chillAST_BinaryOperator::gatherVarDecls() before %d\n", decls.size());
- //print(0,stderr); fprintf(stderr, "\n");
- //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
- if (lhs) lhs->gatherVarDecls(decls); // 'if' to deal with partially formed
- if (rhs) rhs->gatherVarDecls(decls);
- //fprintf(stderr, "after %d\n", decls.size());
-}
-
-
-void chillAST_BinaryOperator::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
- //fprintf(stderr, "chillAST_BinaryOperator::gatherScalarVarDecls() before %d\n", decls.size());
- //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
- lhs->gatherScalarVarDecls(decls);
- rhs->gatherScalarVarDecls(decls);
- //fprintf(stderr, "after %d\n", decls.size());
-}
-
-
-void chillAST_BinaryOperator::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
- //fprintf(stderr, "chillAST_BinaryOperator::gatherArrayVarDecls() before %d\n", decls.size());
- //fprintf(stderr, "lhs is %s\n", lhs->getTypeString());
- lhs->gatherArrayVarDecls(decls);
- rhs->gatherArrayVarDecls(decls);
- //fprintf(stderr, "after %d\n", decls.size());
-}
-
-
-void chillAST_BinaryOperator::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
- lhs->gatherDeclRefExprs(refs);
- rhs->gatherDeclRefExprs(refs);
-}
-
-
-void chillAST_BinaryOperator::gatherStatements(std::vector<chillAST_Node *> &statements) {
-
- // what's legit?
- if (isAssignmentOp()) {
- statements.push_back(this);
- }
-
-}
-
-
-void chillAST_BinaryOperator::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
- lhs->gatherVarUsage(decls);
- rhs->gatherVarUsage(decls);
+ getLHS()->gatherScalarRefs(refs, isAssignmentOp());
+ getRHS()->gatherScalarRefs(refs, 0);
}
void chillAST_BinaryOperator::gatherVarLHSUsage(vector<chillAST_VarDecl *> &decls) {
- lhs->gatherVarUsage(decls);
+ getLHS()->gatherVarUsage(decls);
}
-void chillAST_BinaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
- //if (!strcmp(op, "<=")) {
- // fprintf(stderr, "chillAST_BinaryOperator::replaceVarDecls( old %s, new %s)\n", olddecl->varname, newdecl->varname );
- // print(); printf("\n"); fflush(stdout);
- // fprintf(stderr, "binaryoperator, lhs is of type %s\n", lhs->getTypeString());
- // fprintf(stderr, "binaryoperator, rhs is of type %s\n", rhs->getTypeString());
- //}
- lhs->replaceVarDecls(olddecl, newdecl);
- rhs->replaceVarDecls(olddecl, newdecl);
- //if (!strcmp(op, "<=")) {
- // print(); printf("\n\n"); fflush(stdout);
- //}
+chillAST_TernaryOperator::chillAST_TernaryOperator() {
+ op = strdup("?");
+ children.push_back(NULL);
+ children.push_back(NULL);
+ children.push_back(NULL);
}
chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_Node *c, chillAST_Node *l,
- chillAST_Node *r) {
- if (op)
- op = strdup(oper);
- else
- op = strdup("?"); // the only one so far
- condition = c;
- lhs = l;
- rhs = r;
- if (condition) condition->setParent(this);
- if (lhs) lhs->setParent(this);
- if (rhs) rhs->setParent(this);
-}
-
-void chillAST_TernaryOperator::replaceChild(chillAST_Node *old, chillAST_Node *newchild) {
- //fprintf(stderr, "\nbinop::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs);
-
- // will pointers match??
- if (lhs == old) setLHS(newchild);
- else if (rhs == old) setRHS(newchild);
- else if (condition == old) setCond(newchild);
-
- // silently ignore?
- //else {
- //}
-}
-
-
-void chillAST_TernaryOperator::gatherVarDecls(vector<chillAST_VarDecl *> &decls) {
- condition->gatherVarDecls(decls);
- lhs->gatherVarDecls(decls);
- rhs->gatherVarDecls(decls);
-}
-
-void chillAST_TernaryOperator::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) {
- condition->gatherScalarVarDecls(decls);
- lhs->gatherScalarVarDecls(decls);
- rhs->gatherScalarVarDecls(decls);
-}
-
-
-void chillAST_TernaryOperator::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) {
- condition->gatherArrayVarDecls(decls);
- lhs->gatherArrayVarDecls(decls);
- rhs->gatherArrayVarDecls(decls);
-}
-
-
-void chillAST_TernaryOperator::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) {
- condition->gatherDeclRefExprs(refs);
- lhs->gatherDeclRefExprs(refs);
- rhs->gatherDeclRefExprs(refs);
-}
-
-
-void chillAST_TernaryOperator::gatherVarUsage(vector<chillAST_VarDecl *> &decls) {
- condition->gatherVarUsage(decls);
- lhs->gatherVarUsage(decls);
- rhs->gatherVarUsage(decls);
+ chillAST_Node *r):chillAST_TernaryOperator() {
+ if (op) op = strdup(oper);
+ setCond(c);
+ setLHS(l);
+ setRHS(r);
}
void chillAST_TernaryOperator::gatherVarLHSUsage(vector<chillAST_VarDecl *> &decls) {
// this makes no sense for ternary ??
}
-void chillAST_TernaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
- condition->replaceVarDecls(olddecl, newdecl);
- lhs->replaceVarDecls(olddecl, newdecl);
- rhs->replaceVarDecls(olddecl, newdecl);
-}
-
class chillAST_Node *chillAST_TernaryOperator::constantFold() {
- condition = condition->constantFold();
- lhs = lhs->constantFold();
- rhs = rhs->constantFold();
+ chillAST_Node::constantFold();
chillAST_Node *returnval = this;
- if (condition->isConstant()) {
+ if (getCond()->isConstant()) {
// TODO
}
@@ -1447,30 +1283,15 @@ class chillAST_Node *chillAST_TernaryOperator::constantFold() {
}
class chillAST_Node *chillAST_TernaryOperator::clone() {
- chillAST_Node *c = condition->clone();
- chillAST_Node *l = lhs->clone();
- chillAST_Node *r = rhs->clone();
+ chillAST_Node *c = getCond()->clone();
+ chillAST_Node *l = getLHS()->clone();
+ chillAST_Node *r = getRHS()->clone();
chillAST_TernaryOperator *to = new chillAST_TernaryOperator(op, l, r, parent);
- c->setParent(to);
- l->setParent(to);
- r->setParent(to);
to->isFromSourceFile = isFromSourceFile;
filename = NULL;
return to;
}
-void chillAST_TernaryOperator::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) {
- condition->gatherArrayRefs(refs, isAssignmentOp());
- lhs->gatherArrayRefs(refs, isAssignmentOp());
- rhs->gatherArrayRefs(refs, 0);
-}
-
-void chillAST_TernaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {
- condition->gatherScalarRefs(refs, isAssignmentOp());
- lhs->gatherScalarRefs(refs, isAssignmentOp());
- rhs->gatherScalarRefs(refs, 0);
-}
-
chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, bool writtento,
void *unique) {
base = index = NULL;
diff --git a/src/ir_clang.cc b/src/ir_clang.cc
index 81bdcf7..b5634af 100755
--- a/src/ir_clang.cc
+++ b/src/ir_clang.cc
@@ -3071,10 +3071,10 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C
chillAST_BinaryOperator *bop = (chillAST_BinaryOperator *) e;
char *op = bop->op; // TODO enum for operator types
if (!strcmp(op, "=")) {
- v.push_back(new omega::CG_chillRepr(bop->rhs)); // for assign, return RHS
+ v.push_back(new omega::CG_chillRepr(bop->getRHS())); // for assign, return RHS
} else if (!strcmp(op, "+") || !strcmp(op, "-") || !strcmp(op, "*") || !strcmp(op, "/")) {
- v.push_back(new omega::CG_chillRepr(bop->lhs)); // for +*-/ return both lhs and rhs
- v.push_back(new omega::CG_chillRepr(bop->rhs));
+ v.push_back(new omega::CG_chillRepr(bop->getLHS())); // for +*-/ return both lhs and rhs
+ v.push_back(new omega::CG_chillRepr(bop->getRHS()));
} else {
CHILL_ERROR("Binary Operator UNHANDLED op (%s)\n", op);
exit(-1);
diff --git a/src/printer/cfamily.cpp b/src/printer/cfamily.cpp
index 299c81c..8aa6e62 100644
--- a/src/printer/cfamily.cpp
+++ b/src/printer/cfamily.cpp
@@ -56,10 +56,10 @@ int CFamily::getPrecS(chillAST_BinaryOperator *n) {
void CFamily::printS(std::string ident, chillAST_BinaryOperator *n, std::ostream &o) {
int prec = getPrec(n);
- if (n->lhs) printPrec(ident, n->lhs, o, prec);
+ if (n->getLHS()) printPrec(ident, n->getLHS(), o, prec);
else o << "(NULL)";
o << " " << n->op << " ";
- if (n->rhs) printPrec(ident, n->rhs, o, prec);
+ if (n->getRHS()) printPrec(ident, n->getRHS(), o, prec);
else o << "(NULL)";
}
@@ -347,11 +347,11 @@ int CFamily::getPrecS(chillAST_TernaryOperator *n) {
void CFamily::printS(std::string ident, chillAST_TernaryOperator *n, std::ostream &o) {
int prec = getPrec(n);
- printPrec(ident, n->condition, o, prec);
+ printPrec(ident, n->getCond(), o, prec);
o << "" << n->op << "";
- printPrec(ident, n->lhs, o, prec);
+ printPrec(ident, n->getLHS(), o, prec);
o << ":";
- printPrec(ident, n->rhs, o, prec);
+ printPrec(ident, n->getRHS(), o, prec);
}
const char *unaryPrec[] = {
diff --git a/src/printer/dump.cpp b/src/printer/dump.cpp
index c7abc63..066a2fe 100644
--- a/src/printer/dump.cpp
+++ b/src/printer/dump.cpp
@@ -63,9 +63,9 @@ void Dump::printS(std::string ident, chillAST_ArraySubscriptExpr *n, std::ostrea
void Dump::printS(std::string ident, chillAST_BinaryOperator *n, std::ostream &o) {
o << n->op << " ";
- if (n->lhs) print(ident, n->lhs, o);
+ if (n->getLHS()) print(ident, n->getLHS(), o);
else o << "(NULL) ";
- if (n->rhs) print(ident, n->rhs, o);
+ if (n->getRHS()) print(ident, n->getRHS(), o);
else o << "(NULL) ";
}
@@ -209,9 +209,9 @@ void Dump::printS(std::string ident, chillAST_TypedefDecl *n, std::ostream &o) {
void Dump::printS(std::string ident, chillAST_TernaryOperator *n, std::ostream &o) {
o << n->op << " ";
- print(ident, n->condition, o);
- print(ident, n->lhs, o);
- print(ident, n->rhs, o);
+ print(ident, n->getCond(), o);
+ print(ident, n->getLHS(), o);
+ print(ident, n->getRHS(), o);
}
void Dump::printS(std::string ident, chillAST_UnaryOperator *n, std::ostream &o) {