X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCBBlock.c;h=15470f19ac039f8081e05f7f3fd48a4e418ee25b;hb=aa524159f55edf43a88eb60ebe01ef50d3dd4283;hp=1fb1097b0fc36dcee7d174a48761303519bfbff8;hpb=573903c17677d00eaa7e5fbfbde9a22d41e2aeea;p=fw%2Fsdcc diff --git a/src/SDCCBBlock.c b/src/SDCCBBlock.c index 1fb1097b..15470f19 100644 --- a/src/SDCCBBlock.c +++ b/src/SDCCBBlock.c @@ -29,6 +29,23 @@ int eBBNum = 0; set *graphEdges = NULL; /* list of edges in this flow graph */ +struct _dumpFiles dumpFiles[] = { + {DUMP_RAW0, ".dumpraw0", NULL}, + {DUMP_RAW1, ".dumpraw1", NULL}, + {DUMP_CSE, ".dumpcse", NULL}, + {DUMP_DFLOW, ".dumpdflow", NULL}, + {DUMP_GCSE, ".dumpgcse", NULL}, + {DUMP_DEADCODE, ".dumpdeadcode", NULL}, + {DUMP_LOOP, ".dumploop", NULL}, + {DUMP_LOOPG, ".dumploopg", NULL}, + {DUMP_LOOPD, ".dumploopd", NULL}, + {DUMP_RANGE, ".dumprange", NULL}, + {DUMP_PACK, ".dumppack", NULL}, + {DUMP_RASSGN, ".dumprassgn", NULL}, + {DUMP_LRANGE, ".dumplrange", NULL}, + {0, NULL, NULL} +}; + /*-----------------------------------------------------------------*/ /* printEntryLabel - prints entry label of a ebblock */ /*-----------------------------------------------------------------*/ @@ -67,30 +84,64 @@ newEdge (eBBlock * from, eBBlock * to) return ep; } +/*-----------------------------------------------------------------*/ +/* appendDumpFile - if not already created, create the dump file */ +/*-----------------------------------------------------------------*/ +FILE *appendDumpFile (int id) { + struct _dumpFiles *dumpFilesPtr=dumpFiles; + + while (dumpFilesPtr->id) { + if (dumpFilesPtr->id==id) + break; + dumpFilesPtr++; + } + + if (!dumpFilesPtr->id) { + fprintf (stdout, "internal error: appendDumpFile: unknown dump file.\n"); + exit (1); + } + + if (!dumpFilesPtr->filePtr) { + // not used before, create it + strcpy (scratchFileName, srcFileName); + strcat (scratchFileName, dumpFilesPtr->ext); + if (!(dumpFilesPtr->filePtr = fopen (scratchFileName, "w"))) { + werror (E_FILE_OPEN_ERR, scratchFileName); + exit (1); + } + } + return dumpFilesPtr->filePtr; +} + +/*-----------------------------------------------------------------*/ +/* closeDumpFiles - close possible opened dumpfiles */ +/*-----------------------------------------------------------------*/ +void closeDumpFiles() { + struct _dumpFiles *dumpFilesPtr; + + for (dumpFilesPtr=dumpFiles; dumpFilesPtr->id; dumpFilesPtr++) { + if (dumpFilesPtr->filePtr) { + fclose (dumpFilesPtr->filePtr); + //dprintf ("closed %s\n", dumpFilesPtr->ext); + } + } +} + /*-----------------------------------------------------------------*/ /* dumpLiveRanges - dump liverange information into a file */ /*-----------------------------------------------------------------*/ void -dumpLiveRanges (char *ext, hTab * liveRanges) +dumpLiveRanges (int id, hTab * liveRanges) { FILE *file; symbol *sym; int k; - if (ext) - { - /* create the file name */ - strcpy (buffer, srcFileName); - strcat (buffer, ext); - - if (!(file = fopen (buffer, "a+"))) - { - werror (E_FILE_OPEN_ERR, buffer); - exit (1); - } - } - else + if (id) { + file=appendDumpFile(id); + } else { file = stdout; + } for (sym = hTabFirstItem (liveRanges, &k); sym; sym = hTabNextItem (liveRanges, &k)) @@ -139,31 +190,23 @@ dumpLiveRanges (char *ext, hTab * liveRanges) fprintf (file, "\n"); } - fclose (file); + fflush(file); } + /*-----------------------------------------------------------------*/ /* dumpEbbsToFileExt - writeall the basic blocks to a file */ /*-----------------------------------------------------------------*/ void -dumpEbbsToFileExt (char *ext, eBBlock ** ebbs, int count) +dumpEbbsToFileExt (int id, eBBlock ** ebbs, int count) { FILE *of; int i; - if (ext) - { - /* create the file name */ - strcpy (buffer, srcFileName); - strcat (buffer, ext); - - if (!(of = fopen (buffer, "w"))) - { - werror (E_FILE_OPEN_ERR, buffer); - exit (1); - } - } - else + if (id) { + of=appendDumpFile(id); + } else { of = stdout; + } for (i = 0; i < count; i++) { @@ -182,7 +225,7 @@ dumpEbbsToFileExt (char *ext, eBBlock ** ebbs, int count) fprintf (of, "\n----------------------------------------------------------------\n"); printiCChain (ebbs[i]->sch, of); } - fclose (of); + fflush(of); } /*-----------------------------------------------------------------*/