00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "lego.H"
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <stl.h>
00041 #include <string.h>
00042 #include "TinkerKnobs.H"
00043 #include "legocompress.H"
00044
00045
00046
00047
00048
00049
00050
00051
00052 #define INDENT_SIZE (80)
00053 #define INDENT_INC (2)
00054
00055 char *ParseMap(int);
00056 char *RegionMap(int);
00057
00058 void LegoFree(legoOp*);
00059 int LegoWrite (legoRegion*, FILE *, int);
00060 int LegoWrite (legoRegion*, char *);
00061 int LegoWrite (legoRegion*);
00062
00063 void WriteJump(legoProc*, FILE*);
00064 void WriteAttrs(legoProc*, FILE*);
00065 void WriteEdges(legoProc*, FILE*);
00066 void WriteData(legoProc*, FILE*);
00067 void WriteData(legoModule*, FILE*);
00068 void WriteMem(legoProc*, FILE*);
00069
00070
00071
00072
00073 static const char * const regRTN[] = {"r","vr","mvr","fr","br"};
00074 static const char * const regFTN[] = {"gpr","fpr","pr","btr","cr"};
00075 static const char * const regDTN[] = {"vo","bo","ch","uch","sh","ush","i",
00076 "ui","lng","ulng","llng","ullng",
00077 "lllng","ulllng","ptr","f","d","p",
00078 "b"};
00079
00080 int lineLength;
00081 knobs *K = NULL;
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void WriteOprd (legoOprd* oprdPtr, FILE *outfile)
00102 {
00103 double dblLit;
00104 float fltLit;
00105 int intLit, chrLit, cbLit, predLit, wrtMacro;
00106 long long llLit;
00107 char *lblLit;
00108 char *strLit;
00109 int regN, regT, regS, dataT, fileT, omegaData, intV;
00110 enum addrStyles as;
00111 char newcbstyle;
00112 if (oprdPtr == NULL) { return; }
00113 if (!(oprdPtr->GetValid())) return;
00114 int srcOprdType = oprdPtr->GetOprdType();
00115 switch (srcOprdType) {
00116 case OT_VACANT:
00117 lineLength += fprintf(outfile,"VACANT");
00118 break;
00119 case OT_LITERAL_VO:
00120 lineLength += fprintf(outfile,"vo<>");
00121 break;
00122 case OT_LITERAL_BO:
00123 intLit = oprdPtr->GetLiteralBoolean();
00124 lineLength += fprintf(outfile,"bo<%d>",intLit);
00125 break;
00126 case OT_LITERAL_CH:
00127 intLit = oprdPtr->GetLiteralChar();
00128 lineLength += fprintf(outfile,"ch<%d>",intLit);
00129 break;
00130 case OT_LITERAL_UCH:
00131 intLit = oprdPtr->GetLiteralChar();
00132 lineLength += fprintf(outfile,"uch<%d>",intLit);
00133 break;
00134 case OT_LITERAL_SH:
00135 intLit = oprdPtr->GetLiteralShort();
00136 lineLength += fprintf(outfile,"sh<%d>",intLit);
00137 break;
00138 case OT_LITERAL_USH:
00139 intLit = oprdPtr->GetLiteralUShort();
00140 lineLength += fprintf(outfile,"ush<%d>",intLit);
00141 break;
00142 case OT_LITERAL_I:
00143 intLit = oprdPtr->GetLiteralInteger();
00144 lineLength += fprintf(outfile,"i<%d>",intLit);
00145 break;
00146 case OT_LITERAL_UI:
00147 llLit = oprdPtr->GetLiteralUInteger();
00148 lineLength += fprintf(outfile,"ui<%ld>",intLit);
00149 break;
00150 case OT_LITERAL_LNG:
00151 intLit = oprdPtr->GetLiteralLong();
00152 lineLength += fprintf(outfile,"lng<%ld>",intLit);
00153 break;
00154 case OT_LITERAL_ULNG:
00155 intLit = oprdPtr->GetLiteralULong();
00156 lineLength += fprintf(outfile,"ulng<%uld>",intLit);
00157 break;
00158
00159
00160 case OT_LITERAL_LLNG:
00161 llLit = oprdPtr->GetLiteralLongLong();
00162 lineLength += fprintf(outfile,"llng<%lld>",llLit);
00163 break;
00164 case OT_LITERAL_ULLNG:
00165 intLit = oprdPtr->GetLiteralULongLong();
00166 lineLength += fprintf(outfile,"ullng<%uld>",intLit);
00167 break;
00168 case OT_LITERAL_LLLNG:
00169 intLit = oprdPtr->GetLiteralLongLongLong();
00170 lineLength += fprintf(outfile,"lllng<%ld>",intLit);
00171 break;
00172 case OT_LITERAL_ULLLNG:
00173 intLit = oprdPtr->GetLiteralULongLongLong();
00174 lineLength += fprintf(outfile,"ulllng<%uld>",intLit);
00175 break;
00176 case OT_LITERAL_PTR:
00177 intLit = oprdPtr->GetLiteralPointer();
00178 lineLength += fprintf(outfile,"ptr<%ld>",intLit);
00179 break;
00180 case OT_LITERAL_F:
00181 fltLit = oprdPtr->GetLiteralFloat();
00182 lineLength += fprintf(outfile,"f<%f>",fltLit);
00183 break;
00184 case OT_LITERAL_D:
00185 dblLit = oprdPtr->GetLiteralDouble();
00186 lineLength += fprintf(outfile,"d<%.0lf>",dblLit);
00187 break;
00188 case OT_LITERAL_C:
00189 chrLit = oprdPtr->GetLiteralChar();
00190 lineLength += fprintf(outfile,"c<%c>",chrLit);
00191 break;
00192 case OT_LITERAL_L:
00193 lblLit = oprdPtr->GetLiteralLabel();
00194 as = oprdPtr->GetLiteralAddrStyle();
00195 if (as == AS_UNDEF)
00196 lineLength += fprintf(outfile,"l<%s>",lblLit);
00197 else
00198 lineLength += fprintf(outfile,"l:%s<%s>",ParseMap(as+G_ABS-1),
00199 lblLit);
00200 break;
00201 case OT_LITERAL_S:
00202 strLit = oprdPtr->GetLiteralString();
00203 as = oprdPtr->GetLiteralAddrStyle();
00204 if (as == AS_UNDEF)
00205 lineLength += fprintf(outfile,"s<\"%s\">",strLit);
00206 else
00207 lineLength += fprintf(outfile,"s:%s<\"%s\">",ParseMap(as+G_ABS-1),
00208 strLit);
00209 break;
00210 case OT_LITERAL_CB:
00211 cbLit = oprdPtr->GetLiteralControlBlock();
00212
00213 K->Read ("ir:new-cb-style", newcbstyle);
00214 if (newcbstyle)
00215 lineLength += fprintf(outfile,"b<%d>",cbLit);
00216
00217 else
00218 lineLength += fprintf(outfile,"cb<%d>",cbLit);
00219
00220 break;
00221 case OT_LITERAL_P:
00222 predLit = oprdPtr->GetLiteralPredicate();
00223 if (predLit) { lineLength += fprintf(outfile,"p<t>"); }
00224 else { lineLength += fprintf(outfile,"p<f>"); }
00225 break;
00226 case OT_REG:
00227 regT = oprdPtr->GetOprdRegType();
00228 regS = oprdPtr->GetOprdRegStyle();
00229 dataT = oprdPtr->GetOprdDataType();
00230 fileT = oprdPtr->GetOprdFileType();
00231 regN = oprdPtr->GetOprdRegNum();
00232 intV = oprdPtr->GetOprdIntValue();
00233 omegaData = oprdPtr->GetOprdOmega();
00234 switch (regT) {
00235 case RT_R:
00236 lineLength += fprintf(outfile,"r<%d",regN);
00237 if (omegaData != 0) { lineLength += fprintf(outfile," %d",omegaData); }
00238 lineLength += fprintf(outfile,":%s %s>",regDTN[dataT],regFTN[fileT]);
00239 break;
00240 case RT_VR:
00241 lineLength += fprintf(outfile,"vr<%d",regN);
00242 if (omegaData != 0) { lineLength += fprintf(outfile," %d",omegaData); }
00243 lineLength += fprintf(outfile,":%s>",regDTN[dataT]);
00244 break;
00245 case RT_MVR:
00246 lineLength += fprintf(outfile,"mvr<%d",regN);
00247 if (omegaData != 0) { lineLength += fprintf(outfile," %d",omegaData); }
00248 lineLength += fprintf(outfile,">");
00249 break;
00250 case RT_FR:
00251 lineLength += fprintf(outfile,"fr<%d",regN);
00252 if (omegaData != 0) { lineLength += fprintf(outfile," %d",omegaData); }
00253 lineLength += fprintf(outfile,":%s %s %c>",regDTN[dataT],regFTN[fileT],regS);
00254 break;
00255 case RT_BR:
00256 lineLength += fprintf(outfile,"br<%d",regN);
00257 if (omegaData != 0) { lineLength += fprintf(outfile," %d",omegaData); }
00258 lineLength += fprintf(outfile,":%s %s %c %d>",
00259 regDTN[dataT],regFTN[fileT],regS,intV);
00260 break;
00261 default:
00262 LegoNonFatal ("WriteOprd", "Reg type still not found.");
00263 break;
00264 }
00265 break;
00266 case OT_MACRO:
00267
00268 wrtMacro = oprdPtr->GetOprdRegNum();
00269 if ( wrtMacro < 255 ) { wrtMacro = 256; }
00270 lineLength += fprintf(outfile,"m<%s>",ParseMap(wrtMacro));
00271 break;
00272 case OT_UNDEFINED:
00273 lineLength += fprintf(outfile,"u<>");
00274 break;
00275 default:
00276 LegoNonFatal ("WriteOprd", "Src or dest operand not found.");
00277 break;
00278 }
00279 return;
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 int WriteOps (legoOp* legoOpPtr,
00298 int singleOp,
00299 FILE *outfile,
00300 int offset=0)
00301 {
00302 char indStr[INDENT_SIZE];
00303 unsigned indSz;
00304 unsigned idx;
00305 for (idx = 0; idx<INDENT_SIZE; idx++) { indStr[idx] = '\0'; }
00306 indSz = offset;
00307 for (idx = 0; idx<indSz; idx++) { indStr[idx] = ' '; }
00308
00309 legoOprd *nextPOprdPtr;
00310
00311 lineLength = 0;
00312
00313
00314
00315
00316 int wrtOpId = legoOpPtr->GetOpId();
00317 lineLength += fprintf(outfile,"%sop %d", indStr, wrtOpId);
00318 fflush(outfile);
00319
00320
00321
00322
00323 if(legoOpPtr->GetOpcodePtr() == NULL)
00324 {
00325 int wrtOpcode = legoOpPtr->GetOpcode();
00326 lineLength += fprintf(outfile," (%s",ParseMap(wrtOpcode));
00327 fflush(outfile);
00328 }
00329 else
00330 {
00331
00332 lineLength += fprintf(outfile, "(%s",
00333 legoOpPtr->GetOpcodePtr()->GetOpcString());
00334 fflush(outfile);
00335 }
00336
00337
00338
00339
00340
00341
00342
00343
00344 legoOprd *destPtr = legoOpPtr->GetDestOprdPtr();
00345 lineLength += fprintf(outfile," [");
00346 WriteOprd(destPtr,outfile);
00347 if (destPtr != NULL) {
00348 legoOprd *nextDOprdPtr = destPtr->GetNextOprdPtr();
00349 if (nextDOprdPtr != NULL) {
00350 destPtr = nextDOprdPtr;
00351 lineLength += fprintf(outfile," ");
00352 WriteOprd(destPtr,outfile);
00353 nextDOprdPtr = destPtr->GetNextOprdPtr();
00354 if (nextDOprdPtr != NULL) {
00355 lineLength += fprintf(outfile," ");
00356 WriteOprd(nextDOprdPtr,outfile);
00357 }
00358 }
00359 }
00360 lineLength += fprintf(outfile,"]");
00361 fflush(outfile);
00362
00363
00364
00365
00366
00367
00368
00369
00370 legoOprd *srcPtr = legoOpPtr->GetSrcOprdPtr();
00371 lineLength += fprintf(outfile," [");
00372 WriteOprd(srcPtr,outfile);
00373 if (srcPtr != NULL) {
00374 legoOprd *nextSOprdPtr = srcPtr->GetNextOprdPtr();
00375 if (nextSOprdPtr != NULL) {
00376 srcPtr = nextSOprdPtr;
00377 lineLength += fprintf(outfile," ");
00378 WriteOprd(srcPtr,outfile);
00379 nextSOprdPtr = srcPtr->GetNextOprdPtr();
00380 if (nextSOprdPtr != NULL) {
00381 lineLength += fprintf(outfile," ");
00382 WriteOprd(nextSOprdPtr,outfile);
00383
00384 nextSOprdPtr = nextSOprdPtr->GetNextOprdPtr();
00385 if (nextSOprdPtr != NULL)
00386 {
00387 lineLength += fprintf(outfile," ");
00388 WriteOprd(nextSOprdPtr,outfile);
00389 nextSOprdPtr = nextSOprdPtr->GetNextOprdPtr();
00390 if(nextSOprdPtr != NULL)
00391 {
00392 lineLength += fprintf(outfile," ");
00393 WriteOprd(nextSOprdPtr,outfile);
00394 }
00395 }
00396
00397 }
00398 }
00399 }
00400 lineLength += fprintf(outfile,"]");
00401 fflush(outfile);
00402
00403
00404
00405
00406
00407
00408
00409 legoOprd *predPtr = legoOpPtr->GetPredOprdPtr();
00410 if (predPtr != NULL) {
00411 lineLength += fprintf(outfile," ");
00412 WriteOprd(predPtr,outfile);
00413 nextPOprdPtr = predPtr->GetNextOprdPtr();
00414 if (nextPOprdPtr != NULL) {
00415 LegoNonFatal ("WriteOps", "Multiple predicate operands for op %d.",
00416 legoOpPtr->GetOpId());
00417 }
00418 }
00419 if (lineLength > 65) { fprintf(outfile,"\n%s",indStr); lineLength = 0; }
00420 fflush(outfile);
00421
00422
00423
00424
00425 if ( legoOpPtr->GetSchedOpcode() != NULL ) {
00426 lineLength += fprintf(outfile," s_opcode(%s)",
00427 legoOpPtr->GetSchedOpcode());
00428 if (lineLength > 65) { fprintf(outfile,"\n%s",indStr); lineLength = 0; }
00429 }
00430 fflush(outfile);
00431
00432
00433
00434
00435 opList *chkRelOpsPtr = legoOpPtr->GetRelatedOpsPtr();
00436 if (chkRelOpsPtr != NULL) {
00437 int wrtRelOpId = (chkRelOpsPtr->GetOpPtr())->GetOpId();
00438 double wrtRelOpFF = chkRelOpsPtr->GetWeight();
00439 lineLength += fprintf(outfile," related_ops(op-%d(%f)",wrtRelOpId,wrtRelOpFF);
00440 opList *chkRelONPtr = chkRelOpsPtr->GetNextListPtr();
00441 while (chkRelONPtr != NULL) {
00442 chkRelOpsPtr = chkRelONPtr;
00443 wrtRelOpId = (chkRelOpsPtr->GetOpPtr())->GetOpId();
00444 wrtRelOpFF = chkRelOpsPtr->GetWeight();
00445 chkRelONPtr = chkRelOpsPtr->GetNextListPtr();
00446 lineLength += fprintf(outfile," op-%d(%d)",wrtRelOpId,wrtRelOpFF);
00447 }
00448 lineLength += fprintf(outfile,")");
00449 }
00450 if (lineLength > 65) { fprintf(outfile,"\n%s",indStr); lineLength = 0; }
00451 fflush(outfile);
00452
00453
00454
00455
00456 int wrtSTime = legoOpPtr->GetSchedTime();
00457 if ( wrtSTime > 0 ) {
00458 lineLength += fprintf(outfile," s_time(%d)",wrtSTime);
00459 }
00460 if (lineLength > 65) { fprintf(outfile,"\n%s",indStr); lineLength = 0; }
00461 fflush(outfile);
00462
00463
00464
00465 int wrtSpecul = legoOpPtr->GetSpeculative();
00466 if (wrtSpecul == 1) { lineLength += fprintf(outfile," spec"); }
00467 if (wrtSpecul == 0) { lineLength += fprintf(outfile," nonspec"); }
00468 if (lineLength > 65) { fprintf(outfile,"\n%s",indStr); lineLength = 0; }
00469 fflush(outfile);
00470
00471
00472
00473
00474 attrList *wrtOpAttrListPtr = legoOpPtr->GetOpAttrListPtr();
00475 if (wrtOpAttrListPtr == NULL) { }
00476 else {
00477 lineLength += fprintf(outfile," attr(");
00478 while (wrtOpAttrListPtr != NULL)
00479 {
00480 switch (wrtOpAttrListPtr->GetAttrType())
00481 {
00482 case ATTR_LC:
00483 {
00484 int tmpAttrId = wrtOpAttrListPtr->GetAttrId();
00485 if ( tmpAttrId != 0 ) {
00486 lineLength += fprintf(outfile,"lc ^%d", tmpAttrId);
00487 }
00488 }
00489 break;
00490 case ATTR_LIVE:
00491 {
00492 int tmpAttrId = wrtOpAttrListPtr->GetAttrId();
00493 if ( tmpAttrId != 0 ) {
00494 lineLength += fprintf(outfile,"live ^%d", tmpAttrId);
00495 }
00496 }
00497 break;
00498 case ATTR_TBLNAME:
00499 lineLength += fprintf(outfile, "tbl_name(%s)",
00500 wrtOpAttrListPtr->GetTableName());
00501 break;
00502 default:
00503 break;
00504 }
00505 if (lineLength > 65)
00506 { fprintf(outfile,"\n%s",indStr); lineLength = 0; }
00507
00508 wrtOpAttrListPtr = wrtOpAttrListPtr->GetNextListPtr();
00509 if (wrtOpAttrListPtr != NULL)
00510 lineLength += fprintf(outfile," ");
00511 }
00512 lineLength += fprintf(outfile,")");
00513 }
00514 if (lineLength > 65) { fprintf(outfile,"\n%s",indStr); lineLength = 0; }
00515 fflush(outfile);
00516
00517
00518
00519
00520 flags *wrtOpFlagPtr = legoOpPtr->GetOpFlagPtr();
00521 if (wrtOpFlagPtr == NULL) { }
00522 else {
00523 lineLength += fprintf(outfile," flags(");
00524 flags *tmpFlagPtr = wrtOpFlagPtr;
00525 while ( tmpFlagPtr != NULL ) {
00526 if (tmpFlagPtr->GetFlagName() == 0)
00527 continue;
00528 lineLength += fprintf(outfile,"%s",ParseMap(tmpFlagPtr->GetFlagName()));
00529 tmpFlagPtr = tmpFlagPtr->GetNextFlagPtr();
00530 if ( tmpFlagPtr != NULL ) { lineLength += fprintf(outfile," "); }
00531 }
00532 lineLength += fprintf(outfile,")");
00533 }
00534 if (lineLength > 65) { fprintf(outfile,"\n%s",indStr); lineLength = 0; }
00535 fflush(outfile);
00536
00537
00538
00539
00540 opList *wrtListPtr = legoOpPtr->GetInListPtr();
00541 if ( wrtListPtr != NULL ) {
00542 lineLength += fprintf(outfile," in_edges(");
00543 while ( wrtListPtr != NULL ) {
00544 if ( wrtListPtr->GetOpId() == 0 ) { break; }
00545 fprintf(outfile,"op-%d(%d)",wrtListPtr->GetOpId(),
00546 (int) wrtListPtr->GetWeight());
00547 wrtListPtr = wrtListPtr->GetNextListPtr();
00548 if ( wrtListPtr != NULL ) {
00549 lineLength += fprintf(outfile," ");
00550 }
00551 }
00552 lineLength += fprintf(outfile,")");
00553 }
00554 fflush(outfile);
00555
00556
00557
00558
00559 wrtListPtr = legoOpPtr->GetOutListPtr();
00560 if ( wrtListPtr != NULL ) {
00561 lineLength += fprintf(outfile," out(");
00562 while ( wrtListPtr != NULL ) {
00563 if ( wrtListPtr->GetOpId() == 0) { break; }
00564 fprintf(outfile,"op-%d(%d)",wrtListPtr->GetOpId(),
00565 (int) wrtListPtr->GetWeight());
00566 wrtListPtr = wrtListPtr->GetNextListPtr();
00567 if ( wrtListPtr != NULL ) {
00568 lineLength += fprintf(outfile," ");
00569 }
00570 }
00571 lineLength += fprintf(outfile,")");
00572 }
00573 fflush(outfile);
00574
00575
00576
00577
00578 legoOp *wrtNextOp = legoOpPtr->GetNextLink();
00579
00580
00581
00582
00583 int wrtBlockId= legoOpPtr->GetBlockId();
00584 if (wrtBlockId != -1) {
00585 lineLength += fprintf(outfile," bb_id(%d)",wrtBlockId);
00586 }
00587 fprintf(outfile,")\n");
00588 fflush(outfile);
00589
00590
00591
00592
00593 if ((wrtNextOp != NULL) && (singleOp == 0)) {
00594 if (!WriteOps(wrtNextOp,singleOp,outfile,offset)) { return 0;}
00595 }
00596
00597 return 1;
00598 }
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608 int DumpOps (legoOp* legoOpPtr)
00609 {
00610 return WriteOps(legoOpPtr,0,stderr);
00611 }
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 int LegoWrite (legoRegion* legoRegPtr, char *rblOutFile)
00628 {
00629 FILE *rblout;
00630
00631 if (legoRegPtr->GetRegionType() == RT_MODULE)
00632 LegoWrite ((legoModule *) legoRegPtr, rblOutFile);
00633 else
00634 {
00635
00636
00637
00638 rblout = fopen(rblOutFile, "w");
00639 if (!rblout) {
00640 printf("Fatal Error: LegoWrite - output file %s open failed\n",rblOutFile);
00641 exit(2);
00642 }
00643 LegoWrite (legoRegPtr, rblout, 0);
00644 fclose (rblout);
00645 }
00646 return 1;
00647 }
00648
00649
00650
00651
00652
00653
00654
00655
00656 int LegoWrite (legoRegion* legoRegPtr)
00657 {
00658 if (legoRegPtr->GetRegionType() == RT_MODULE)
00659 LegoWrite ((legoModule *) legoRegPtr, NULL);
00660 else
00661 LegoWrite (legoRegPtr, stderr, 0);
00662 return 1;
00663 }
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676 int LegoWrite (legoRegion* legoRegPtr, FILE *filPtr, int offset)
00677 {
00678 char indStr[INDENT_SIZE];
00679 unsigned indSz;
00680 unsigned idx;
00681 legoProc* procPtr;
00682 legoModule* moduPtr;
00683 for (idx = 0; idx<INDENT_SIZE; idx++) { indStr[idx] = '\0'; }
00684 indSz = offset;
00685 for (idx = 0; idx<indSz; idx++) { indStr[idx] = ' '; }
00686 int allocatedKnobs;
00687
00688 if (K == NULL)
00689 {
00690 K = new knobs();
00691 allocatedKnobs = 1;
00692 }
00693 else
00694 allocatedKnobs = 0;
00695
00696
00697
00698
00699 enum regionTypes rType = legoRegPtr->GetRegionType();
00700
00701
00702
00703
00704 fprintf(filPtr,"%s",indStr);
00705 if (rType == RT_PROC) {
00706 procPtr = (legoProc*)legoRegPtr;
00707 if (procPtr->GetScope() == LIR_GLOBAL) {
00708 fprintf(filPtr,"global ");
00709 }
00710 else if (procPtr->GetScope() == LIR_GNU_WEAK) {
00711 fprintf(filPtr,"gnu_weak ");
00712 }
00713 }
00714 fprintf(filPtr,"%s",RegionMap((int)rType));
00715
00716
00717
00718
00719 if (rType == RT_PROC) {
00720 procPtr = (legoProc*)legoRegPtr;
00721 fprintf(filPtr," %s",procPtr->GetProcName());
00722 }
00723
00724
00725
00726
00727 fprintf(filPtr," %d (",legoRegPtr->GetRegionId());
00728 indSz = indSz + INDENT_INC;
00729 for ( ; idx < indSz; idx++) {indStr[idx] = ' ';}
00730
00731 fprintf(filPtr,"\n%s",indStr);
00732
00733
00734
00735
00736 fprintf(filPtr,"weight(%.0f)",legoRegPtr->GetWeight());
00737 fprintf(filPtr,"\n%s",indStr);
00738
00739
00740
00741 fprintf(filPtr,"entry_ops(");
00742 if ( legoRegPtr->GetEntryOpsPtr() != NULL ) {
00743 opList *tmpoplist = legoRegPtr->GetEntryOpsPtr();
00744 while (tmpoplist != NULL)
00745 {
00746 if (tmpoplist->GetValid() == 0) break;
00747 fprintf(filPtr,"%d",(tmpoplist->GetOpPtr()->GetOpId()));
00748 tmpoplist = tmpoplist->GetNextListPtr();
00749 if (tmpoplist != NULL) { fprintf(filPtr," "); }
00750 }
00751 }
00752 fprintf(filPtr,") ");
00753
00754 fprintf(filPtr,"exit_ops(");
00755 if ( legoRegPtr->GetExitOpsPtr() != NULL ) {
00756 opList *tmpoplist = legoRegPtr->GetExitOpsPtr();
00757 while (tmpoplist != NULL)
00758 {
00759 if (tmpoplist->GetValid() == 0) break;
00760 fprintf(filPtr,"%d",(tmpoplist->GetOpPtr()->GetOpId()));
00761 tmpoplist = tmpoplist->GetNextListPtr();
00762 if (tmpoplist != NULL) { fprintf(filPtr," "); }
00763 }
00764 }
00765 fprintf(filPtr,")");
00766 fprintf(filPtr,"\n%s",indStr);
00767
00768
00769
00770
00771 fprintf(filPtr,"entry_edges(");
00772 edgeList *tmpListPtr = legoRegPtr->GetInEdgesPtr();
00773 while ( tmpListPtr != NULL ) {
00774 if ( tmpListPtr->GetValid() == 0 ) { break; }
00775 fprintf(filPtr,"ctrl ^%d",tmpListPtr->GetEdgeId());
00776 tmpListPtr = tmpListPtr->GetNextListPtr();
00777 if ( tmpListPtr != NULL ) { fprintf(filPtr," "); }
00778 }
00779 fprintf(filPtr,") ");
00780
00781
00782
00783
00784 fprintf(filPtr,"exit_edges(");
00785 tmpListPtr = legoRegPtr->GetOutEdgesPtr();
00786 while ( tmpListPtr != NULL ) {
00787 if ( tmpListPtr->GetValid() == 0 ) { break; }
00788 fprintf(filPtr,"ctrl ^%d",tmpListPtr->GetEdgeId());
00789 tmpListPtr = tmpListPtr->GetNextListPtr();
00790 if ( tmpListPtr != NULL ) { fprintf(filPtr," "); }
00791 }
00792 fprintf(filPtr,")");
00793
00794
00795
00796
00797 fprintf(filPtr,"\n%s",indStr);
00798
00799
00800
00801
00802 flags *tmpFlagPtr = legoRegPtr->GetFlagPtr();
00803
00804
00805
00806
00807 if ( tmpFlagPtr != NULL )
00808 {
00809 fprintf(filPtr,"flags(");
00810
00811 while ( tmpFlagPtr != NULL ) {
00812 if (tmpFlagPtr->GetFlagName() == 0)
00813 break;
00814 fprintf(filPtr,"%s",ParseMap(tmpFlagPtr->GetFlagName()));
00815 tmpFlagPtr = tmpFlagPtr->GetNextFlagPtr();
00816 if ( tmpFlagPtr != NULL ) { fprintf(filPtr," "); }
00817 }
00818 fprintf(filPtr,")");
00819 }
00820
00821
00822
00823
00824 fprintf(filPtr,"\n%s",indStr);
00825
00826
00827
00828
00829 fprintf(filPtr,"attr(");
00830 attrList *wrtRegAttrListPtr = legoRegPtr->GetRegionAttrListPtr();
00831 if (wrtRegAttrListPtr == NULL) { }
00832 else {
00833 int tmpAttrId = (legoRegPtr->GetRegionAttrListPtr())->GetAttrId();
00834 if ( tmpAttrId != 0 ) {
00835 fprintf(filPtr,"lc ^%d", tmpAttrId);
00836 }
00837 }
00838 fprintf(filPtr,")");
00839
00840
00841
00842
00843 fprintf(filPtr,"\n%s",indStr);
00844
00845
00846
00847
00848 fprintf(filPtr,"subregions(");
00849
00850
00851
00852
00853
00854 fprintf(filPtr,"\n");
00855
00856
00857
00858
00859 int itemCount = legoRegPtr->GetCount();
00860
00861
00862
00863
00864
00865
00866 if (IS_BLOCK(rType) && itemCount > 0)
00867 WriteOps ((legoOp *)legoRegPtr->GetItem(0), 0,
00868 filPtr, indSz+INDENT_INC);
00869 else
00870 {
00871 for (idx=0; idx<itemCount; idx++) {
00872 if ( (rType == RT_PROC) ||
00873 (rType == RT_LOOPBODY) ||
00874 (rType == RT_LOOP) ||
00875 (rType == RT_TREE) ||
00876 (rType == RT_TRACE) ) {
00877 LegoWrite((legoRegion*)legoRegPtr->GetItem(idx),filPtr,
00878 indSz+INDENT_INC);
00879 }
00880 else {
00881
00882
00883 LegoNonFatal ("LegoWrite", "Don't know how to write region "
00884 " of type %d.\n", rType);
00885 }
00886 }
00887 }
00888
00889
00890
00891
00892 fprintf(filPtr,"%s",indStr);
00893
00894
00895
00896
00897 indSz = indSz - INDENT_INC;
00898 indStr[indSz] = '\0';
00899
00900 fprintf(filPtr,")\n%s",indStr);
00901
00902
00903
00904
00905
00906 fprintf(filPtr,")\n");
00907
00908
00909
00910
00911 if (allocatedKnobs)
00912 {
00913 delete K; K = NULL;
00914 }
00915
00916 return 1;
00917 }
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927 int LegoWrite (legoModule* legoModPtr, char *rblOutFile=NULL )
00928 {
00929 FILE *filPtr = NULL;
00930 legoRegion *legoRegPtr;
00931 legoRegion *modRegPtr;
00932 int idx;
00933 vector<char *> *modComments;
00934 vector<char *>::iterator comi;
00935 char *cmdString;
00936 char usegzip;
00937
00938
00939
00940
00941 usegzip = TRUE;
00942
00943
00944
00945 if ( rblOutFile == NULL ) { filPtr = stdout; }
00946
00947 if (!filPtr)
00948 {
00949 if (usegzip) {
00950
00951 if ((cmdString = (char *)calloc(strlen(rblOutFile)+strlen(COMPRESS_CMD)
00952 +8,sizeof(char)))!=NULL)
00953 {
00954 sprintf(cmdString,"%s > %s",COMPRESS_CMD,rblOutFile);
00955 filPtr = popen(cmdString, "w");
00956 free(cmdString);
00957 }
00958 else
00959 {
00960 rblOutFile = NULL;
00961 }
00962 }
00963 else {
00964
00965 filPtr = fopen(rblOutFile, "w");
00966 }
00967 }
00968 if (!filPtr) {
00969 LegoNonFatal ("LegoWrite", "Output file open failed - writing "
00970 "to stderr.");
00971 filPtr = stderr;
00972 }
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989 modComments = legoModPtr->GetComments();
00990 for (comi = modComments->begin(); comi != modComments->end(); comi++)
00991
00992
00993 fprintf (filPtr, "SMODCMT %s EMODCMT\n", *comi);
00994 fprintf (filPtr, "\n");
00995
00996
00997
00998 modRegPtr = legoModPtr;
00999 WriteData((legoModule*)modRegPtr, filPtr);
01000 int itemCount = modRegPtr->GetCount();
01001 for (idx=0; idx<itemCount; idx++) {
01002 LegoWrite((legoRegion*)modRegPtr->GetItem(idx),filPtr,0);
01003
01004
01005
01006
01007
01008
01009
01010
01011 WriteEdges((legoProc*)modRegPtr->GetItem(idx), filPtr);
01012
01013
01014
01015
01016 WriteAttrs((legoProc*)modRegPtr->GetItem(idx), filPtr);
01017
01018
01019
01020
01021 WriteMem((legoProc*)modRegPtr->GetItem(idx), filPtr);
01022
01023
01024
01025
01026 WriteJump((legoProc*)modRegPtr->GetItem(idx), filPtr);
01027 }
01028
01029 if (usegzip) {
01030 if (rblOutFile != NULL) pclose (filPtr);
01031 }
01032 else {
01033 if (rblOutFile != NULL) fclose (filPtr);
01034 }
01035
01036 return 1;
01037 }
01038