Remember plugins should someone like bugpoint want to know them.
[oota-llvm.git] / lib / Support / CommandLine.cpp
index 533d7d56066feef67fbdcaf348eb8cbc8ca9ddd6..1644308077a26bf6f8b663199f5f60c9ea7b147e 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/Config/config.h"
 #include "llvm/Support/CommandLine.h"
 #include <algorithm>
+#include <functional>
 #include <map>
 #include <set>
 #include <iostream>
@@ -297,6 +298,10 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
 
   // Check out the positional arguments to collect information about them.
   unsigned NumPositionalRequired = 0;
+  
+  // Determine whether or not there are an unlimited number of positionals
+  bool HasUnlimitedPositionals = false;
+  
   Option *ConsumeAfterOpt = 0;
   if (!PositionalOpts.empty()) {
     if (PositionalOpts[0]->getNumOccurrencesFlag() == cl::ConsumeAfter) {
@@ -332,6 +337,7 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
       }
       UnboundedFound |= EatsUnboundedNumberOfValues(Opt);
     }
+    HasUnlimitedPositionals = UnboundedFound || ConsumeAfterOpt;
   }
 
   // PositionalVals - A vector of "positional" arguments we accumulate into
@@ -442,8 +448,11 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
     }
 
     if (Handler == 0) {
-      std::cerr << ProgramName << ": Unknown command line argument '" << argv[i]
-                << "'.  Try: '" << argv[0] << " --help'\n";
+      if (ProgramName)
+        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;
     }
@@ -479,12 +488,29 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
 
   // Check and handle positional arguments now...
   if (NumPositionalRequired > PositionalVals.size()) {
-    std::cerr << ProgramName
-              << ": Not enough positional command line arguments specified!\n"
-              << "Must specify at least " << NumPositionalRequired
-              << " positional arguments: See: " << argv[0] << " --help\n";
+    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.";
+    
+    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";
     ErrorParsing = true;
-
 
   } else if (ConsumeAfterOpt == 0) {
     // Positional args have already been handled if ConsumeAfter is specified...
@@ -930,7 +956,12 @@ public:
   void operator=(bool OptionWasSpecified) {
     if (OptionWasSpecified) {
       std::cerr << "Low Level Virtual Machine (" << PACKAGE_NAME << ") "
-                << PACKAGE_VERSION << " (see http://llvm.cs.uiuc.edu/)\n";
+                << PACKAGE_VERSION << " (see http://llvm.org/)";
+#ifndef NDEBUG
+      std::cerr << " DEBUG BUILD\n";
+#else
+      std::cerr << "\n";
+#endif
       getOpts().clear();  // Don't bother making option dtors remove from map.
       exit(1);
     }
@@ -945,17 +976,17 @@ HelpPrinter NormalPrinter(false);
 HelpPrinter HiddenPrinter(true);
 
 cl::opt<HelpPrinter, true, parser<bool> >
-HOp("help", cl::desc("display available options (--help-hidden for more)"),
+HOp("help", cl::desc("Display available options (--help-hidden for more)"),
     cl::location(NormalPrinter), cl::ValueDisallowed);
 
 cl::opt<HelpPrinter, true, parser<bool> >
-HHOp("help-hidden", cl::desc("display all available options"),
+HHOp("help-hidden", cl::desc("Display all available options"),
      cl::location(HiddenPrinter), cl::Hidden, cl::ValueDisallowed);
 
 // Define the --version option that prints out the LLVM version for the tool
 VersionPrinter VersionPrinterInstance;
 cl::opt<VersionPrinter, true, parser<bool> >
-VersOp("version", cl::desc("display the version"),
+VersOp("version", cl::desc("Display the version of this program"),
     cl::location(VersionPrinterInstance), cl::ValueDisallowed);