[llvm-commits] [llvm] r60659 - /llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Mikhail Glushenkov foldr at codedgers.com
Sun Dec 7 08:42:47 PST 2008


Author: foldr
Date: Sun Dec  7 10:42:47 2008
New Revision: 60659

URL: http://llvm.org/viewvc/llvm-project?rev=60659&view=rev
Log:
Try to guess when the auto-generated cl::Sink option should be marked 'extern'.

This would be much easier to do if the CommandLine library didn't use
global state. Global state is evil.

Modified:
    llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

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

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Sun Dec  7 10:42:47 2008
@@ -1427,7 +1427,7 @@
 /// EmitOptionDefintions - Iterate over a list of option descriptions
 /// and emit registration code.
 void EmitOptionDefintions (const OptionDescriptions& descs,
-                           bool HasSink,
+                           bool HasSink, bool HasExterns,
                            std::ostream& O)
 {
   std::vector<OptionDescription> Aliases;
@@ -1503,7 +1503,9 @@
 
   // Emit the sink option.
   if (HasSink)
-    O << "cl::list<std::string> " << SinkOptionName << "(cl::Sink);\n";
+    O << (HasExterns ? "extern cl" : "cl")
+      << "::list<std::string> " << SinkOptionName
+      << (HasExterns ? ";\n" : "(cl::Sink);\n");
 
   O << '\n';
 }
@@ -1744,20 +1746,32 @@
 struct PluginData {
   OptionDescriptions OptDescs;
   bool HasSink;
+  bool HasExterns;
   ToolDescriptions ToolDescs;
   RecordVector Edges;
   int Priority;
 };
 
 /// HasSink - Go through the list of tool descriptions and check if
-/// there is one with the 'sink' property set.
+/// there are any with the 'sink' property set.
 bool HasSink(const ToolDescriptions& ToolDescs) {
   for (ToolDescriptions::const_iterator B = ToolDescs.begin(),
          E = ToolDescs.end(); B != E; ++B)
     if ((*B)->isSink())
       return true;
 
-    return false;
+  return false;
+}
+
+/// HasExterns - Go through the list of option descriptions and check
+/// if there are any external options.
+bool HasExterns(const OptionDescriptions& OptDescs) {
+ for (OptionDescriptions::const_iterator B = OptDescs.begin(),
+         E = OptDescs.end(); B != E; ++B)
+    if (B->second.isExtern())
+      return true;
+
+  return false;
 }
 
 /// CollectPluginData - Collect tool and option properties,
@@ -1773,6 +1787,7 @@
   const RecordVector& Tools = Records.getAllDerivedDefinitions("Tool");
   CollectToolDescriptions(Tools.begin(), Tools.end(), Data.ToolDescs);
   Data.HasSink = HasSink(Data.ToolDescs);
+  Data.HasExterns = HasExterns(Data.OptDescs);
 
   // Collect compilation graph edges.
   const RecordVector& CompilationGraphs =
@@ -1805,7 +1820,7 @@
   EmitIncludes(O);
 
   // Emit global option registration code.
-  EmitOptionDefintions(Data.OptDescs, Data.HasSink, O);
+  EmitOptionDefintions(Data.OptDescs, Data.HasSink, Data.HasExterns, O);
 
   // Emit hook declarations.
   EmitHookDeclarations(Data.ToolDescs, O);





More information about the llvm-commits mailing list