]> granicus.if.org Git - clang/commitdiff
Add clang -cc1 -load option.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 3 Dec 2009 05:11:05 +0000 (05:11 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 3 Dec 2009 05:11:05 +0000 (05:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90413 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticFrontendKinds.td
include/clang/Driver/CC1Options.td
include/clang/Frontend/FrontendOptions.h
lib/Frontend/CompilerInvocation.cpp
tools/clang-cc/clang-cc.cpp

index c36d1c442bab6d3e9361b43e9b85348f61d4f6cc..fa34caccf5738b4d16af7015eb4d681750ff0268 100644 (file)
@@ -39,6 +39,8 @@ def err_fe_remap_missing_from_file : Error<
     "could not remap from missing file '%0'">, DefaultFatal;
 def err_fe_unable_to_load_pch : Error<
     "unable to load PCH file">;
+def err_fe_unable_to_load_plugin : Error<
+    "unable to load plugin '%0': '%1'">;
 
 def err_verify_bogus_characters : Error<
     "bogus characters before '{{' in expected string">;
index b34fe0340a55085d7c353dc690035a41b0872f93..74aa11b3423695e64387d3ccebce5d88b4affb13 100644 (file)
@@ -205,6 +205,8 @@ def cxx_inheritance_view : Separate<"-cxx-inheritance-view">,
 def fixit_at : Separate<"-fixit-at">, MetaVarName<"source-location">,
   HelpText<"Perform Fix-It modifications at the given source location">;
 def o : Separate<"-o">, MetaVarName<"path">, HelpText<"Specify output file">;
+def load : Separate<"-load">, MetaVarName<"dsopath">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
 def plugin : Separate<"-plugin">,
   HelpText<"Use the named plugin action (use \"help\" to list available options)">;
 
index c1ec8e70f1c653ccd28ddba9e7b3a6696df4fe01..ce60941534dfeba0447f50ef4347121038e676e7 100644 (file)
@@ -105,6 +105,9 @@ public:
   /// The name of the action to run when using a plugin action.
   std::string ActionName;
 
+  /// The list of plugins to load.
+  std::vector<std::string> Plugins;
+
 public:
   FrontendOptions() {
     DebugCodeCompletionPrinter = 1;
index 761bae9e641b6ec07c9e352d18033b78425b7e9a..3e6f9cbd852fb73136ae041b66e76abc345d4698 100644 (file)
@@ -345,6 +345,10 @@ static void FrontendOptsToArgs(const FrontendOptions &Opts,
     Res.push_back("-plugin");
     Res.push_back(Opts.ActionName);
   }
+  for (unsigned i = 0, e = Opts.Plugins.size(); i != e; ++i) {
+    Res.push_back("-load");
+    Res.push_back(Opts.Plugins[i]);
+  }
 }
 
 static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts,
@@ -877,6 +881,7 @@ ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Diagnostic &Diags) {
   }
 
   Opts.OutputFile = getLastArgValue(Args, OPT_o);
+  Opts.Plugins = getAllArgValues(Args, OPT_load);
   Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch);
   Opts.ShowMacrosInCodeCompletion = Args.hasArg(OPT_code_completion_macros);
   Opts.ShowStats = Args.hasArg(OPT_print_stats);
index 2899684284a97875c9d2f8de3c65b2d82e347de4..b189b4b51d658f6d4fbe62889e058bf2a1b24093 100644 (file)
@@ -42,6 +42,7 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/System/DynamicLibrary.h"
 #include "llvm/System/Host.h"
 #include "llvm/System/Path.h"
 #include "llvm/System/Signals.h"
@@ -299,7 +300,8 @@ int main(int argc, char **argv) {
                                    Clang.getDiagnostics(), argv[0]))
     return 1;
 #else
-  // Buffer diagnostics from argument parsing.
+  // Buffer diagnostics from argument parsing so that we can output them using a
+  // well formed diagnostic object.
   TextDiagnosticBuffer DiagsBuffer;
   Diagnostic Diags(&DiagsBuffer);
 
@@ -321,6 +323,15 @@ int main(int argc, char **argv) {
 
   DiagsBuffer.FlushDiagnostics(Clang.getDiagnostics());
 
+  // Load any requested plugins.
+  for (unsigned i = 0,
+         e = Clang.getFrontendOpts().Plugins.size(); i != e; ++i) {
+    const std::string &Path = Clang.getFrontendOpts().Plugins[i];
+    std::string Error;
+    if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
+      Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error;
+  }
+
   // If there were any errors in processing arguments, exit now.
   if (Clang.getDiagnostics().getNumErrors())
     return 1;