[llvm-commits] [llvm] r51759 - in /llvm/trunk: tools/llvmc2/llvmc.cpp utils/TableGen/LLVMCConfigurationEmitter.cpp

Mikhail Glushenkov foldr at codedgers.com
Thu May 29 23:28:38 PDT 2008


Author: foldr
Date: Fri May 30 01:28:37 2008
New Revision: 51759

URL: http://llvm.org/viewvc/llvm-project?rev=51759&view=rev
Log:
Add a check for side effect-free options (specified only in the OptionList).

Modified:
    llvm/trunk/tools/llvmc2/llvmc.cpp
    llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Modified: llvm/trunk/tools/llvmc2/llvmc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/llvmc.cpp?rev=51759&r1=51758&r2=51759&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/llvmc.cpp (original)
+++ llvm/trunk/tools/llvmc2/llvmc.cpp Fri May 30 01:28:37 2008
@@ -32,6 +32,9 @@
 // Built-in command-line options.
 // External linkage here is intentional.
 
+// TOFIX: Add a --keep-temps option.
+// TOFIX: Write a 'driver driver' (easier to do as a separate
+// executable that drives llvmc2 proper).
 cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input file>"),
                                      cl::ZeroOrMore);
 cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),

Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=51759&r1=51758&r2=51759&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Fri May 30 01:28:37 2008
@@ -243,6 +243,7 @@
   /// HasSink - Should the emitter generate a "cl::sink" option?
   bool HasSink;
 
+  /// FindOption - exception-throwing wrapper for find().
   const GlobalOptionDescription& FindOption(const std::string& OptName) const {
     const_iterator I = Descriptions.find(OptName);
     if (I != Descriptions.end())
@@ -251,7 +252,8 @@
       throw OptName + ": no such option!";
   }
 
-  // Insert new GlobalOptionDescription into GlobalOptionDescriptions list
+  /// insertDescription - Insert new GlobalOptionDescription into
+  /// GlobalOptionDescriptions list
   void insertDescription (const GlobalOptionDescription& o)
   {
     container_type::iterator I = Descriptions.find(o.Name);
@@ -750,7 +752,6 @@
                                       GlobalOptionDescriptions& OptDescs)
 {
   // Iterate over a properties list of every Tool definition
-
   for (;B!=E;++B) {
     RecordVector::value_type T = *B;
     // Throws an exception if the value does not exist.
@@ -760,12 +761,43 @@
   }
 }
 
+/// CheckForSuperfluousOptions - Check that there are no side
+/// effect-free options (specified only in the OptionList). Otherwise,
+/// output a warning.
+void CheckForSuperfluousOptions (const ToolPropertiesList& TPList,
+                                 const GlobalOptionDescriptions& OptDescs) {
+  llvm::StringSet<> nonSuperfluousOptions;
+
+  // Add all options mentioned in the TPList to the set of
+  // non-superfluous options.
+  for (ToolPropertiesList::const_iterator B = TPList.begin(),
+         E = TPList.end(); B != E; ++B) {
+    const ToolProperties& TP = *(*B);
+    for (ToolOptionDescriptions::const_iterator B = TP.OptDescs.begin(),
+           E = TP.OptDescs.end(); B != E; ++B) {
+      nonSuperfluousOptions.insert(B->first());
+    }
+  }
+
+  // Check that all options in OptDescs belong to the set of
+  // non-superfluous options.
+  for (GlobalOptionDescriptions::const_iterator B = OptDescs.begin(),
+         E = OptDescs.end(); B != E; ++B) {
+    const GlobalOptionDescription& Val = B->second;
+    if (!nonSuperfluousOptions.count(Val.Name)
+        && Val.Type != OptionType::Alias)
+      cerr << "Warning: option '-" << Val.Name << "' has no effect! "
+        "Probable cause: this option is specified only in the OptionList.\n";
+  }
+}
+
 /// EmitCaseTest1Arg - Helper function used by
 /// EmitCaseConstructHandler.
 bool EmitCaseTest1Arg(const std::string& TestName,
                       const DagInit& d,
                       const GlobalOptionDescriptions& OptDescs,
                       std::ostream& O) {
+  // TOFIX - Add a mechanism for OS detection.
   checkNumberOfArguments(&d, 1);
   const std::string& OptName = InitPtrToString(d.getArg(0));
   if (TestName == "switch_on") {
@@ -1666,6 +1698,10 @@
   CollectPropertiesFromOptionList(OptionLists.begin(), OptionLists.end(),
                                   opt_descs);
 
+  // Check that there are no options without side effects (specified
+  // only in the OptionList).
+  CheckForSuperfluousOptions(tool_props, opt_descs);
+
   // Emit global option registration code.
   EmitOptionDescriptions(opt_descs, O);
 





More information about the llvm-commits mailing list