OpenADFortTk (basic)
src/whirl2xaif/Args.cxx
Go to the documentation of this file.
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 "      --debug [lvl]   debug mode at level `lvl'\n";
00032 
00033 bool Args::ourSimpleLoopFlag=false;   // default: done't force it
00034 bool Args::ourDoNotFilterFlag=false;  // default: filter it
00035 bool Args::ourNoTimeStampFlag=false;  // default: dump a time stamp
00036 bool Args::ourVariedOnlyFlag=false;   // default: require both usefull and varied
00037 bool Args::ourUniformCBactFlag=false; // default: no uniform activation
00038 
00039 #define CLP CmdLineParser
00040 
00041 CmdLineParser::OptArgDesc Args::optArgs[] = {
00042   // Options
00043   { 'o', "output",      CLP::ARG_REQ , CLP::DUPOPT_ERR,  NULL },
00044   {  0 , "prefix",      CLP::ARG_OPT,  CLP::DUPOPT_CLOB, NULL },
00045   { 'v', "variedOnly",  CLP::ARG_NONE, CLP::DUPOPT_CLOB, NULL },
00046   { 'h', "help",        CLP::ARG_NONE, CLP::DUPOPT_CLOB, NULL },
00047   { 's', "simpleLoop",  CLP::ARG_NONE, CLP::DUPOPT_ERR,  NULL },
00048   { 'n', "noFilter",    CLP::ARG_NONE, CLP::DUPOPT_ERR,  NULL },
00049   { 'N', "noTimeStamp", CLP::ARG_NONE, CLP::DUPOPT_ERR,  NULL },
00050   {  0 , "uniformCBact",CLP::ARG_NONE, CLP::DUPOPT_ERR,  NULL },
00051   {  0 , "debug",       CLP::ARG_OPT,  CLP::DUPOPT_CLOB, NULL },
00052   CmdLineParser::OptArgDesc_NULL
00053 };
00054 
00055 #undef CLP
00056 
00057 //***************************************************************************
00058 // Args
00059 //***************************************************************************
00060 
00061 Args::Args()
00062 {
00063   Ctor();
00064 }
00065 
00066 Args::Args(int argc, const char* const argv[])
00067 {
00068   Ctor();
00069   Parse(argc, argv);
00070 }
00071 
00072 
00073 void
00074 Args::Ctor()
00075 {
00076   ourVariedOnlyFlag=false;
00077   tmpVarPrefix = "OpenAD_"; // default prefix
00078   debug = 0;                // default: 0 (off)
00079 }
00080 
00081 Args::~Args()
00082 {
00083 }
00084 
00085 void 
00086 Args::PrintUsage(std::ostream& os) const
00087 {
00088   os << "Usage: " << GetCmd() << " " << usage_summary << endl
00089      << usage_details << endl;
00090 } 
00091 
00092 void 
00093 Args::PrintError(std::ostream& os, const char* msg) const
00094 {
00095   os << GetCmd() << ": " << msg << endl
00096      << "Try `" << GetCmd() << " --help' for more information." << endl;
00097 }
00098 
00099 void 
00100 Args::PrintError(std::ostream& os, const std::string& msg) const
00101 {
00102   PrintError(os, msg.c_str());
00103 }
00104 
00105 
00106 void
00107 Args::Parse(int argc, const char* const argv[])
00108 {
00109   try {
00110     // -------------------------------------------------------
00111     // Parse the command line
00112     // -------------------------------------------------------
00113     parser.Parse(optArgs, argc, argv);
00114     
00115     // -------------------------------------------------------
00116     // Sift through results, checking for semantic errors
00117     // -------------------------------------------------------
00118     
00119     // Special options that should be checked first
00120     if (parser.IsOpt("debug")) { 
00121       debug = 1; 
00122       if (parser.IsOptArg("debug")) {
00123         const string& arg = parser.GetOptArg("debug");
00124         debug = (int)CmdLineParser::ToLong(arg);
00125       }
00126     }
00127     if (parser.IsOpt("help")) { 
00128       PrintUsage(std::cerr); 
00129       exit(0);
00130     }
00131     if (parser.IsOpt("variedOnly")) { 
00132       ourVariedOnlyFlag=true;
00133     }
00134     if (parser.IsOpt("output")) { 
00135       xaifFileNm = parser.GetOptArg("output");
00136     }    
00137     if (parser.IsOpt("prefix")) { 
00138       tmpVarPrefix = parser.GetOptArg("prefix");
00139     }
00140     if (parser.IsOpt("simpleLoop")) { 
00141       ourSimpleLoopFlag = true; 
00142     }
00143     if (parser.IsOpt("noFilter")) { 
00144       ourDoNotFilterFlag = true; 
00145     }
00146     if (parser.IsOpt("noTimeStamp")) { 
00147       ourNoTimeStampFlag= true; 
00148     }
00149     if (parser.IsOpt("uniformCBact")) { 
00150       ourUniformCBactFlag = true; 
00151     }
00152     // Check for required arguments
00153     if (parser.GetNumArgs() != 1) {
00154       PrintError(std::cerr, "Invalid number of arguments!");
00155       exit(1);
00156     }
00157     whirlFileNm = parser.GetArg(0);
00158   } 
00159   catch (CmdLineParser::ParseError& e) {
00160     PrintError(std::cerr, e.GetMessage());
00161     exit(1);
00162   }
00163 }
00164 
00165 
00166 void 
00167 Args::Dump(std::ostream& os) const
00168 {
00169   parser.Dump(os);
00170 }
00171 
00172 void 
00173 Args::DDump() const
00174 {
00175   Dump(std::cerr);
00176 }
00177 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines