[llvm-commits] [llvm] r47377 - in /llvm/trunk: include/llvm/Support/CommandLine.h lib/Support/CommandLine.cpp

Anton Korobeynikov asl at math.spbu.ru
Wed Feb 20 04:38:10 PST 2008


Author: asl
Date: Wed Feb 20 06:38:07 2008
New Revision: 47377

URL: http://llvm.org/viewvc/llvm-project?rev=47377&view=rev
Log:
Add 'sink' cmdline option. Patch by Mikhail Glushenkov!

Modified:
    llvm/trunk/include/llvm/Support/CommandLine.h
    llvm/trunk/lib/Support/CommandLine.cpp

Modified: llvm/trunk/include/llvm/Support/CommandLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CommandLine.h?rev=47377&r1=47376&r2=47377&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/CommandLine.h (original)
+++ llvm/trunk/include/llvm/Support/CommandLine.h Wed Feb 20 06:38:07 2008
@@ -123,7 +123,8 @@
 enum MiscFlags {               // Miscellaneous flags to adjust argument
   CommaSeparated     = 0x200,  // Should this cl::list split between commas?
   PositionalEatsArgs = 0x400,  // Should this positional cl::list eat -args?
-  MiscMask           = 0x600   // Union of the above flags.
+  Sink               = 0x800,  // Should this cl::list eat all unknown options?
+  MiscMask           = 0xE00   // Union of the above flags.
 };
 
 

Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=47377&r1=47376&r2=47377&view=diff

==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Wed Feb 20 06:38:07 2008
@@ -101,6 +101,7 @@
 /// GetOptionInfo - Scan the list of registered options, turning them into data
 /// structures that are easier to handle.
 static void GetOptionInfo(std::vector<Option*> &PositionalOpts,
+                          std::vector<Option*> &SinkOpts,
                           std::map<std::string, Option*> &OptionsMap) {
   std::vector<const char*> OptionNames;
   Option *CAOpt = 0;  // The ConsumeAfter option if it exists.
@@ -126,6 +127,8 @@
     // Remember information about positional options.
     if (O->getFormattingFlag() == cl::Positional)
       PositionalOpts.push_back(O);
+    else if (O->getMiscFlags() && cl::Sink) // Remember sink options
+      SinkOpts.push_back(O);
     else if (O->getNumOccurrencesFlag() == cl::ConsumeAfter) {
       if (CAOpt)
         O->error("Cannot specify more than one option with cl::ConsumeAfter!");
@@ -337,8 +340,9 @@
                                  const char *Overview) {
   // Process all registered options.
   std::vector<Option*> PositionalOpts;
+  std::vector<Option*> SinkOpts;
   std::map<std::string, Option*> Opts;
-  GetOptionInfo(PositionalOpts, Opts);
+  GetOptionInfo(PositionalOpts, SinkOpts, Opts);
   
   assert((!Opts.empty() || !PositionalOpts.empty()) &&
          "No options specified!");
@@ -418,8 +422,9 @@
     // response to things like -load, etc.  If this happens, rescan the options.
     if (OptionListChanged) {
       PositionalOpts.clear();
+      SinkOpts.clear();
       Opts.clear();
-      GetOptionInfo(PositionalOpts, Opts);
+      GetOptionInfo(PositionalOpts, SinkOpts, Opts);
       OptionListChanged = false;
     }
     
@@ -515,9 +520,15 @@
     }
 
     if (Handler == 0) {
-      cerr << ProgramName << ": Unknown command line argument '"
-           << argv[i] << "'.  Try: '" << argv[0] << " --help'\n";
-      ErrorParsing = true;
+      if (SinkOpts.empty()) {
+        cerr << ProgramName << ": Unknown command line argument '"
+             << argv[i] << "'.  Try: '" << argv[0] << " --help'\n";
+        ErrorParsing = true;
+      } else {
+        for (std::vector<Option*>::iterator I = SinkOpts.begin(),
+               E = SinkOpts.end(); I != E ; ++I)
+          (*I)->addOccurrence(i, "", argv[i]);
+      }
       continue;
     }
 
@@ -929,8 +940,9 @@
 
     // Get all the options.
     std::vector<Option*> PositionalOpts;
+    std::vector<Option*> SinkOpts;
     std::map<std::string, Option*> OptMap;
-    GetOptionInfo(PositionalOpts, OptMap);
+    GetOptionInfo(PositionalOpts, SinkOpts, OptMap);
     
     // Copy Options into a vector so we can sort them as we like...
     std::vector<std::pair<std::string, Option*> > Opts;





More information about the llvm-commits mailing list