Don't performance load/op/store transformation if op produces a floating point
[oota-llvm.git] / lib / Support / CommandLine.cpp
index 164cb5286f33230f249028f65626600f66956a4b..57620b50d6c6f8a3a8e81c194616a414a923e53c 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "llvm/Config/config.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/System/Path.h"
 #include <algorithm>
 #include <functional>
 #include <map>
 #include <cerrno>
 #include <cstring>
 using namespace llvm;
-
 using namespace cl;
 
+//===----------------------------------------------------------------------===//
+// Template instantiations and anchors.
+//
+TEMPLATE_INSTANTIATION(class basic_parser<bool>);
+TEMPLATE_INSTANTIATION(class basic_parser<int>);
+TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
+TEMPLATE_INSTANTIATION(class basic_parser<double>);
+TEMPLATE_INSTANTIATION(class basic_parser<float>);
+TEMPLATE_INSTANTIATION(class basic_parser<std::string>);
+
+TEMPLATE_INSTANTIATION(class opt<unsigned>);
+TEMPLATE_INSTANTIATION(class opt<int>);
+TEMPLATE_INSTANTIATION(class opt<std::string>);
+TEMPLATE_INSTANTIATION(class opt<bool>);
+
+void Option::anchor() {}
+void basic_parser_impl::anchor() {}
+void parser<bool>::anchor() {}
+void parser<int>::anchor() {}
+void parser<unsigned>::anchor() {}
+void parser<double>::anchor() {}
+void parser<float>::anchor() {}
+void parser<std::string>::anchor() {}
+
+//===----------------------------------------------------------------------===//
+
 // Globals for name and overview of program
-static const char *ProgramName = "<unknown>";
+static std::string ProgramName = "<premain>";
 static const char *ProgramOverview = 0;
 
 // This collects additional help to be printed.
@@ -46,7 +72,7 @@ extrahelp::extrahelp(const char* Help)
 }
 
 //===----------------------------------------------------------------------===//
-// Basic, shared command line option processing machinery...
+// Basic, shared command line option processing machinery.
 //
 
 // Return the global command line option vector.  Making it a function scoped
@@ -188,8 +214,8 @@ static bool EatsUnboundedNumberOfValues(const Option *O) {
 /// using strdup (), so it is the caller's responsibility to free ()
 /// them later.
 ///
-static void ParseCStringVector (std::vector<char *> &output,
-                                const char *input) {
+static void ParseCStringVector(std::vector<char *> &output,
+                               const char *input) {
   // Characters which will be treated as token separators:
   static const char *delims = " \v\f\t\r\n";
 
@@ -239,26 +265,25 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar,
   assert(envVar && "Environment variable name missing");
 
   // Get the environment variable they want us to parse options out of.
-  const char *envValue = getenv (envVar);
+  const char *envValue = getenv(envVar);
   if (!envValue)
     return;
 
   // Get program's "name", which we wouldn't know without the caller
   // telling us.
-  std::vector<char *> newArgv;
-  newArgv.push_back (strdup (progName));
+  std::vector<char*> newArgv;
+  newArgv.push_back(strdup(progName));
 
   // Parse the value of the environment variable into a "command line"
   // and hand it off to ParseCommandLineOptions().
-  ParseCStringVector (newArgv, envValue);
-  int newArgc = newArgv.size ();
-  ParseCommandLineOptions (newArgc, &newArgv[0], Overview);
+  ParseCStringVector(newArgv, envValue);
+  int newArgc = newArgv.size();
+  ParseCommandLineOptions(newArgc, &newArgv[0], Overview);
 
   // Free all the strdup()ed strings.
-  for (std::vector<char *>::iterator i = newArgv.begin (), e = newArgv.end ();
-       i != e; ++i) {
+  for (std::vector<char*>::iterator i = newArgv.begin(), e = newArgv.end();
+       i != e; ++i)
     free (*i);
-  }
 }
 
 /// LookupOption - Lookup the option specified by the specified option on the
@@ -289,7 +314,8 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
   assert((!getOpts().empty() || !getPositionalOpts().empty()) &&
          "No options specified, or ParseCommandLineOptions called more"
          " than once!");
-  ProgramName = argv[0];  // Save this away safe and snug
+  sys::Path progname(argv[0]);
+  ProgramName = sys::Path(argv[0]).getLast();
   ProgramOverview = Overview;
   bool ErrorParsing = false;
 
@@ -448,11 +474,8 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
     }
 
     if (Handler == 0) {
-      if (ProgramName)
-        std::cerr << ProgramName << ": Unknown command line argument '"
+      std::cerr << ProgramName << ": Unknown command line argument '"
                   << argv[i] << "'.  Try: '" << argv[0] << " --help'\n";
-      else
-        std::cerr << "Unknown command line argument '" << argv[i] << "'.\n";
       ErrorParsing = true;
       continue;
     }
@@ -488,28 +511,18 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
 
   // Check and handle positional arguments now...
   if (NumPositionalRequired > PositionalVals.size()) {
-    if (ProgramName)
-      std::cerr << ProgramName
-                << ": Not enough positional command line arguments specified!\n"
-                << "Must specify at least " << NumPositionalRequired
-                << " positional arguments: See: " << argv[0] << " --help\n";
-    else
-      std::cerr << "Not enough positional command line arguments specified!\n"
-                << "Must specify at least " << NumPositionalRequired
-                << " positional arguments.";
+    std::cerr << ProgramName
+              << ": Not enough positional command line arguments specified!\n"
+              << "Must specify at least " << NumPositionalRequired
+              << " positional arguments: See: " << argv[0] << " --help\n";
     
     ErrorParsing = true;
   } else if (!HasUnlimitedPositionals
              && PositionalVals.size() > PositionalOpts.size()) {
-    if (ProgramName)
-      std::cerr << ProgramName
-                << ": Too many positional arguments specified!\n"
-                << "Can specify at most " << PositionalOpts.size()
-                << " positional arguments: See: " << argv[0] << " --help\n";
-    else
-      std::cerr << "Too many positional arguments specified!\n"
-                << "Can specify at most " << PositionalOpts.size()
-                << " positional arguments.\n";
+    std::cerr << ProgramName
+              << ": Too many positional arguments specified!\n"
+              << "Can specify at most " << PositionalOpts.size()
+              << " positional arguments: See: " << argv[0] << " --help\n";
     ErrorParsing = true;
 
   } else if (ConsumeAfterOpt == 0) {
@@ -613,6 +626,7 @@ bool Option::error(std::string Message, const char *ArgName) {
     std::cerr << HelpStr;  // Be nice for positional arguments
   else
     std::cerr << ProgramName << ": for the -" << ArgName;
+  
   std::cerr << " option: " << Message << "\n";
   return true;
 }