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
00038 #include <stdio.h>
00039 #include <string.h>
00040 #include <signal.h>
00041 #include <stdlib.h>
00042
00043 #include "workaround.h"
00044 #include "dipa_errors.h"
00045 #include "resource.h"
00046 #include "timing.h"
00047 #include "tracing.h"
00048 #include "resource.h"
00049 #include "messg.h"
00050 #include "dipa_phase.h"
00051 #include "dipa_phase_ctrl.h"
00052 #include "dipa_args.h"
00053
00054 DIPA_Phase::DIPA_Phase(const char *_name)
00055 {
00056 phase_name = _name;
00057 phase_id = INVALID_PHASE_ID;
00058 phase_stat = NULL;
00059 rolist = NULL;
00060 enabled = false;
00061
00062 arg_list.clear();
00063 }
00064
00065
00066
00067
00068
00069
00070 void DIPA_Phase::Add_Arg(char *arg)
00071 {
00072 char *p=arg;
00073 CMD_ARG pair1;
00074
00075 pair1.first = arg;
00076 pair1.second = NULL;
00077 p = strchr(arg, '%');
00078
00079 if (p) {
00080 *p='\0';
00081 p++;
00082 if (*p) {
00083 pair1.second = p;
00084 p = strchr(p, '%');
00085 FmtAssert((p!=NULL), ("Invalid option %s\n", arg));
00086 *p = '\0';
00087 }
00088 }
00089 arg_list.push_back(pair1);
00090 DEV_TRACE("Phase %s - added an arg:%s %s\n", Get_Name(), pair1.first, pair1.second);
00091 }
00092
00093
00094
00095
00096 void DIPA_Phase::Proc_Arg(CMD_ARGS *args, DIPA_Olist *olist)
00097 {
00098
00099 if (args && !args->empty()) {
00100 CMD_ARGS_Iter it;
00101 for (it = args->begin(); it != args->end(); it++) {
00102 fprintf(stdout, "Global args: %s %s\n", (*it).first, (*it).second?(*it).second:"(no value)");
00103 }
00104 }
00105
00106
00107 if (olist && !olist->empty()) {
00108 DIPA_Olist_Iter iter;
00109 for (iter = olist->begin(); iter != olist->end(); iter++) {
00110 fprintf(stdout, "DIPA objects: %s\n", (*iter)->Get_Rfile());
00111 }
00112 }
00113
00114
00115 if (!arg_list.empty()) {
00116 CMD_ARGS_Iter it;
00117 for (it = arg_list.begin(); it != arg_list.end(); it++) {
00118 fprintf(stdout, "Local args: %s %s\n", (*it).first, (*it).second?(*it).second:"(no value)");
00119 }
00120 }
00121 }
00122
00123 BOOL DIPA_Phase::Start(CMD_ARGS *args, DIPA_Olist *olist)
00124 {
00125 printf("Entering phase %s\n", Get_Name());
00126 Pre_Dump_IR();
00127
00128 Post_Dump_IR();
00129
00130 return true;
00131 }
00132
00133 void DIPA_Phase::Pre_Dump_IR(FILE *file)
00134 {
00135 if (!Is_Tracing_Enabled()) return;
00136
00137 FILE *f = (file)?file:stdout;
00138 fprintf(f, "--Start Dump before phase %s\n", Get_Name());
00139
00140 fprintf(f, "--End Dump before phase %s\n", Get_Name());
00141 }
00142
00143 void DIPA_Phase::Post_Dump_IR(FILE *file)
00144 {
00145 if (!Is_Tracing_Enabled()) return;
00146
00147 FILE *f = (file)?file:stdout;
00148 fprintf(f, "--Start Dump after phase %s\n", Get_Name());
00149
00150 fprintf(f, "--End Dump after phase %s\n", Get_Name());
00151 }
00152
00153 void DIPA_Phase::Accum_Stats(void)
00154 {
00155 Accum_Stats(this);
00156 }
00157
00158 void DIPA_Phase::Accum_Stats(DIPA_Phase *ph)
00159 {
00160 Phase_List *phList;
00161
00162 phList = ph->Get_Childs();
00163 if (!phList->empty()) {
00164 Phase_Iter it;
00165
00166 for (it=phList->begin(); it!=phList->end(); it++) {
00167 Accum_Stats(*it);
00168 }
00169 } else {
00170
00171 Add_Timer_To_Parent(Get_Id());
00172 }
00173 }
00174
00175 void DIPA_Phase::Dump_Stats(FILE *file)
00176 {
00177 if (!file) file = stdout;
00178
00179 fprintf(file, "Phase statistics - %s\n", Get_Name());
00180 Resource_Report(file, RR_Report_Delta, Timer(Get_Id()), NULL);
00181 }
00182
00183 void DIPA_Phase::Help(void)
00184 {
00185 fprintf(stderr, "Special help for phase %s:\n", Get_Name());
00186 fprintf(stderr, "\tOverride this function to provide special help messages!\n", Get_Name());
00187 exit(0);
00188 }