Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

/users/u3/mtikir/PMaCInstrumentor_v1601/tools/main.C

Go to the documentation of this file.
00001 #include <XCoffFile.h>
00002 
00003 #include <IdenticalInstrumentor.h>
00004 #include <BasicBlockCounter.h>
00005 #include <CacheSimulator.h>
00006 #include <BasicBlockTracer.h>
00007 #include <CountAllBlocks.h>
00008 #include <DataExtender.h>
00009 
00010 void printBriefOptions(){
00011     fprintf(stderr,"\n");
00012     fprintf(stderr,"Brief Descriptions for Options:\n");
00013     fprintf(stderr,"===============================\n");
00014         fprintf(stderr,"\t--typ : required for all.\n");
00015         fprintf(stderr,"\t--app : required for all.\n");
00016         fprintf(stderr,"\t--lib : optional for all. shared library top directory.\n");
00017         fprintf(stderr,"\t        default is $PMACINST_LIB_HOME\n");
00018         fprintf(stderr,"\t--ext : optional for all. default is (typ)inst, such as\n");
00019         fprintf(stderr,"\t        jbbinst for type jbb.\n");
00020     fprintf(stderr,"\t--dtl : optional for all. detailed .static file with lineno\n");
00021         fprintf(stderr,"\t        and filenames. default is no details.\n");
00022         fprintf(stderr,"\t--inp : required for sim/csc.\n");
00023         fprintf(stderr,"\t--lpi : optional for sim/csc. loop level block inclusion for\n");
00024         fprintf(stderr,"\t        cache simulation. default is no.\n");
00025         fprintf(stderr,"\t--phs : optional for sim/csc. phase number. defaults to no phase,\n"); 
00026         fprintf(stderr,"\t        otherwise, .phase.N. is included in output file names\n");
00027     fprintf(stderr,"\n");
00028 }
00029 
00030 void printUsage(char* argv[],bool shouldExt=false) {
00031     fprintf(stderr,"\n");
00032     fprintf(stderr,"usage : %s\n",argv[0]);
00033         fprintf(stderr,"\t--typ (ide|dat|bbt|cnt|jbb|sim|csc)\n");
00034         fprintf(stderr,"\t--app <executable_path>\n");
00035         fprintf(stderr,"\t--inp <block_unique_ids>    <-- valid for sim/csc\n");
00036         fprintf(stderr,"\t[--lib <shared_lib_topdir>]\n");
00037         fprintf(stderr,"\t[--ext <output_suffix>]\n");
00038     fprintf(stderr,"\t[--dtl]\n");
00039         fprintf(stderr,"\t[--lpi]                     <-- valid for sim/csc\n");
00040         fprintf(stderr,"\t[--phs <phase_no>]          <-- valid for sim/csc\n");
00041         fprintf(stderr,"\t[--help]\n");
00042     fprintf(stderr,"\n");
00043         if(shouldExt){
00044                 printBriefOptions();
00045         }
00046     exit(-1);
00047 }
00048 
00049 typedef enum {
00050     unknown_inst_type = 0,
00051     identical_inst_type,
00052     frequency_inst_type,
00053     simulation_inst_type,
00054     simucntr_inst_type,
00055     bbtrace_inst_type,
00056     countblocks_inst_type,
00057     data_extender_type,
00058     Total_InstrumentationType
00059 } InstrumentationType;
00060 
00061 
00062 int main(int argc,char* argv[]){
00063 
00064     char*    execName  = NULL;
00065     char*    inptName  = NULL;
00066     char*    extension = "";
00067     char*    libPath   = NULL;
00068     int32_t  phaseNo   = 0;
00069     uint32_t instType  = unknown_inst_type;
00070     uint32_t argApp    = 0;
00071     uint32_t argTyp    = 0;
00072     uint32_t argExt    = 0;
00073     uint32_t argPhs    = 0;
00074     uint32_t argInp    = 0;
00075     bool     loopIncl  = false;
00076     bool     extdPrnt  = false;
00077 
00078     TIMER(double t = timer());
00079     for (int32_t i = 1; i < argc; i++){
00080         if (!strcmp(argv[i],"--app")){
00081             if(argApp++){
00082                 fprintf(stderr,"\nError : Duplicate %s option\n",argv[i]);
00083                 printUsage(argv);
00084             }
00085             execName = argv[++i];
00086         } else if(!strcmp(argv[i],"--typ")){
00087             if (argTyp++){
00088                 fprintf(stderr,"\nError : Duplicate %s option\n",argv[i]);
00089                 printUsage(argv);
00090             }
00091             ++i;
00092             if (!strcmp(argv[i],"ide")){
00093                 instType = identical_inst_type;
00094                 extension = "ideinst";
00095             } else if (!strcmp(argv[i],"dat")){
00096                 instType = data_extender_type;
00097                 extension = "datinst";
00098             } else if (!strcmp(argv[i],"jbb")){
00099                 instType = frequency_inst_type;
00100                 extension = "jbbinst";
00101             } else if (!strcmp(argv[i],"sim")){
00102                 instType = simulation_inst_type;
00103                 extension = "siminst";
00104             } else if (!strcmp(argv[i],"csc")){
00105                 instType = simucntr_inst_type;
00106                 extension = "cscinst";
00107             } else if (!strcmp(argv[i],"bbt")){
00108                 instType = bbtrace_inst_type;
00109                 extension = "bbtinst";
00110             } else if (!strcmp(argv[i],"cnt")){
00111                 instType = countblocks_inst_type;
00112                 extension = "cntinst";
00113             }
00114         } else if(!strcmp(argv[i],"--help")){
00115                         printUsage(argv,true);
00116                 }
00117     }
00118 
00119     if (!execName){
00120         fprintf(stderr,"\nError : No executable is specified\n\n");
00121         printUsage(argv);
00122     }
00123 
00124     if ((instType <= unknown_inst_type) || 
00125        (instType >= Total_InstrumentationType)){
00126         fprintf(stderr,"\nError : Unknown instrumentation type\n");
00127         printUsage(argv);
00128     }
00129 
00130     for (int32_t i = 1; i < argc; i++){
00131         if (!strcmp(argv[i],"--app") || !strcmp(argv[i],"--typ")){
00132             ++i;
00133         } else if (!strcmp(argv[i],"--ext")){
00134             if (argExt++){
00135                 fprintf(stderr,"\nError : Duplicate %s option\n",argv[i]);
00136                 printUsage(argv);
00137             }
00138             extension = argv[++i];
00139         } else if(!strcmp(argv[i],"--phs")){
00140             if (argPhs++){
00141                 fprintf(stderr,"\nError : Duplicate %s option\n",argv[i]);
00142                 printUsage(argv);
00143             }
00144             if ((instType != simulation_inst_type) && (instType != simucntr_inst_type)){
00145                 fprintf(stderr,"\nError : Option %s is not valid other than simulation\n",argv[i]);
00146                 printUsage(argv);
00147             }
00148 
00149             ++i;
00150             char* endptr = NULL;
00151             phaseNo = strtol(argv[i],&endptr,10);
00152             if ((endptr == argv[i]) || !phaseNo){
00153                 fprintf(stderr,"\nError : Given phase number is not correct, requires > 0\n\n");
00154                 printUsage(argv);
00155             }
00156 
00157         } else if (!strcmp(argv[i],"--inp")){
00158             if (argInp++){
00159                 fprintf(stderr,"\nError : Duplicate %s option\n",argv[i]);
00160                 printUsage(argv);
00161             }
00162             if ((instType != simulation_inst_type) && (instType != simucntr_inst_type)){
00163                 fprintf(stderr,"\nError : Option %s is not valid other than simulation\n",argv[i]);
00164                 printUsage(argv);
00165             }
00166 
00167             inptName = argv[++i];
00168         } else if (!strcmp(argv[i],"--lpi")){
00169             loopIncl = true;
00170             if ((instType != simulation_inst_type) && (instType != simucntr_inst_type)){
00171                 fprintf(stderr,"\nError : Option %s is not valid other than simulation\n",argv[i++]);
00172                 printUsage(argv);
00173             }
00174         } else if (!strcmp(argv[i],"--dtl")){
00175             extdPrnt = true;
00176         } else if (!strcmp(argv[i],"--lib")){
00177             libPath = argv[++i];
00178         } else {
00179             fprintf(stderr,"\nError : Unknown switch at %s\n\n",argv[i]);
00180             printUsage(argv);
00181         }
00182     }
00183 
00184     if (((instType == simulation_inst_type) || 
00185          (instType == simucntr_inst_type)) && !inptName){
00186         fprintf(stderr,"\nError : Input is required for cache simulation instrumentation\n\n");
00187         printUsage(argv);
00188     }
00189 
00190     ASSERT((instType == simulation_inst_type) || (instType == simucntr_inst_type) || (phaseNo == 0));
00191 
00192     if (sizeof(PowerPCInstruction) != 4){
00193         PRINT_ERROR("Size of instruction has to be 4 bytes");
00194     }
00195 
00196     if (sizeof(HashCode) != 8){
00197         PRINT_ERROR("Development error; The size of hashCode has to be 8 bytes");
00198     }
00199 
00200     if(!libPath){
00201         libPath = getenv("PMACINST_LIB_HOME");
00202         if (!libPath){
00203             PRINT_ERROR("Error : use --lib option or define set the MACINST_LIB_HOME variable"); 
00204         }
00205     }
00206     PRINT_INFOR("The instrumentation libraries will be used from %s",libPath);
00207 
00208     TIMER(double t1 = timer());
00209 
00210     PRINT_INFOR("******** Instrumentation Beginning ********");
00211     XCoffFile xcoffFile(execName);
00212 
00213     xcoffFile.parse();
00214     xcoffFile.briefPrint();
00215 
00216     TIMER(double t2 = timer();PRINT_INFOR("___timer: Instrumentation Step I parse  : %.2f",t2-t1);t1=t2);
00217 
00218     DEBUG_MORE(
00219         xcoffFile.displaySymbols();
00220         xcoffFile.print();
00221     );
00222 
00223     if(extdPrnt){
00224         xcoffFile.setLineInfoFinder();
00225     }
00226 
00227     TIMER(t2 = timer();PRINT_INFOR("___timer: Instrumentation Step II Line  : %.2f",t2-t1);t1=t2);
00228 
00229     DEBUG(xcoffFile.testBitSet(););
00230     if(extdPrnt){
00231         xcoffFile.findLoops();
00232     }
00233 
00234     TIMER(t2 = timer();PRINT_INFOR("___timer: Instrumentation Step III Loop : %.2f",t2-t1);t1=t2);
00235 
00236     XCoffFileGen* xcoffFileGen = NULL;
00237     if (instType == identical_inst_type){
00238 
00239         xcoffFileGen = new IdenticalInstrumentor(&xcoffFile,extension);
00240 
00241     } else if (instType == data_extender_type){
00242 
00243         xcoffFileGen = new DataExtender(&xcoffFile,extension);
00244 
00245     } else if (instType == frequency_inst_type){
00246 
00247         xcoffFileGen = new BasicBlockCounter(&xcoffFile,extension,(uint32_t)phaseNo);
00248 
00249     } else if (instType == bbtrace_inst_type){
00250 
00251         xcoffFileGen = new BasicBlockTracer(&xcoffFile,extension,(uint32_t)phaseNo);
00252 
00253     } else if (instType == countblocks_inst_type){
00254 
00255         xcoffFileGen = new CountAllBlocks(&xcoffFile,extension,(uint32_t)phaseNo);
00256 
00257     } else if (instType == simulation_inst_type){
00258 
00259         xcoffFileGen = new CacheSimulator(&xcoffFile,extension,(uint32_t)phaseNo,inptName,false,loopIncl);
00260 
00261     } else if (instType == simucntr_inst_type){
00262 
00263         xcoffFileGen = new CacheSimulator(&xcoffFile,extension,(uint32_t)phaseNo,inptName,true,loopIncl);
00264 
00265     } else {
00266         PRINT_ERROR("Error : unknown instrumentation type, so quiting");
00267     }
00268 
00269     if((instType == frequency_inst_type) ||
00270        (instType == simulation_inst_type) ||
00271        (instType == simucntr_inst_type)){
00272         ((CommonMethods*)xcoffFileGen)->setExtendedPrint(extdPrnt);
00273     }
00274 
00275     xcoffFileGen->setPathToInstLib(libPath);
00276 
00277     PRINT_INFOR("******** Function  Count  %d          ********",xcoffFileGen->getNumberOfAllFunctions());
00278     PRINT_INFOR("******** Basic Block Cou  %d          ********",xcoffFileGen->getNumberOfAllBlocks());
00279     PRINT_INFOR("******** Memory Op Count  %d          ********",xcoffFileGen->getNumberOfAllMemoryOps());
00280     PRINT_INFOR("******** FloatP Op Count  %d          ********",xcoffFileGen->getNumberOfAllFloatPOps());
00281     PRINT_INFOR("******** Instrument Point %d          ********",xcoffFileGen->getNumberOfInstPoints(NULL));
00282 
00283     xcoffFileGen->instrument();
00284 
00285     TIMER(t2 = timer();PRINT_INFOR("___timer: Instrumentation Step IV Instr : %.2f",t2-t1);t1=t2);
00286 
00287     PRINT_INFOR("******** Original File Si %d          ********",xcoffFile.getFileSize());
00288     PRINT_INFOR("******** Instrumented Siz %d          ********",xcoffFileGen->getInstrumentedFileSize());
00289 
00290     uint32_t written = xcoffFileGen->dump();
00291     PRINT_INFOR("******** Output File Siz  %d          ********",written);
00292 
00293     TIMER(t2 = timer();PRINT_INFOR("___timer: Instrumentation Step V Dump   : %.2f",t2-t1);t1=t2);
00294 
00295     xcoffFileGen->verify(written);
00296 
00297     PRINT_INFOR("******** Instrumentation Successfull ********");
00298 
00299     TIMER(t = timer()-t;PRINT_INFOR("___timer: Total Execution Time          : %.2f",t););
00300 
00301     PRINT_INFOR("\n");
00302     PRINT_INFOR("******** DONE ******** SUCCESS ***** SUCCESS ***** SUCCESS ********\n");
00303     return 0;
00304 }

Generated on Mon Jan 28 11:08:33 2008 for PMaCInstrumentor by doxygen 1.3.5