|
OpenADFortTk (basic)
|
00001 #include <cstdlib> 00002 00003 #include "Args.h" 00004 00005 //*************************** Forward Declarations ************************** 00006 00007 using std::cerr; 00008 using std::endl; 00009 using std::string; 00010 00011 //*************************************************************************** 00012 00013 static const char* usage_summary = 00014 "[options] <whirl-file>\n"; 00015 00016 static const char* usage_details = 00017 "Given a WHIRL file, translates the 'numerical core' into XAIF. By default,\n" 00018 "output is sent to stdout.\n" 00019 "\n" 00020 "Options:\n" 00021 " -h, --help print this help and exit\n" 00022 " -n, --noFilter do not filter ud/du chains by current basic block\n" 00023 " -N, --noTimeStamp do not print a time stamp into the output\n" 00024 " -o, --output <file> send output to <file> instead of stdout\n" 00025 " --prefix <pfx> Set the temporary variable prefix to <pfx>. Default\n" 00026 " is 'OpenAD_'\n" 00027 " -s, --simpleLoop force simple loop property on all loop constructs\n" 00028 " -v, --variedOnly do not require active data to also be 'useful'\n" 00029 " --uniformCBact if any variable in a given common block is active\n" 00030 " then activate all of them\n" 00031 " --allActive all floating point variables are made active\n" 00032 " --debug [lvl] debug mode at level `lvl'\n"; 00033 00034 bool Args::ourSimpleLoopFlag=false; // default: done't force it 00035 bool Args::ourDoNotFilterFlag=false; // default: filter it 00036 bool Args::ourNoTimeStampFlag=false; // default: dump a time stamp 00037 bool Args::ourVariedOnlyFlag=false; // default: require both usefull and varied 00038 bool Args::ourUniformCBactFlag=false; // default: no uniform activation 00039 bool Args::ourAllActiveFlag=false; // default: no global activation 00040 00041 #define CLP CmdLineParser 00042 00043 CmdLineParser::OptArgDesc Args::optArgs[] = { 00044 // Options 00045 { 'o', "output", CLP::ARG_REQ , CLP::DUPOPT_ERR, NULL }, 00046 { 0 , "prefix", CLP::ARG_OPT, CLP::DUPOPT_CLOB, NULL }, 00047 { 'v', "variedOnly", CLP::ARG_NONE, CLP::DUPOPT_CLOB, NULL }, 00048 { 'h', "help", CLP::ARG_NONE, CLP::DUPOPT_CLOB, NULL }, 00049 { 's', "simpleLoop", CLP::ARG_NONE, CLP::DUPOPT_ERR, NULL }, 00050 { 'n', "noFilter", CLP::ARG_NONE, CLP::DUPOPT_ERR, NULL }, 00051 { 'N', "noTimeStamp", CLP::ARG_NONE, CLP::DUPOPT_ERR, NULL }, 00052 { 0 , "uniformCBact",CLP::ARG_NONE, CLP::DUPOPT_ERR, NULL }, 00053 { 0 , "allActive", CLP::ARG_NONE, CLP::DUPOPT_ERR, NULL }, 00054 { 0 , "debug", CLP::ARG_OPT, CLP::DUPOPT_CLOB, NULL }, 00055 CmdLineParser::OptArgDesc_NULL 00056 }; 00057 00058 #undef CLP 00059 00060 //*************************************************************************** 00061 // Args 00062 //*************************************************************************** 00063 00064 Args::Args() 00065 { 00066 Ctor(); 00067 } 00068 00069 Args::Args(int argc, const char* const argv[]) 00070 { 00071 Ctor(); 00072 Parse(argc, argv); 00073 } 00074 00075 00076 void 00077 Args::Ctor() 00078 { 00079 ourVariedOnlyFlag=false; 00080 tmpVarPrefix = "OpenAD_"; // default prefix 00081 debug = 0; // default: 0 (off) 00082 } 00083 00084 Args::~Args() 00085 { 00086 } 00087 00088 void 00089 Args::PrintUsage(std::ostream& os) const 00090 { 00091 os << "Usage: " << GetCmd() << " " << usage_summary << endl 00092 << usage_details << endl; 00093 } 00094 00095 void 00096 Args::PrintError(std::ostream& os, const char* msg) const 00097 { 00098 os << GetCmd() << ": " << msg << endl 00099 << "Try `" << GetCmd() << " --help' for more information." << endl; 00100 } 00101 00102 void 00103 Args::PrintError(std::ostream& os, const std::string& msg) const 00104 { 00105 PrintError(os, msg.c_str()); 00106 } 00107 00108 00109 void 00110 Args::Parse(int argc, const char* const argv[]) 00111 { 00112 try { 00113 // ------------------------------------------------------- 00114 // Parse the command line 00115 // ------------------------------------------------------- 00116 parser.Parse(optArgs, argc, argv); 00117 00118 // ------------------------------------------------------- 00119 // Sift through results, checking for semantic errors 00120 // ------------------------------------------------------- 00121 00122 // Special options that should be checked first 00123 if (parser.IsOpt("debug")) { 00124 debug = 1; 00125 if (parser.IsOptArg("debug")) { 00126 const string& arg = parser.GetOptArg("debug"); 00127 debug = (int)CmdLineParser::ToLong(arg); 00128 } 00129 } 00130 if (parser.IsOpt("help")) { 00131 PrintUsage(std::cerr); 00132 exit(0); 00133 } 00134 if (parser.IsOpt("variedOnly")) { 00135 ourVariedOnlyFlag=true; 00136 } 00137 if (parser.IsOpt("output")) { 00138 xaifFileNm = parser.GetOptArg("output"); 00139 } 00140 if (parser.IsOpt("prefix")) { 00141 tmpVarPrefix = parser.GetOptArg("prefix"); 00142 } 00143 if (parser.IsOpt("simpleLoop")) { 00144 ourSimpleLoopFlag = true; 00145 } 00146 if (parser.IsOpt("noFilter")) { 00147 ourDoNotFilterFlag = true; 00148 } 00149 if (parser.IsOpt("noTimeStamp")) { 00150 ourNoTimeStampFlag= true; 00151 } 00152 if (parser.IsOpt("uniformCBact")) { 00153 ourUniformCBactFlag = true; 00154 } 00155 if (parser.IsOpt("allActive")) { 00156 ourAllActiveFlag = true; 00157 } 00158 // Check for required arguments 00159 if (parser.GetNumArgs() != 1) { 00160 PrintError(std::cerr, "Invalid number of arguments!"); 00161 exit(1); 00162 } 00163 whirlFileNm = parser.GetArg(0); 00164 } 00165 catch (CmdLineParser::ParseError& e) { 00166 PrintError(std::cerr, e.GetMessage()); 00167 exit(1); 00168 } 00169 } 00170 00171 00172 void 00173 Args::Dump(std::ostream& os) const 00174 { 00175 parser.Dump(os); 00176 } 00177 00178 void 00179 Args::DDump() const 00180 { 00181 Dump(std::cerr); 00182 } 00183