00001 #include <string.h>
00002 #include <stdlib.h>
00003 #include "sdag-globals.h"
00004 #include "xi-symbol.h"
00005
00006 #include "EToken.h"
00007 #include "CStateVar.h"
00008
00009 namespace xi {
00010
00011 SdagConstruct *buildAtomic(const char* code,
00012 SdagConstruct *pub_list,
00013 const char *trace_name)
00014 {
00015 char *tmp = strdup(code);
00016 RemoveSdagComments(tmp);
00017 SdagConstruct *ret = new SdagConstruct(SATOMIC, new XStr(tmp), pub_list, 0,0,0,0, 0 );
00018 free(tmp);
00019
00020 if (trace_name)
00021 {
00022 tmp = strdup(trace_name);
00023 tmp[strlen(tmp)-1]=0;
00024 ret->traceName = new XStr(tmp+1);
00025 free(tmp);
00026 }
00027
00028 return ret;
00029 }
00030
00031 void SdagConstruct::numberNodes(void)
00032 {
00033 switch(type) {
00034 case SSDAGENTRY: nodeNum = numSdagEntries++; break;
00035 case SOVERLAP: nodeNum = numOverlaps++; break;
00036 case SWHEN: nodeNum = numWhens++; break;
00037 case SFOR: nodeNum = numFors++; break;
00038 case SWHILE: nodeNum = numWhiles++; break;
00039 case SIF: nodeNum = numIfs++; if(con2!=0) con2->numberNodes(); break;
00040 case SELSE: nodeNum = numElses++; break;
00041 case SFORALL: nodeNum = numForalls++; break;
00042 case SSLIST: nodeNum = numSlists++; break;
00043 case SOLIST: nodeNum = numOlists++; break;
00044 case SATOMIC: nodeNum = numAtomics++; break;
00045 case SFORWARD: nodeNum = numForwards++; break;
00046 case SCONNECT: nodeNum = numConnects++; break;
00047 case SINT_EXPR:
00048 case SIDENT:
00049 default:
00050 break;
00051 }
00052 SdagConstruct *cn;
00053 if (constructs != 0) {
00054 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
00055 cn->numberNodes();
00056 }
00057 }
00058 }
00059
00060 void SdagConstruct::labelNodes(void)
00061 {
00062 char text[128];
00063 switch(type) {
00064 case SSDAGENTRY:
00065 sprintf(text, "%s", con1->text->charstar());
00066 label = new XStr(text);
00067 break;
00068 case SOVERLAP:
00069 sprintf(text, "_overlap_%d", nodeNum);
00070 label = new XStr(text);
00071 break;
00072 case SWHEN:
00073 sprintf(text, "_when_%d", nodeNum);
00074 label = new XStr(text);
00075 EntryList *el;
00076 el = elist;
00077 while (el !=NULL) {
00078 el->entry->label = new XStr(el->entry->name);
00079 el=el->next;
00080 }
00081 break;
00082 case SFOR:
00083 sprintf(text, "_for_%d", nodeNum);
00084 label = new XStr(text);
00085 break;
00086 case SWHILE:
00087 sprintf(text, "_while_%d", nodeNum);
00088 label = new XStr(text);
00089 break;
00090 case SIF:
00091 sprintf(text, "_if_%d", nodeNum);
00092 label = new XStr(text);
00093 if(con2!=0) con2->labelNodes();
00094 break;
00095 case SELSE:
00096 sprintf(text, "_else_%d", nodeNum);
00097 label = new XStr(text);
00098 break;
00099 case SFORALL:
00100 sprintf(text, "_forall_%d", nodeNum);
00101 label = new XStr(text);
00102 break;
00103 case SSLIST:
00104 sprintf(text, "_slist_%d", nodeNum);
00105 label = new XStr(text);
00106 break;
00107 case SOLIST:
00108 sprintf(text, "_olist_%d", nodeNum);
00109 label = new XStr(text);
00110 break;
00111 case SATOMIC:
00112 sprintf(text, "_atomic_%d", nodeNum);
00113 label = new XStr(text);
00114 break;
00115 case SFORWARD:
00116 sprintf(text, "_forward_%d", nodeNum);
00117 label = new XStr(text);
00118 break;
00119 case SCONNECT:
00120 sprintf(text, "_connect_%s",connectEntry->charstar());
00121 label = new XStr(text);
00122 break;
00123 case SINT_EXPR:
00124 case SIDENT:
00125 default:
00126 break;
00127 }
00128 SdagConstruct *cn;
00129 if (constructs != 0) {
00130 for(cn=(SdagConstruct *)(constructs->begin()); !constructs->end(); cn=(SdagConstruct *)(constructs->next())) {
00131 cn->labelNodes();
00132 }
00133 }
00134 }
00135
00136 void EntryList::generateEntryList(TList<CEntry*>& CEntrylist, SdagConstruct *thisWhen)
00137 {
00138 EntryList *el;
00139 el = this;
00140 while (el != NULL)
00141 {
00142 el->entry->generateEntryList(CEntrylist, thisWhen);
00143 el = el->next;
00144 }
00145 }
00146
00147 void Entry::generateEntryList(TList<CEntry*>& CEntrylist, SdagConstruct *thisWhen)
00148 {
00149
00150 CEntry *entry;
00151 bool found = false;
00152
00153 for(entry=CEntrylist.begin(); !CEntrylist.end(); entry=CEntrylist.next()) {
00154 if(*(entry->entry) == (const char *)name)
00155 {
00156 ParamList *epl;
00157 epl = entry->paramlist;
00158 ParamList *pl;
00159 pl = param;
00160 found = false;
00161 if ((entry->paramlist->isVoid() == 1) && (pl->isVoid() == 1)) {
00162 found = true;
00163 }
00164 while ((pl != NULL) && (epl != NULL))
00165 {
00166 bool kindMatches =
00167 (pl->isArray() && epl->isArray()) ||
00168 (pl->isBuiltin() && epl->isBuiltin()) ||
00169 (pl->isReference() && epl->isReference()) ||
00170 (pl->isMessage() && epl->isMessage()) ||
00171 (pl->isNamed() && epl->isNamed());
00172 bool baseNameMatches = (strcmp(pl->getBaseName(), epl->getBaseName()) == 0);
00173 if (kindMatches && baseNameMatches)
00174 found = true;
00175
00176 pl = pl->next;
00177 epl = epl->next;
00178 }
00179 if (((pl == NULL) && (epl != NULL)) ||
00180 ((pl != NULL) && (epl == NULL)))
00181 found = false;
00182 if (found) {
00183
00184 int whenFound = 0;
00185 TList<SdagConstruct*> *tmpList = &(entry->whenList);
00186 SdagConstruct *tmpNode;
00187 for(tmpNode = tmpList->begin(); !tmpList->end(); tmpNode = tmpList->next()) {
00188 if(tmpNode->nodeNum == thisWhen->nodeNum)
00189 whenFound = 1;
00190 }
00191 if(!whenFound)
00192 entry->whenList.append(thisWhen);
00193 entryPtr = entry;
00194 if(intExpr != 0)
00195 entry->refNumNeeded = 1;
00196 }
00197 }
00198 }
00199 if(!found) {
00200 CEntry *newEntry;
00201 newEntry = new CEntry(new XStr(name), param, estateVars, paramIsMarshalled() );
00202 CEntrylist.append(newEntry);
00203 entryPtr = newEntry;
00204 newEntry->whenList.append(thisWhen);
00205 if(intExpr != 0)
00206 newEntry->refNumNeeded = 1;
00207 }
00208
00209 }
00210
00211 void SdagConstruct::generateEntryList(TList<CEntry*>& CEntrylist, SdagConstruct *thisWhen)
00212 {
00213 SdagConstruct *cn;
00214 switch(type) {
00215 case SWHEN:
00216 elist->generateEntryList(CEntrylist, this);
00217 break;
00218 case SIF:
00219
00220 if(con2!=0) con2->generateEntryList(CEntrylist, thisWhen);
00221 break;
00222 }
00223 if (constructs != 0) {
00224 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
00225 cn->generateEntryList(CEntrylist,thisWhen);
00226 }
00227 }
00228 }
00229
00230 void SdagConstruct::generateConnectEntries(XStr& decls) {
00231 decls << " void " <<connectEntry->charstar() << "(";
00232 ParamList *pl = param;
00233 XStr msgParams;
00234 if (pl->isVoid() == 1) {
00235 decls << "void";
00236 }
00237 else if (pl->isMessage() == 1){
00238 decls << pl->getBaseName() <<" *" <<pl->getGivenName();
00239 }
00240 else {
00241 decls << "CkMarshallMsg *" <<"_msg";
00242 }
00243 decls << ") {\n";
00244
00245 if (!pl->isVoid() && !pl->isMessage()) {
00246 msgParams <<" char *impl_buf= _msg->msgBuf;\n";
00247 param->beginUnmarshall(msgParams);
00248 }
00249
00250 decls << msgParams.charstar() <<"\n";
00251 decls << " " <<text->charstar() <<"\n";
00252
00253 decls << " }\n";
00254 }
00255
00256 void SdagConstruct::generateConnectEntryList(TList<SdagConstruct*>& ConnectEList) {
00257 if (type == SCONNECT)
00258 ConnectEList.append(this);
00259 if (constructs != 0) {
00260 SdagConstruct *cn;
00261 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
00262 cn->generateConnectEntryList(ConnectEList);
00263 }
00264 }
00265
00266 }
00267
00268 void SdagConstruct::propagateState(int uniqueVarNum)
00269 {
00270 CStateVar *sv;
00271
00272
00273
00274
00275 stateVars = new TList<CStateVar*>();
00276 ParamList *pl = param;
00277 if (pl->isVoid() == 1) {
00278 sv = new CStateVar(1, NULL, 0, NULL, 0, NULL, 0);
00279 stateVars->append(sv);
00280 }
00281 else {
00282 while (pl != NULL) {
00283 stateVars->append(new CStateVar(pl));
00284 pl = pl->next;
00285 }
00286 }
00287
00288 #if CMK_BIGSIM_CHARM
00289
00290 stateVarsChildren = new TList<CStateVar*>();
00291
00292 for(sv=stateVars->begin();!stateVars->end();sv=stateVars->next())
00293 stateVarsChildren->append(sv);
00294 sv = new CStateVar(0, "void *", 0,"_bgParentLog", 0, NULL, 1);
00295 stateVarsChildren->append(sv);
00296 #else
00297 stateVarsChildren = stateVars;
00298 #endif
00299
00300 SdagConstruct *cn;
00301 TList<CStateVar*> *whensEntryMethodStateVars;
00302 whensEntryMethodStateVars = new TList<CStateVar*>();
00303 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
00304 cn->propagateState(*stateVarsChildren, *whensEntryMethodStateVars , *publishesList, uniqueVarNum);
00305 }
00306 }
00307
00308
00309 void SdagConstruct::propagateState(TList<CStateVar*>& list, TList<CStateVar*>& wlist, TList<SdagConstruct*>& publist, int uniqueVarNum)
00310 {
00311 CStateVar *sv;
00312 TList<CStateVar*> *whensEntryMethodStateVars;
00313 stateVars = new TList<CStateVar*>();
00314 switch(type) {
00315 case SFORALL:
00316 stateVarsChildren = new TList<CStateVar*>();
00317 for(sv=list.begin(); !list.end(); sv=list.next()) {
00318 stateVars->append(sv);
00319 stateVarsChildren->append(sv);
00320 }
00321 sv = new CStateVar(0,"int", 0, con1->text->charstar(), 0,NULL, 0);
00322 stateVarsChildren->append(sv);
00323 {
00324 char txt[128];
00325 sprintf(txt, "_cf%d", nodeNum);
00326 counter = new XStr(txt);
00327 sv = new CStateVar(0, "CCounter *", 0, txt, 0, NULL, 1);
00328 stateVarsChildren->append(sv);
00329 }
00330 break;
00331 case SWHEN:
00332 whensEntryMethodStateVars = new TList<CStateVar*>();
00333 stateVarsChildren = new TList<CStateVar*>();
00334 for(sv=list.begin(); !list.end(); sv=list.next()) {
00335 stateVars->append(sv);
00336 stateVarsChildren->append(sv);
00337 }
00338
00339 {
00340 EntryList *el;
00341 el = elist;
00342 ParamList *pl;
00343 while (el != NULL) {
00344 pl = el->entry->param;
00345 el->entry->stateVars = new TList<CStateVar*>();
00346 if (pl->isVoid()) {
00347 sv = new CStateVar(1, NULL, 0, NULL, 0, NULL, 0);
00348
00349 stateVarsChildren->append(sv);
00350 whensEntryMethodStateVars->append(sv);
00351 el->entry->estateVars.append(sv);
00352 el->entry->stateVars->append(sv);
00353 }
00354 else {
00355 while(pl != NULL) {
00356 sv = new CStateVar(pl);
00357 stateVarsChildren->append(sv);
00358 whensEntryMethodStateVars->append(sv);
00359 el->entry->estateVars.append(sv);
00360 el->entry->stateVars->append(sv);
00361
00362 pl = pl->next;
00363 }
00364 }
00365 el = el->next;
00366
00367 }
00368 }
00369 break;
00370 case SIF:
00371 for(sv=list.begin(); !list.end(); sv=list.next()) {
00372 stateVars->append(sv);
00373 }
00374 stateVarsChildren = stateVars;
00375 if(con2 != 0) con2->propagateState(list, wlist,publist, uniqueVarNum);
00376 break;
00377 case SOLIST:
00378 stateVarsChildren = new TList<CStateVar*>();
00379 for(sv=list.begin(); !list.end(); sv=list.next()) {
00380 stateVars->append(sv);
00381 stateVarsChildren->append(sv);
00382 }
00383 {
00384 char txt[128];
00385 sprintf(txt, "_co%d", nodeNum);
00386 counter = new XStr(txt);
00387 sv = new CStateVar(0, "CCounter *", 0, txt, 0, NULL, 1);
00388 stateVarsChildren->append(sv);
00389 }
00390 break;
00391 case SFOR:
00392 case SWHILE:
00393 case SELSE:
00394 case SSLIST:
00395 case SOVERLAP:
00396 for(sv=list.begin(); !list.end(); sv=list.next()) {
00397 stateVars->append(sv);
00398 }
00399 stateVarsChildren = stateVars;
00400 break;
00401 case SATOMIC:
00402 for(sv=list.begin(); !list.end(); sv=list.next()) {
00403 stateVars->append(sv);
00404 }
00405 stateVarsChildren = stateVars;
00406 if (con1 != 0) {
00407 publist.append(con1);
00408
00409
00410
00411
00412
00413
00414 }
00415 break;
00416 case SFORWARD:
00417 stateVarsChildren = new TList<CStateVar*>();
00418 for(sv=list.begin(); !list.end(); sv=list.next()) {
00419 stateVars->append(sv);
00420 }
00421 for(sv=wlist.begin(); !wlist.end(); sv=wlist.next()) {
00422 stateVarsChildren->append(sv);
00423 }
00424
00425 break;
00426 case SCONNECT:
00427 case SINT_EXPR:
00428 case SIDENT:
00429 case SENTRY:
00430 case SELIST:
00431 break;
00432 default:
00433 fprintf(stderr, "internal error in sdag translator..\n");
00434 exit(1);
00435 break;
00436 }
00437 SdagConstruct *cn;
00438 if (constructs != 0) {
00439 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
00440 if (type == SWHEN)
00441 cn->propagateState(*stateVarsChildren, *whensEntryMethodStateVars, publist, uniqueVarNum);
00442 else
00443 cn->propagateState(*stateVarsChildren, wlist, publist, uniqueVarNum);
00444 }
00445 }
00446 }
00447
00448 void SdagConstruct::generateCode(XStr& decls, XStr& defs, Entry *entry)
00449 {
00450 switch(type) {
00451 case SSDAGENTRY:
00452 generateSdagEntry(decls, defs, entry);
00453 break;
00454 case SSLIST:
00455 generateSlist(decls, defs, entry);
00456 break;
00457 case SOLIST:
00458 generateOlist(decls, defs, entry);
00459 break;
00460 case SFORALL:
00461 generateForall(decls, defs, entry);
00462 break;
00463 case SATOMIC:
00464 generateAtomic(decls, defs, entry);
00465 break;
00466 case SIF:
00467 generateIf(decls, defs, entry);
00468 if(con2 != 0)
00469 con2->generateCode(decls, defs, entry);
00470 break;
00471 case SELSE:
00472 generateElse(decls, defs, entry);
00473 break;
00474 case SWHILE:
00475 generateWhile(decls, defs, entry);
00476 break;
00477 case SFOR:
00478 generateFor(decls, defs, entry);
00479 break;
00480 case SOVERLAP:
00481 generateOverlap(decls, defs, entry);
00482 break;
00483 case SWHEN:
00484 generateWhen(decls, defs, entry);
00485 break;
00486 case SFORWARD:
00487 generateForward(decls, defs, entry);
00488 break;
00489 case SCONNECT:
00490 generateConnect(decls, defs, entry);
00491 break;
00492 default:
00493 break;
00494 }
00495 SdagConstruct *cn;
00496 if (constructs != 0) {
00497 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
00498 cn->generateCode(decls, defs, entry);
00499 }
00500 }
00501 }
00502
00503 void SdagConstruct::generateConnect(XStr& decls, XStr& defs, Entry* entry) {
00504 generateSignature(decls, defs, entry, false, "void", label, false, NULL);
00505 defs << " int index;\n";
00506 if ((param->isVoid() == 0) && (param->isMessage() == 0)) {
00507 defs << " CkMarshallMsg *x;\n";
00508 defs << " index = CkIndex_Ar1::" <<connectEntry->charstar() <<"(x);\n";
00509 defs << " CkCallback cb(index, CkArrayIndex1D(thisIndex), a1);\n";
00510 }
00511 else if (param->isVoid() == 1) {
00512 defs << " index = CkIndex_Ar1::" <<connectEntry->charstar() <<"(void);\n";
00513 defs << " CkCallback cb(index, CkArrayIndex1D(thisIndex), a1);\n";
00514 }
00515 else {
00516 defs << " " << param->getBaseName() <<" *x;\n";
00517 defs << " index = CkIndex_Ar1::" <<connectEntry->charstar() <<"(x);\n";
00518 defs << " CkCallback cb(index, CkArrayIndex1D(thisIndex), a1);\n";
00519 }
00520 defs << " myPublish->get_" <<connectEntry->charstar() <<"(cb);\n";
00521
00522 endMethod(defs);
00523 }
00524
00525 void SdagConstruct::generateForward(XStr& decls, XStr& defs, Entry* entry) {
00526 SdagConstruct *cn;
00527 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
00528 for (cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
00529 defs << " { ";
00530 generateCall(defs, *stateVarsChildren, cn->text->charstar());
00531 defs<<" }\n";
00532 }
00533 generateCall(defs, *stateVarsChildren, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
00534 endMethod(defs);
00535 }
00536
00537
00538 void SdagConstruct::generateWhen(XStr& decls, XStr& defs, Entry* entry)
00539 {
00540 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
00541 generateSignature(decls, defs, entry, false, "int", label, false, stateVars);
00542 #if CMK_BIGSIM_CHARM
00543 generateBeginTime(defs);
00544 #endif
00545
00546 CStateVar *sv;
00547
00548 Entry *e;
00549 EntryList *el;
00550 el = elist;
00551 while (el != NULL){
00552 e = el->entry;
00553 if (e->param->isVoid() == 1)
00554 defs << " CMsgBuffer *"<<e->getEntryName()<<"_buf;\n";
00555 else if (e->paramIsMarshalled() == 1) {
00556
00557 defs << " CMsgBuffer *"<<e->getEntryName()<<"_buf;\n";
00558 defs << " CkMarshallMsg *" <<
00559 e->getEntryName() << "_msg;\n";
00560 }
00561 else {
00562 for(sv=e->stateVars->begin(); !e->stateVars->end(); e->stateVars->next()) {
00563 defs << " CMsgBuffer *"<<sv->name->charstar()<<"_buf;\n";
00564 defs << " " << sv->type->charstar() << " " <<
00565 sv->name->charstar() << ";\n";
00566 }
00567 }
00568 el = el->next;
00569 }
00570
00571 defs << "\n";
00572 el = elist;
00573 while (el != NULL) {
00574 e = el->entry;
00575
00576 defs << " ";
00577 if ((e->paramIsMarshalled() == 1) || (e->param->isVoid() == 1))
00578 defs << e->getEntryName();
00579 else
00580 defs << sv->name->charstar();
00581 defs << "_buf = __cDep->getMessage(" << e->entryPtr->entryNum;
00582 if (e->intExpr)
00583 defs << ", " << e->intExpr;
00584 defs << "); // SEGFAULT? __cDep = 0x0? Did you call __sdag_init() in your constructor?\n";
00585
00586 el = el->next;
00587 }
00588
00589 defs << "\n";
00590 defs << " if (";
00591 el = elist;
00592 while (el != NULL) {
00593 e = el->entry;
00594 if ((e->paramIsMarshalled() == 1) || (e->param->isVoid() ==1)) {
00595 defs << "(" << e->getEntryName() << "_buf != 0)";
00596 }
00597 else {
00598 sv = e->stateVars->begin();
00599 defs << "(" << sv->name->charstar() << "_buf != 0)";
00600 }
00601 el = el->next;
00602 if (el != NULL)
00603 defs << "&&";
00604 }
00605 defs << ") {\n";
00606
00607 #if CMK_BIGSIM_CHARM
00608
00609
00610 int elen=0;
00611 for(el=elist; el!=NULL; el=elist->next) elen++;
00612
00613 defs << " void * logs1["<< elen << "]; \n";
00614 defs << " void * logs2["<< elen + 1<< "]; \n";
00615 int localnum = 0;
00616 for(el=elist; el!=NULL; el=elist->next) {
00617 e = el->entry;
00618 if ((e->paramIsMarshalled() == 1) || (e->param->isVoid() ==1)) {
00619 defs << " logs1[" << localnum << "] = " << e->getEntryName() << "_buf->bgLog1; \n";
00620 defs << " logs2[" << localnum << "] = " << e->getEntryName() << "_buf->bgLog2; \n";
00621 localnum++;
00622 }
00623 else{
00624 defs << " logs1[" << localnum << "] = " << sv->name->charstar()<< "_buf->bgLog1; \n";
00625 defs << " logs2[" << localnum << "] = " << sv->name->charstar() << "_buf->bgLog2; \n";
00626 localnum++;
00627 }
00628 }
00629
00630 defs << " logs2[" << localnum << "] = " << "_bgParentLog; \n";
00631 generateEventBracket(defs,SWHEN);
00632 defs << " _TRACE_BG_FORWARD_DEPS(logs1,logs2,"<< localnum << ",_bgParentLog);\n";
00633 #endif
00634
00635 el = elist;
00636 while (el != NULL) {
00637 e = el->entry;
00638 if (e->param->isVoid() == 1) {
00639 defs <<" CkFreeSysMsg((void *) "<<e->getEntryName() <<"_buf->msg);\n";
00640 defs << " __cDep->removeMessage(" << e->getEntryName() <<
00641 "_buf);\n";
00642 defs << " delete " << e->getEntryName() << "_buf;\n";
00643 }
00644 else if (e->paramIsMarshalled() == 1) {
00645 defs << " " << e->getEntryName() << "_msg = (CkMarshallMsg *)"
00646 << e->getEntryName() << "_buf->msg;\n";
00647 defs << " char *"<<e->getEntryName() <<"_impl_buf=((CkMarshallMsg *)"
00648 <<e->getEntryName() <<"_msg)->msgBuf;\n";
00649 defs <<" PUP::fromMem " <<e->getEntryName() <<"_implP("
00650 <<e->getEntryName() <<"_impl_buf);\n";
00651
00652 for(sv=e->stateVars->begin(); !e->stateVars->end(); sv=e->stateVars->next()) {
00653 if (sv->arrayLength != NULL)
00654 defs <<" int impl_off_"<<sv->name->charstar()
00655 <<"; "<<e->getEntryName() <<"_implP|impl_off_"
00656 <<sv->name->charstar()<<";\n";
00657 else
00658 defs <<" "<<sv->type->charstar()<<" "<<sv->name->charstar()
00659 <<"; " <<e->getEntryName() <<"_implP|"
00660 <<sv->name->charstar()<<";\n";
00661 }
00662 defs << " " <<e->getEntryName() <<"_impl_buf+=CK_ALIGN("
00663 <<e->getEntryName() <<"_implP.size(),16);\n";
00664 for(sv=e->stateVars->begin(); !e->stateVars->end(); sv=e->stateVars->next()) {
00665 if (sv->arrayLength != NULL)
00666 defs << " "<<sv->type->charstar()<< " *" <<sv->name->charstar() <<"=(" <<sv->type->charstar()
00667 <<" *)(" <<e->getEntryName() <<"_impl_buf+" <<"impl_off_"
00668 <<sv->name->charstar()<<");\n";
00669 }
00670 defs << " __cDep->removeMessage(" << e->getEntryName() <<
00671 "_buf);\n";
00672 defs << " delete " << e->getEntryName() << "_buf;\n";
00673 }
00674 else {
00675 sv = e->stateVars->begin();
00676 defs << " " << sv->name->charstar() << " = (" <<
00677 sv->type->charstar() << ") " <<
00678 sv->name->charstar() << "_buf->msg;\n";
00679 defs << " __cDep->removeMessage(" << sv->name->charstar() <<
00680 "_buf);\n";
00681 defs << " delete " << sv->name->charstar() << "_buf;\n";
00682 }
00683 el = el->next;
00684 }
00685
00686
00687 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00688 defs << " " << label->charstar() << "_PathMergePoint.updateMax(currentlyExecutingPath); /* Critical Path Detection */ \n";
00689 defs << " currentlyExecutingPath = " << label->charstar() << "_PathMergePoint; /* Critical Path Detection */ \n";
00690 defs << " " << label->charstar() << "_PathMergePoint.reset(); /* Critical Path Detection */ \n";
00691 #endif
00692
00693 defs << " ";
00694
00695 if (constructs && !constructs->empty()) {
00696 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
00697 } else {
00698 generateCall(defs, *stateVarsChildren, label->charstar(), "_end");
00699 }
00700
00701 el = elist;
00702 while (el != NULL){
00703 e = el->entry;
00704 if (e->paramIsMarshalled() == 1) {
00705 defs << " delete " << e->getEntryName() << "_msg;\n";
00706 }
00707 el = el->next;
00708 }
00709 defs << " return 1;\n";
00710 defs << " } else {\n";
00711
00712 int nRefs=0, nAny=0;
00713 el = elist;
00714 while (el != NULL) {
00715 e = el->entry;
00716 if(e->intExpr == 0)
00717 nAny++;
00718 else
00719 nRefs++;
00720 el = el->next;
00721 }
00722
00723
00724 #define MAXARG 8
00725 #define MAXANY 8
00726 #define MAXREF 8
00727
00728 if(stateVars->length() > MAXARG) {
00729 fprintf(stderr, "numStateVars more that %d, contact developers.\n",
00730 MAXARG);
00731 exit(1);
00732 }
00733 if(nRefs > MAXREF) {
00734 fprintf(stderr, "numDepends more that %d, contact developers.\n",
00735 MAXREF);
00736 exit(1);
00737 }
00738 if(nAny > MAXANY) {
00739 fprintf(stderr, "numDepends more that %d, contact developers.\n",
00740 MAXANY);
00741 exit(1);
00742 }
00743 defs << " CWhenTrigger *tr;\n";
00744 defs << " tr = new CWhenTrigger(" << nodeNum << ", " <<
00745 stateVars->length() << ", " << nRefs << ", " << nAny << ");\n";
00746 int iArgs=0;
00747
00748
00749 int hasArray = 0;
00750 int numParamsNeedingMarshalling = 0;
00751 int paramIndex =0;
00752 for(sv=stateVars->begin();!stateVars->end();sv=stateVars->next()) {
00753 if (sv->isVoid == 1) {
00754
00755 defs <<" tr->args[" <<iArgs++ <<"] = (size_t)0xFF;\n";
00756 }
00757 else {
00758 if (sv->isMsg == 1) {
00759 defs << " tr->args["<<iArgs++ <<"] = (size_t) " <<sv->name->charstar()<<";\n";
00760 }
00761 else {
00762 numParamsNeedingMarshalling++;
00763 if (numParamsNeedingMarshalling == 1) {
00764 defs << " int impl_off=0;\n";
00765 paramIndex = iArgs;
00766 iArgs++;
00767 }
00768 }
00769 if (sv->arrayLength !=NULL) {
00770 hasArray++;
00771 if (hasArray == 1)
00772 defs<< " int impl_arrstart=0;\n";
00773 defs <<" int impl_off_"<<sv->name->charstar()<<", impl_cnt_"<<sv->name->charstar()<<";\n";
00774 defs <<" impl_off_"<<sv->name->charstar()<<"=impl_off=CK_ALIGN(impl_off,sizeof("<<sv->type->charstar()<<"));\n";
00775 defs <<" impl_off+=(impl_cnt_"<<sv->name->charstar()<<"=sizeof("<<sv->type->charstar()<<")*("<<sv->arrayLength->charstar()<<"));\n";
00776 }
00777 }
00778 }
00779 if (numParamsNeedingMarshalling > 0) {
00780 defs << " { \n";
00781 defs << " PUP::sizer implP;\n";
00782 for(sv=stateVars->begin();!stateVars->end();sv=stateVars->next()) {
00783 if (sv->arrayLength !=NULL)
00784 defs << " implP|impl_off_" <<sv->name->charstar() <<";\n";
00785 else if ((sv->isMsg != 1) && (sv->isVoid !=1))
00786 defs << " implP|" <<sv->name->charstar() <<";\n";
00787 }
00788 if (hasArray > 0) {
00789 defs <<" impl_arrstart=CK_ALIGN(implP.size(),16);\n";
00790 defs <<" impl_off+=impl_arrstart;\n";
00791 }
00792 else {
00793 defs << " impl_off+=implP.size();\n";
00794 }
00795 defs << " }\n";
00796 defs << " CkMarshallMsg *impl_msg;\n";
00797 defs << " impl_msg = CkAllocateMarshallMsg(impl_off,NULL);\n";
00798 defs << " {\n";
00799 defs << " PUP::toMem implP((void *)impl_msg->msgBuf);\n";
00800 for(sv=stateVars->begin();!stateVars->end();sv=stateVars->next()) {
00801 if (sv->arrayLength !=NULL)
00802 defs << " implP|impl_off_" <<sv->name->charstar() <<";\n";
00803 else if ((sv->isMsg != 1) && (sv->isVoid != 1))
00804 defs << " implP|" <<sv->name->charstar() <<";\n";
00805 }
00806 defs << " }\n";
00807 if (hasArray > 0) {
00808 defs <<" char *impl_buf=impl_msg->msgBuf+impl_arrstart;\n";
00809 for(sv=stateVars->begin();!stateVars->end();sv=stateVars->next()) {
00810 if (sv->arrayLength !=NULL)
00811 defs << " memcpy(impl_buf+impl_off_"<<sv->name->charstar()<<
00812 ","<<sv->name->charstar()<<",impl_cnt_"<<sv->name->charstar()<<");\n";
00813 }
00814 }
00815 defs << " tr->args[" <<paramIndex <<"] = (size_t) impl_msg;\n";
00816 }
00817 int iRef=0, iAny=0;
00818
00819 el = elist;
00820 while (el != NULL) {
00821 e = el->entry;
00822 if(e->intExpr == 0) {
00823 defs << " tr->anyEntries[" << iAny++ << "] = " <<
00824 e->entryPtr->entryNum << ";\n";
00825 } else {
00826 defs << " tr->entries[" << iRef << "] = " <<
00827 e->entryPtr->entryNum << ";\n";
00828 defs << " tr->refnums[" << iRef++ << "] = " <<
00829 e->intExpr << ";\n";
00830 }
00831 el = el->next;
00832 }
00833
00834 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00835
00836 defs << " " << label->charstar() << "_PathMergePoint.updateMax(currentlyExecutingPath); /* Critical Path Detection */ \n";
00837 defs << " currentlyExecutingPath = " << label->charstar() << "_PathMergePoint; /* Critical Path Detection */ \n";
00838 #endif
00839
00840 defs << " __cDep->Register(tr);\n";
00841 defs << " return 0;\n";
00842 defs << " }\n";
00843
00844 endMethod(defs);
00845
00846
00847 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
00848 strcat(nameStr,"_end");
00849
00850 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
00851 #if CMK_BIGSIM_CHARM
00852 generateBeginTime(defs);
00853 generateEventBracket(defs, SWHEN_END);
00854 #endif
00855 defs << " ";
00856 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
00857
00858 el = elist;
00859 while (el) {
00860 e = el->entry;
00861 if (e->param->isMessage() == 1) {
00862 sv = e->stateVars->begin();
00863 defs << " CmiFree(UsrToEnv(" << sv->name->charstar() << "));\n";
00864 }
00865
00866 el = el->next;
00867 }
00868
00869 endMethod(defs);
00870 }
00871
00872 void SdagConstruct::generateWhile(XStr& decls, XStr& defs, Entry* entry)
00873 {
00874 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
00875 defs << " if (" << con1->text->charstar() << ") {\n";
00876 defs << " ";
00877 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
00878 defs << " } else {\n";
00879 defs << " ";
00880 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
00881 defs << " }\n";
00882 endMethod(defs);
00883
00884 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
00885 defs << " if (" << con1->text->charstar() << ") {\n";
00886 defs << " ";
00887 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
00888 defs << " } else {\n";
00889 defs << " ";
00890 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
00891 defs << " }\n";
00892 endMethod(defs);
00893 }
00894
00895 void SdagConstruct::generateFor(XStr& decls, XStr& defs, Entry* entry)
00896 {
00897 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
00898
00899 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
00900 #if CMK_BIGSIM_CHARM
00901 generateBeginTime(defs);
00902 #endif
00903 defs << " " << con1->text->charstar() << ";\n";
00904
00905 #if CMK_BIGSIM_CHARM
00906 generateEventBracket(defs, SFOR);
00907 #endif
00908 defs << " if (" << con2->text->charstar() << ") {\n";
00909 defs << " ";
00910 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
00911 defs << " } else {\n";
00912 defs << " ";
00913 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
00914 defs << " }\n";
00915 endMethod(defs);
00916
00917
00918 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
00919 strcat(nameStr,"_end");
00920
00921 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
00922 #if CMK_BIGSIM_CHARM
00923 generateBeginTime(defs);
00924 #endif
00925 defs << " " << con3->text->charstar() << ";\n";
00926 defs << " if (" << con2->text->charstar() << ") {\n";
00927 defs << " ";
00928 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
00929 defs << " } else {\n";
00930 #if CMK_BIGSIM_CHARM
00931 generateEventBracket(defs, SFOR_END);
00932 #endif
00933 defs << " ";
00934 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
00935 defs << " }\n";
00936 endMethod(defs);
00937 }
00938
00939 void SdagConstruct::generateIf(XStr& decls, XStr& defs, Entry* entry)
00940 {
00941 strcpy(nameStr,label->charstar());
00942 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
00943 #if CMK_BIGSIM_CHARM
00944 generateBeginTime(defs);
00945 generateEventBracket(defs, SIF);
00946 #endif
00947 defs << " if (" << con1->text->charstar() << ") {\n";
00948 defs << " ";
00949 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
00950 defs << " } else {\n";
00951 defs << " ";
00952 if (con2 != 0) {
00953 generateCall(defs, *stateVarsChildren, con2->label->charstar());
00954 } else {
00955 generateCall(defs, *stateVarsChildren, label->charstar(), "_end");
00956 }
00957 defs << " }\n";
00958 endMethod(defs);
00959
00960 strcpy(nameStr,label->charstar());
00961 strcat(nameStr,"_end");
00962 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
00963 #if CMK_BIGSIM_CHARM
00964 generateBeginTime(defs);
00965 generateEventBracket(defs,SIF_END);
00966 #endif
00967 defs << " ";
00968 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
00969 endMethod(defs);
00970 }
00971
00972 void SdagConstruct::generateElse(XStr& decls, XStr& defs, Entry* entry)
00973 {
00974 strcpy(nameStr,label->charstar());
00975 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
00976
00977 generateBeginTime(defs);
00978 generateEventBracket(defs, SELSE);
00979 defs << " ";
00980 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
00981 endMethod(defs);
00982
00983
00984 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
00985 strcat(nameStr,"_end");
00986 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
00987 #if CMK_BIGSIM_CHARM
00988 generateBeginTime(defs);
00989 generateEventBracket(defs,SELSE_END);
00990 #endif
00991 defs << " ";
00992 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
00993 endMethod(defs);
00994 }
00995
00996 void SdagConstruct::generateForall(XStr& decls, XStr& defs, Entry* entry)
00997 {
00998 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
00999 defs << " int __first = (" << con2->text->charstar() <<
01000 "), __last = (" << con3->text->charstar() <<
01001 "), __stride = (" << con4->text->charstar() << ");\n";
01002 defs << " if (__first > __last) {\n";
01003 defs << " int __tmp=__first; __first=__last; __last=__tmp;\n";
01004 defs << " __stride = -__stride;\n";
01005 defs << " }\n";
01006 defs << " CCounter *" << counter->charstar() <<
01007 " = new CCounter(__first,__last,__stride);\n";
01008 defs << " for(int " << con1->text->charstar() <<
01009 "=__first;" << con1->text->charstar() <<
01010 "<=__last;" << con1->text->charstar() << "+=__stride) {\n";
01011 defs << " ";
01012 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
01013 defs << " }\n";
01014 endMethod(defs);
01015
01016 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
01017 defs << " " << counter->charstar() << "->decrement(); /* DECREMENT 1 */ \n";
01018 defs << " if (" << counter->charstar() << "->isDone()) {\n";
01019 defs << " delete " << counter->charstar() << ";\n";
01020 defs << " ";
01021 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
01022 defs << " }\n";
01023 endMethod(defs);
01024 }
01025
01026 void SdagConstruct::generateOlist(XStr& decls, XStr& defs, Entry* entry)
01027 {
01028 SdagConstruct *cn;
01029 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
01030 defs << " CCounter *" << counter->charstar() << "= new CCounter(" <<
01031 constructs->length() << ");\n";
01032 for(cn=constructs->begin();
01033 !constructs->end(); cn=constructs->next()) {
01034 defs << " ";
01035 generateCall(defs, *stateVarsChildren, cn->label->charstar());
01036 }
01037 endMethod(defs);
01038
01039 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
01040 strcat(nameStr,"_end");
01041 #if CMK_BIGSIM_CHARM
01042 defs << " CkVec<void*> " <<label->charstar() << "_bgLogList;\n";
01043 #endif
01044
01045 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
01046 #if CMK_BIGSIM_CHARM
01047 generateBeginTime(defs);
01048 defs << " " <<label->charstar() << "_bgLogList.insertAtEnd(_bgParentLog);\n";
01049 #endif
01050
01051 defs << " " << counter->charstar() << "->decrement();\n";
01052
01053 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
01054 defs << " olist_" << counter->charstar() << "_PathMergePoint.updateMax(currentlyExecutingPath); /* Critical Path Detection FIXME: is the currently executing path the right thing for this? The duration ought to have been added somewhere. */ \n";
01055 #endif
01056
01057 defs << " if (" << counter->charstar() << "->isDone()) {\n";
01058
01059 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
01060 defs << " currentlyExecutingPath = olist_" << counter->charstar() << "_PathMergePoint; /* Critical Path Detection */ \n";
01061 defs << " olist_" << counter->charstar() << "_PathMergePoint.reset(); /* Critical Path Detection */ \n";
01062 #endif
01063
01064 defs << " delete " << counter->charstar() << ";\n";
01065
01066 #if CMK_BIGSIM_CHARM
01067 generateListEventBracket(defs, SOLIST_END);
01068 defs << " "<< label->charstar() <<"_bgLogList.length()=0;\n";
01069 #endif
01070
01071 defs << " ";
01072 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
01073 defs << " }\n";
01074 endMethod(defs);
01075 }
01076
01077 void SdagConstruct::generateOverlap(XStr& decls, XStr& defs, Entry* entry)
01078 {
01079 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
01080 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
01081 #if CMK_BIGSIM_CHARM
01082 generateBeginTime(defs);
01083 generateEventBracket(defs, SOVERLAP);
01084 #endif
01085 defs << " ";
01086 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
01087 endMethod(defs);
01088
01089
01090 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
01091 strcat(nameStr,"_end");
01092 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
01093 #if CMK_BIGSIM_CHARM
01094 generateBeginTime(defs);
01095 generateEventBracket(defs, SOVERLAP_END);
01096 #endif
01097 defs << " ";
01098 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
01099 endMethod(defs);
01100 }
01101
01102 void SdagConstruct::generateSlist(XStr& decls, XStr& defs, Entry* entry)
01103 {
01104 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
01105 defs << " ";
01106 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
01107 endMethod(defs);
01108
01109 generateSignature(decls, defs, entry, false, "void", label, true, stateVarsChildren);
01110 defs << " ";
01111 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
01112 endMethod(defs);
01113 }
01114
01115 void SdagConstruct::generateSdagEntry(XStr& decls, XStr& defs, Entry *entry)
01116 {
01117 decls << "public:\n";
01118 generateSignature(decls, defs, entry, false, "void", con1->text, false, stateVars);
01119 SdagConstruct *sc;
01120 SdagConstruct *sc1;
01121 for(sc =publishesList->begin(); !publishesList->end(); sc=publishesList->next()) {
01122 for(sc1=sc->constructs->begin(); !sc->constructs->end(); sc1 = sc->constructs->next())
01123 defs << " _connect_" << sc1->text->charstar() <<"();\n";
01124 }
01125
01126 #if CMK_BIGSIM_CHARM
01127 generateEndSeq(defs);
01128 #endif
01129 if (!entry->getContainer()->isGroup() || !entry->isConstructor())
01130 generateTraceEndCall(defs);
01131
01132 defs << " ";
01133 generateCall(defs, *stateVarsChildren, constructs->front()->label->charstar());
01134
01135 #if CMK_BIGSIM_CHARM
01136 generateTlineEndCall(defs);
01137 generateBeginExec(defs, "spaceholder");
01138 #endif
01139 if (!entry->getContainer()->isGroup() || !entry->isConstructor())
01140 generateDummyBeginExecute(defs);
01141
01142 endMethod(defs);
01143
01144 decls << "private:\n";
01145 generateSignature(decls, defs, entry, false, "void", con1->text, true,
01146 #if CMK_BIGSIM_CHARM
01147 stateVarsChildren
01148 #else
01149 stateVars
01150 #endif
01151 );
01152 endMethod(defs);
01153 }
01154
01155 void SdagConstruct::generateAtomic(XStr& decls, XStr& defs, Entry* entry)
01156 {
01157 generateSignature(decls, defs, entry, false, "void", label, false, stateVars);
01158
01159 #if CMK_BIGSIM_CHARM
01160 sprintf(nameStr,"%s%s", CParsedFile::className->charstar(),label->charstar());
01161 generateBeginExec(defs, nameStr);
01162 #endif
01163 generateTraceBeginCall(defs);
01164
01165 defs << " " << text->charstar() << "\n";
01166
01167 generateTraceEndCall(defs);
01168 #if CMK_BIGSIM_CHARM
01169 generateEndExec(defs);
01170 #endif
01171
01172 defs << " ";
01173 generateCall(defs, *stateVars, next->label->charstar(), nextBeginOrEnd ? 0 : "_end");
01174 endMethod(defs);
01175 }
01176
01177 void generateSignature(XStr& str,
01178 const XStr* name, const char* suffix,
01179 TList<CStateVar*>* params)
01180 {
01181
01182 }
01183 void generateSignature(XStr& decls, XStr& defs,
01184 const Entry* entry, bool declareStatic, const char* returnType,
01185 const XStr* name, bool isEnd,
01186 TList<CStateVar*>* params)
01187 {
01188 generateSignature(decls, defs, entry->getContainer(), declareStatic, returnType,
01189 name, isEnd, params);
01190 }
01191 void generateSignature(XStr& decls, XStr& defs,
01192 const Chare* chare, bool declareStatic, const char* returnType,
01193 const XStr* name, bool isEnd,
01194 TList<CStateVar*>* params)
01195 {
01196 decls << " " << (declareStatic ? "static " : "") << returnType << " ";
01197
01198 templateGuardBegin(false, defs);
01199 defs << chare->tspec() << returnType << " " << chare->baseName() << "::";
01200
01201 XStr op;
01202
01203 op << name;
01204 if (isEnd)
01205 op << "_end";
01206 op << "(";
01207
01208 if (params) {
01209 CStateVar *sv;
01210 int count = 0;
01211 for (sv = params->begin(); !params->end(); ) {
01212 if (sv->isVoid != 1) {
01213 if (count != 0)
01214 op << ", ";
01215
01216 if (sv->type != 0)
01217 op <<sv->type->charstar() <<" ";
01218 if (sv->byRef != 0)
01219 op <<" &";
01220 if (sv->arrayLength != NULL)
01221 op <<"* ";
01222 if (sv->name != 0)
01223 op <<sv->name->charstar();
01224
01225 count++;
01226 }
01227
01228 sv = params->next();
01229 }
01230 }
01231
01232 op << ")";
01233
01234 decls << op << ";\n";
01235 defs << op << " {\n";
01236 }
01237 void endMethod(XStr& op)
01238 {
01239 op << "}\n";
01240 templateGuardEnd(op);
01241 op << "\n\n";
01242 }
01243
01244 void SdagConstruct::generateCall(XStr& op, TList<CStateVar*>& list,
01245 const char* name, const char* nameSuffix) {
01246 op << name << (nameSuffix ? nameSuffix : "") << "(";
01247
01248 CStateVar *sv;
01249 int isVoid;
01250 int count;
01251 count = 0;
01252 for(sv=list.begin(); !list.end(); ) {
01253 isVoid = sv->isVoid;
01254 if ((count != 0) && (isVoid != 1))
01255 op << ", ";
01256 if (sv->name != 0)
01257 op << sv->name->charstar();
01258 if (sv->isVoid != 1)
01259 count++;
01260 sv = list.next();
01261 }
01262
01263 op << ");\n";
01264 }
01265
01266
01267
01268 void SdagConstruct::setNext(SdagConstruct *n, int boe)
01269 {
01270 switch(type) {
01271 case SSLIST:
01272 next = n;
01273 nextBeginOrEnd = boe;
01274 {
01275 SdagConstruct *cn=constructs->begin();
01276 if (cn==0)
01277 return;
01278
01279 for(SdagConstruct *nextNode=constructs->next(); nextNode != 0; nextNode = constructs->next()) {
01280 if (nextNode->type == SCONNECT)
01281 continue;
01282
01283 cn->setNext(nextNode, 1);
01284 cn = nextNode;
01285 }
01286 cn->setNext(this, 0);
01287 }
01288 return;
01289 case SSDAGENTRY:
01290 case SOVERLAP:
01291 case SOLIST:
01292 case SFORALL:
01293 case SWHEN:
01294 case SFOR:
01295 case SWHILE:
01296 case SATOMIC:
01297 case SFORWARD:
01298 case SELSE:
01299 next = n;
01300 nextBeginOrEnd = boe;
01301 n = this; boe = 0; break;
01302 case SIF:
01303 next = n;
01304 nextBeginOrEnd = boe;
01305 if(con2 != 0)
01306 con2->setNext(n, boe);
01307 n = this;
01308 boe = 0;
01309 break;
01310 default:
01311 break;
01312 }
01313 SdagConstruct *cn;
01314 if (constructs != 0) {
01315 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
01316 cn->setNext(n, boe);
01317 }
01318 }
01319 }
01320
01321
01322
01323
01324 void SdagConstruct::generateTrace()
01325 {
01326 char text[1024];
01327 switch(type) {
01328 case SATOMIC:
01329 if (traceName) {
01330 sprintf(text, "%s_%s", CParsedFile::className->charstar(), traceName->charstar());
01331
01332 for (unsigned int i=0; i<strlen(text); i++)
01333 if (text[i]==' '||text[i]=='\t') text[i]='_';
01334 }
01335 else {
01336 sprintf(text, "%s%s", CParsedFile::className->charstar(), label->charstar());
01337 }
01338 traceName = new XStr(text);
01339 break;
01340 default:
01341 break;
01342 }
01343
01344 SdagConstruct *cn;
01345 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
01346 cn->generateTrace();
01347 }
01348 if (con1) con1->generateTrace();
01349 if (con2) con2->generateTrace();
01350 if (con3) con3->generateTrace();
01351 }
01352
01353 void SdagConstruct::generateTraceBeginCall(XStr& op)
01354 {
01355 if(traceName)
01356 op << " " << "_TRACE_BEGIN_EXECUTE_DETAILED(-1, -1, " << "_sdag_idx_" << traceName->charstar() << "(), CkMyPe(), 0, NULL); \n";
01357 }
01358
01359 void SdagConstruct::generateDummyBeginExecute(XStr& op)
01360 {
01361 op << " " << "_TRACE_BEGIN_EXECUTE_DETAILED(-1, -1, _dummyEP, CkMyPe(), 0, NULL); \n";
01362 }
01363
01364 void SdagConstruct::generateTraceEndCall(XStr& op)
01365 {
01366 op << " " << "_TRACE_END_EXECUTE(); \n";
01367 }
01368
01369 void SdagConstruct::generateBeginExec(XStr& op, const char *name){
01370 op << " " << "_TRACE_BG_BEGIN_EXECUTE_NOMSG(\""<<name<<"\",&_bgParentLog,1);\n";
01371 }
01372
01373 void SdagConstruct::generateEndExec(XStr& op){
01374 op << " " << "_TRACE_BG_END_EXECUTE(0);\n";
01375 }
01376
01377 void SdagConstruct::generateBeginTime(XStr& op)
01378 {
01379
01380 op << " double __begintime = CkVTimer(); \n";
01381 }
01382
01383 void SdagConstruct::generateTlineEndCall(XStr& op)
01384 {
01385
01386 op <<" _TRACE_BG_TLINE_END(&_bgParentLog);\n";
01387 }
01388
01389 void SdagConstruct::generateEndSeq(XStr& op)
01390 {
01391 op << " void* _bgParentLog = NULL;\n";
01392 op << " CkElapse(0.01e-6);\n";
01393
01394 generateTlineEndCall(op);
01395 generateTraceEndCall(op);
01396 generateEndExec(op);
01397 }
01398
01399 void SdagConstruct::generateEventBracket(XStr& op, int eventType)
01400 {
01401 (void) eventType;
01402
01403 op << " _TRACE_BG_USER_EVENT_BRACKET(\"" << nameStr
01404 << "\", __begintime, CkVTimer(),&_bgParentLog); \n";
01405 }
01406
01407 void SdagConstruct::generateListEventBracket(XStr& op, int eventType)
01408 {
01409 (void) eventType;
01410 op << " _TRACE_BGLIST_USER_EVENT_BRACKET(\"" << nameStr
01411 << "\",__begintime,CkVTimer(),&_bgParentLog, " << label->charstar()
01412 << "_bgLogList);\n";
01413 }
01414
01415 void SdagConstruct::generateRegisterEp(XStr& defs)
01416 {
01417 if (traceName) {
01418 defs << " (void)_sdag_idx_" << traceName << "();\n";
01419 }
01420
01421 SdagConstruct *cn;
01422 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
01423 cn->generateRegisterEp(defs);
01424 }
01425 if (con1) con1->generateRegisterEp(defs);
01426 if (con2) con2->generateRegisterEp(defs);
01427 if (con3) con3->generateRegisterEp(defs);
01428 }
01429
01430 void SdagConstruct::generateTraceEp(XStr& decls, XStr& defs, Chare* chare)
01431 {
01432 if (traceName) {
01433 XStr regName, idxName;
01434
01435 idxName << "_sdag_idx_" << traceName;
01436 regName << "_sdag_reg_" << traceName;
01437 generateSignature(decls, defs, chare, true, "int", &idxName, false, NULL);
01438 defs << " static int epidx = " << regName << "();\n"
01439 << " return epidx;\n";
01440 endMethod(defs);
01441
01442 generateSignature(decls, defs, chare, true, "int", ®Name, false, NULL);
01443 defs << " return CkRegisterEp(\""
01444 << traceName << "\", NULL, 0, " << chare->indexName() << "::__idx, 0"
01445 << ");\n";
01446 endMethod(defs);
01447 }
01448
01449 SdagConstruct *cn;
01450 for(cn=constructs->begin(); !constructs->end(); cn=constructs->next()) {
01451 cn->generateTraceEp(decls, defs, chare);
01452 }
01453 if (con1) con1->generateTraceEp(decls, defs, chare);
01454 if (con2) con2->generateTraceEp(decls, defs, chare);
01455 if (con3) con3->generateTraceEp(decls, defs, chare);
01456 }
01457
01458
01459 void RemoveSdagComments(char *str)
01460 {
01461 char *ptr = str;
01462 while ((ptr = strstr(ptr, "//"))) {
01463 char *lend = strstr(ptr, "\n");
01464 if (lend==NULL) break;
01465 while (ptr != lend) *ptr++=' ';
01466 }
01467 }
01468
01469 }