Add pluggable action support to clang-cc, via -plugin command line option.
 - Expects the plugin has been loaded with -load.

 - Using this may require disabling TOOL_NO_EXPORTS in the clang-cc Makefile, this breaks the llvm::Registry way of working (static constructors are bad, kids). This should be replaced with a "real" plugin model that has explicit plugin interfaces.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88824 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/Options.cpp b/tools/clang-cc/Options.cpp
index 33b8d77..3c57479 100644
--- a/tools/clang-cc/Options.cpp
+++ b/tools/clang-cc/Options.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/RegistryParser.h"
 #include <stdio.h>
 
 using namespace clang;
@@ -383,6 +384,11 @@
  llvm::cl::value_desc("path"),
  llvm::cl::desc("Specify output file"));
 
+static llvm::cl::opt<std::string>
+PluginActionName("plugin",
+                 llvm::cl::desc("Use the named plugin action "
+                                "(use \"help\" to list available options)"));
+
 static llvm::cl::opt<ActionKind>
 ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
            llvm::cl::init(ParseSyntaxOnly),
@@ -885,12 +891,18 @@
 void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
   using namespace frontendoptions;
 
+  // Select program action.
+  Opts.ProgramAction = ProgAction;
+  if (PluginActionName.getPosition()) {
+    Opts.ProgramAction = frontend::PluginAction;
+    Opts.ActionName = PluginActionName;
+  }
+
   Opts.CodeCompletionAt = CodeCompletionAt;
   Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
   Opts.DisableFree = DisableFree;
   Opts.EmptyInputOnly = EmptyInputOnly;
   Opts.FixItLocations = FixItAtLocations;
-  Opts.ProgramAction = ProgAction;
   Opts.OutputFile = OutputFile;
   Opts.RelocatablePCH = RelocatablePCH;
   Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;