charmxi: Split SDAG's When into a separate class from SdagConstruct
authorPhil Miller <mille121@illinois.edu>
Thu, 4 Oct 2012 21:15:26 +0000 (16:15 -0500)
committerPhil Miller <mille121@illinois.edu>
Thu, 4 Oct 2012 21:15:26 +0000 (16:15 -0500)
src/xlat-i/sdag/CEntry.C
src/xlat-i/sdag/CEntry.h
src/xlat-i/sdag/CParsedFile.C
src/xlat-i/sdag/CSdagConstruct.C
src/xlat-i/xi-grammar.tab.C
src/xlat-i/xi-grammar.y
src/xlat-i/xi-symbol.h

index 669b309b9380ad57c55480c172aa84bf3a04adc5..00586a77bb2df3f782c12ed5e6d35b4c7e224697 100644 (file)
@@ -8,7 +8,7 @@ namespace xi {
 
 void CEntry::generateDeps(XStr& op)
 {
-  for(list<SdagConstruct*>::iterator cn = whenList.begin(); cn != whenList.end(); ++cn) {
+  for(list<WhenConstruct*>::iterator cn = whenList.begin(); cn != whenList.end(); ++cn) {
     op << "    __cDep->addDepends(" << (*cn)->nodeNum << "," << entryNum << ");\n";
   }
 }
@@ -193,7 +193,7 @@ void CEntry::generateCode(XStr& decls, XStr& defs)
   }
   else {   
     defs << "    switch(tr->whenID) {\n";
-    for(list<SdagConstruct*>::iterator cn = whenList.begin(); cn != whenList.end(); ++cn)
+    for(list<WhenConstruct*>::iterator cn = whenList.begin(); cn != whenList.end(); ++cn)
     {
       defs << "      case " << (*cn)->nodeNum << ":\n";
       defs << "      {\n";
index 91d6c196a139b2f8c32587142daf19859e8bd15c..194d32eb910a139e6a5ccbf1506f7d1d5c9ad950 100644 (file)
@@ -10,6 +10,7 @@ namespace xi {
 
 class Entry;
 class SdagConstruct;
+class WhenConstruct;
 class ParamList;
 class CStateVar;
 
@@ -24,7 +25,7 @@ public:
     int entryNum;
     int needsParamMarshalling;
     int refNumNeeded;
-    std::list<SdagConstruct*> whenList;
+    std::list<WhenConstruct*> whenList;
     CEntry(XStr *e, ParamList *p, const std::list<CStateVar*>& list, int pm) : entry(e), paramlist(p), needsParamMarshalling(pm) {
        CStateVar *sv;
        myParameters = list;
index 37ac9827e39e3780b2f8462abe814d0d0ec20d88..b752cc165b714b095d6146ef4a288be68c140dff 100644 (file)
@@ -83,7 +83,7 @@ void CParsedFile::mapCEntry(void)
 void CParsedFile::generateEntryList(void)
 {
   for(std::list<Entry*>::iterator cn = nodeList.begin(); cn != nodeList.end(); ++cn) {
-    (*cn)->sdagCon->generateEntryList(entryList, (SdagConstruct*)0);
+    (*cn)->sdagCon->generateEntryList(entryList, NULL);
   }
 }
 
index 0479e53571258f82dfc27ba2863ff92613d9ff45..1f3499fdb8e9e2b49a43577198e52c94092ebbe9 100644 (file)
@@ -186,7 +186,7 @@ void SdagConstruct::labelNodes(void)
   }
 }
 
-void EntryList::generateEntryList(list<CEntry*>& CEntrylist, SdagConstruct *thisWhen)
+void EntryList::generateEntryList(list<CEntry*>& CEntrylist, WhenConstruct *thisWhen)
 {
    EntryList *el;
    el = this;
@@ -197,7 +197,7 @@ void EntryList::generateEntryList(list<CEntry*>& CEntrylist, SdagConstruct *this
    }
 }
 
-void Entry::generateEntryList(list<CEntry*>& CEntrylist, SdagConstruct *thisWhen)
+void Entry::generateEntryList(list<CEntry*>& CEntrylist, WhenConstruct *thisWhen)
 {
    // case SENTRY:
    bool found = false;
@@ -235,7 +235,7 @@ void Entry::generateEntryList(list<CEntry*>& CEntrylist, SdagConstruct *thisWhen
        if (found) {
           // check to see if thisWhen is already in entry's whenList
           bool whenFound = false;
-          for(list<SdagConstruct*>::iterator it = (*entry)->whenList.begin();
+          for(list<WhenConstruct*>::iterator it = (*entry)->whenList.begin();
               it != (*entry)->whenList.end(); ++it) {
             if ((*it)->nodeNum == thisWhen->nodeNum)
               whenFound = true;
@@ -260,25 +260,30 @@ void Entry::generateEntryList(list<CEntry*>& CEntrylist, SdagConstruct *thisWhen
       //break;
 }
 
-void SdagConstruct::generateEntryList(std::list<CEntry*>& CEntrylist, SdagConstruct *thisWhen)
+void SdagConstruct::generateEntryList(list<CEntry*>& CEntrylist, WhenConstruct *thisWhen)
 {
-  SdagConstruct *cn;
-  switch(type) {
-    case SWHEN:
-      elist->generateEntryList(CEntrylist, this);  /* con1 is the WHEN's ELIST */
-      break;
-    case SIF:
-       /* con2 is the ELSE corresponding to this IF */
-      if(con2!=0) con2->generateEntryList(CEntrylist, thisWhen); 
-      break;
-  }
+  if (SIF == type && con2 != 0)
+    con2->generateEntryList(CEntrylist, thisWhen);
+  generateChildrenEntryList(CEntrylist, thisWhen);
+}
+
+void WhenConstruct::generateEntryList(list<CEntry*>& CEntrylist, WhenConstruct *thisWhen)
+{
+  elist->generateEntryList(CEntrylist, this);  /* con1 is the WHEN's ELIST */
+  generateChildrenEntryList(CEntrylist, thisWhen);
+}
+
+void SdagConstruct::generateChildrenEntryList(list<CEntry*>& CEntrylist,
+                                              WhenConstruct *thisWhen) {
   if (constructs != 0) {
-    for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
+    for(SdagConstruct *cn = constructs->begin();
+        !constructs->end();
+        cn = constructs->next()) {
       cn->generateEntryList(CEntrylist,thisWhen);
     }
   }
 }
+
 void SdagConstruct::generateConnectEntries(XStr& decls) {
    decls << "  void " <<connectEntry << "(";
    ParamList *pl = param;
@@ -358,7 +363,6 @@ void SdagConstruct::propagateState(int uniqueVarNum)
   delete whensEntryMethodStateVars;
 }
 
-
 void SdagConstruct::propagateState(TList<CStateVar*>& list, TList<CStateVar*>& wlist, TList<SdagConstruct*>& publist, int uniqueVarNum)
 {
   CStateVar *sv;
@@ -381,43 +385,6 @@ void SdagConstruct::propagateState(TList<CStateVar*>& list, TList<CStateVar*>& w
         stateVarsChildren->append(sv);
       }
       break;
-    case SWHEN:
-      whensEntryMethodStateVars = new TList<CStateVar*>();
-      stateVarsChildren = new TList<CStateVar*>();
-      for(sv=list.begin(); !list.end(); sv=list.next()) {
-        stateVars->append(sv);
-        stateVarsChildren->append(sv);
-      }
-     
-      {  
-        EntryList *el;
-       el = elist;
-        ParamList *pl;
-       while (el != NULL) {
-          pl = el->entry->param;
-         el->entry->stateVars = new TList<CStateVar*>();
-          if (pl->isVoid()) {
-            sv = new CStateVar(1, NULL, 0, NULL, 0, NULL, 0);
-            //stateVars->append(sv);
-              stateVarsChildren->append(sv);
-              whensEntryMethodStateVars->append(sv); 
-              el->entry->addEStateVar(sv);
-          }
-          else {
-            while(pl != NULL) {
-              sv = new CStateVar(pl);
-              stateVarsChildren->append(sv);
-              whensEntryMethodStateVars->append(sv); 
-              el->entry->addEStateVar(sv);
-
-              pl = pl->next;
-           }
-         }
-         el = el->next;
-
-       }
-      }
-      break;
     case SIF:
       for(sv=list.begin(); !list.end(); sv=list.next()) {
         stateVars->append(sv);
@@ -485,16 +452,59 @@ void SdagConstruct::propagateState(TList<CStateVar*>& list, TList<CStateVar*>& w
       exit(1);
       break;
   }
+
+  propagateStateToChildren(*stateVarsChildren, wlist, publist,  uniqueVarNum);
+  delete whensEntryMethodStateVars;
+}
+
+void WhenConstruct::propagateState(TList<CStateVar*>& list, TList<CStateVar*>& wlist, TList<SdagConstruct*>& publist, int uniqueVarNum) {
+  CStateVar *sv;
+  TList<CStateVar*> whensEntryMethodStateVars;
+  stateVars = new TList<CStateVar*>();
+  stateVarsChildren = new TList<CStateVar*>();
+
+  for(sv=list.begin(); !list.end(); sv=list.next()) {
+    stateVars->append(sv);
+    stateVarsChildren->append(sv);
+  }
+
+  EntryList *el;
+  el = elist;
+  ParamList *pl;
+  while (el != NULL) {
+    pl = el->entry->param;
+    el->entry->stateVars = new TList<CStateVar*>();
+    if (pl->isVoid()) {
+      sv = new CStateVar(1, NULL, 0, NULL, 0, NULL, 0);
+      //stateVars->append(sv);
+      stateVarsChildren->append(sv);
+      whensEntryMethodStateVars.append(sv);
+      el->entry->addEStateVar(sv);
+    }
+    else {
+      while(pl != NULL) {
+        sv = new CStateVar(pl);
+        stateVarsChildren->append(sv);
+        whensEntryMethodStateVars.append(sv);
+        el->entry->addEStateVar(sv);
+
+        pl = pl->next;
+      }
+    }
+    el = el->next;
+
+  }
+
+  propagateStateToChildren(*stateVarsChildren, whensEntryMethodStateVars, publist,  uniqueVarNum);
+}
+
+void SdagConstruct::propagateStateToChildren(TList<CStateVar*>& stateVarsChildren, TList<CStateVar*>& wlist, TList<SdagConstruct*>& publist, int uniqueVarNum) {
   SdagConstruct *cn;
   if (constructs != 0) {
     for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
-      if (type == SWHEN)
-         cn->propagateState(*stateVarsChildren, *whensEntryMethodStateVars, publist,  uniqueVarNum);
-      else
-         cn->propagateState(*stateVarsChildren, wlist, publist,  uniqueVarNum);
+      cn->propagateState(stateVarsChildren, wlist, publist, uniqueVarNum);
     }
   }
-  delete whensEntryMethodStateVars;
 }
 
 void SdagConstruct::generateCode(XStr& decls, XStr& defs, Entry *entry)
@@ -532,9 +542,6 @@ void SdagConstruct::generateCode(XStr& decls, XStr& defs, Entry *entry)
     case SOVERLAP:
       generateOverlap(decls, defs, entry);
       break;
-    case SWHEN:
-      generateWhen(decls, defs, entry);
-      break;
     case SFORWARD:
       generateForward(decls, defs, entry);
       break;
@@ -544,6 +551,10 @@ void SdagConstruct::generateCode(XStr& decls, XStr& defs, Entry *entry)
     default:
       break;
   }
+  generateChildrenCode(decls, defs, entry);
+}
+
+void SdagConstruct::generateChildrenCode(XStr& decls, XStr& defs, Entry* entry) {
   SdagConstruct *cn;
   if (constructs != 0) {
     for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
@@ -669,7 +680,7 @@ void SdagConstruct::generateForward(XStr& decls, XStr& defs, Entry* entry) {
 }
 
 
-void SdagConstruct::generateWhen(XStr& decls, XStr& defs, Entry* entry)
+void WhenConstruct::generateCode(XStr& decls, XStr& defs, Entry* entry)
 {
   sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
   generateSignature(decls, defs, entry, false, "int", label, false, stateVars);
@@ -1001,6 +1012,8 @@ void SdagConstruct::generateWhen(XStr& decls, XStr& defs, Entry* entry)
   }
 
   endMethod(defs);
+
+  generateChildrenCode(decls, defs, entry);
 }
 
 void SdagConstruct::generateWhile(XStr& decls, XStr& defs, Entry* entry)
index 7dae7281a7e08f99b86b2a733a62c583b7fa3f3c..016612de0aec8763d34422799994cbf2a4a2a618 100644 (file)
@@ -4224,21 +4224,21 @@ yyreduce:
 
 /* Line 1455 of yacc.c  */
 #line 1060 "xi-grammar.y"
-    { (yyval.sc) = new SdagConstruct(SWHEN, 0, 0, 0,0,0, 0,  (yyvsp[(2) - (4)].entrylist)); }
+    { (yyval.sc) = new WhenConstruct((yyvsp[(2) - (4)].entrylist), 0); }
     break;
 
   case 274:
 
 /* Line 1455 of yacc.c  */
 #line 1062 "xi-grammar.y"
-    { (yyval.sc) = new SdagConstruct(SWHEN, 0, 0, 0,0,0, (yyvsp[(3) - (3)].sc), (yyvsp[(2) - (3)].entrylist)); }
+    { (yyval.sc) = new WhenConstruct((yyvsp[(2) - (3)].entrylist), (yyvsp[(3) - (3)].sc)); }
     break;
 
   case 275:
 
 /* Line 1455 of yacc.c  */
 #line 1064 "xi-grammar.y"
-    { (yyval.sc) = new SdagConstruct(SWHEN, 0, 0, 0,0,0, (yyvsp[(4) - (5)].sc), (yyvsp[(2) - (5)].entrylist)); }
+    { (yyval.sc) = new WhenConstruct((yyvsp[(2) - (5)].entrylist), (yyvsp[(4) - (5)].sc)); }
     break;
 
   case 276:
index 80ce9419b48f0a289db3f746044c10fc10cb3b2a..013f9fad2fac63d898e8beaaa302fc64ffeed5dc 100644 (file)
@@ -1057,11 +1057,11 @@ SingleConstruct : ATOMIC OptTraceName ParamBraceStart CCode ParamBraceEnd OptPub
                    $$ = new SdagConstruct(SCONNECT, $3, $7, $4);
                }
                | WHEN SEntryList '{' '}'
-               { $$ = new SdagConstruct(SWHEN, 0, 0, 0,0,0, 0,  $2); }
+               { $$ = new WhenConstruct($2, 0); }
                | WHEN SEntryList SingleConstruct
-               { $$ = new SdagConstruct(SWHEN, 0, 0, 0,0,0, $3, $2); }
+               { $$ = new WhenConstruct($2, $3); }
                | WHEN SEntryList '{' Slist '}'
-               { $$ = new SdagConstruct(SWHEN, 0, 0, 0,0,0, $4, $2); }
+               { $$ = new WhenConstruct($2, $4); }
                | OVERLAP '{' Olist '}'
                { $$ = new SdagConstruct(SOVERLAP,0, 0,0,0,0,$3, 0); }  
                | FOR StartIntExpr CCode ';' CCode ';' CCode  EndIntExpr '{' Slist '}'
index e48c2ca23eafa71af325015a9544d0ebc84de22d..9d9330ee000b8bb1645eda92e17027e6b43b9701 100644 (file)
@@ -1056,7 +1056,7 @@ class Entry : public Member {
     XStr genRegEp(bool isForRedn = false);
     void preprocess();
     char *getEntryName() { return name; }
-    void generateEntryList(std::list<CEntry*>&, SdagConstruct *);
+    void generateEntryList(std::list<CEntry*>&, WhenConstruct *);
     void collectSdagCode(CParsedFile *pf, int& sdagPresent);
     void propagateState(int);
     void lookforCEntry(CEntry *centry);
@@ -1069,7 +1069,7 @@ class EntryList {
     EntryList *next;
     EntryList(Entry *e,EntryList *elist=NULL):
        entry(e), next(elist) {}
-    void generateEntryList(std::list<CEntry*>&, SdagConstruct *);
+    void generateEntryList(std::list<CEntry*>&, WhenConstruct *);
 };
 
 
@@ -1258,7 +1258,6 @@ public:
 /******************* Structured Dagger Constructs ***************/
 class SdagConstruct { 
 private:
-  void generateWhen(XStr& decls, XStr& defs, Entry* entry);
   void generateOverlap(XStr& decls, XStr& defs, Entry* entry);
   void generateWhile(XStr& decls, XStr& defs, Entry* entry);
   void generateFor(XStr& decls, XStr& defs, Entry* entry);
@@ -1271,6 +1270,8 @@ private:
   void generateAtomic(XStr& decls, XStr& defs, Entry* entry);
   void generateForward(XStr& decls, XStr& defs, Entry* entry);
   void generateConnect(XStr& decls, XStr& defs, Entry* entry);
+
+protected:
   void generateCall(XStr& defs, TList<CStateVar*>& args,
                     const XStr* name, const char* nameSuffix = 0);
 
@@ -1278,10 +1279,14 @@ private:
   void generateBeginTime(XStr& defs);               //for Event Bracket
   void generateEventBracket(XStr& defs, int eventType);     //for Event Bracket
   void generateListEventBracket(XStr& defs, int eventType);
+  void generateChildrenCode(XStr& decls, XStr& defs, Entry* entry);
+  void generateChildrenEntryList(std::list<CEntry*>& CEntrylist, WhenConstruct *thisWhen);
+  void propagateStateToChildren(TList<CStateVar*>&, TList<CStateVar*>&, TList<SdagConstruct*>&, int);
   TList<SdagConstruct *> *constructs;
   TList<SdagConstruct *> *publishesList;
   TList<CStateVar *> *stateVars;
   TList<CStateVar *> *stateVarsChildren;
+
 public:
   int nodeNum;
   XStr *label;
@@ -1320,10 +1325,10 @@ public:
   void labelNodes(void);
   void generateConnectEntryList(std::list<SdagConstruct*>&);
   void generateConnectEntries(XStr&);
-  void generateEntryList(std::list<CEntry*>&, SdagConstruct *);
+  virtual void generateEntryList(std::list<CEntry*>&, WhenConstruct *);
   void propagateState(int);
-  void propagateState(TList<CStateVar*>&, TList<CStateVar*>&, TList<SdagConstruct*>&, int);
-  void generateCode(XStr& decls, XStr& defs, Entry *entry);
+  virtual void propagateState(TList<CStateVar*>&, TList<CStateVar*>&, TList<SdagConstruct*>&, int);
+  virtual void generateCode(XStr& decls, XStr& defs, Entry *entry);
   void generateWhenCode(XStr& op);
   void setNext(SdagConstruct *, int);
 
@@ -1337,7 +1342,16 @@ public:
   static void generateEndExec(XStr& defs);
   static void generateEndSeq(XStr& defs);
   static void generateDummyBeginExecute(XStr& defs);
+};
 
+class WhenConstruct : public SdagConstruct {
+public:
+  void generateCode(XStr& decls, XStr& defs, Entry *entry);
+  WhenConstruct(EntryList *el, SdagConstruct *body)
+    : SdagConstruct(SWHEN, 0, 0, 0,0,0, body, el)
+  { }
+  void generateEntryList(std::list<CEntry*>& CEntrylist, WhenConstruct *thisWhen);
+  void propagateState(TList<CStateVar*>&, TList<CStateVar*>&, TList<SdagConstruct*>&, int);
 };
 
 SdagConstruct *buildAtomic(const char* code,