diff options
Diffstat (limited to 'flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp')
-rw-r--r-- | flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index a17b6b5..677f8cd 100644 --- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -13,6 +13,7 @@ #include "flang/Frontend/CompilerInstance.h" #include "flang/Frontend/FrontendActions.h" +#include "flang/Frontend/FrontendPluginRegistry.h" #include "clang/Driver/Options.h" #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" @@ -62,6 +63,19 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction( return std::make_unique<GetSymbolsSourcesAction>(); case InitOnly: return std::make_unique<InitOnlyAction>(); + case PluginAction: { + for (const FrontendPluginRegistry::entry &plugin : + FrontendPluginRegistry::entries()) { + if (plugin.getName() == ci.frontendOpts().ActionName) { + std::unique_ptr<PluginParseTreeAction> p(plugin.instantiate()); + return std::move(p); + } + } + unsigned diagID = ci.diagnostics().getCustomDiagID( + clang::DiagnosticsEngine::Error, "unable to find plugin '%0'"); + ci.diagnostics().Report(diagID) << ci.frontendOpts().ActionName; + return nullptr; + } default: break; // TODO: @@ -82,6 +96,7 @@ std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci) { return act; } + bool ExecuteCompilerInvocation(CompilerInstance *flang) { // Honor -help. if (flang->frontendOpts().showHelp) { @@ -99,6 +114,22 @@ bool ExecuteCompilerInvocation(CompilerInstance *flang) { return true; } + // Load any requested plugins. + for (const std::string &Path : flang->frontendOpts().plugins) { + std::string Error; + if (llvm::sys::DynamicLibrary::LoadLibraryPermanently( + Path.c_str(), &Error)) { + unsigned diagID = flang->diagnostics().getCustomDiagID( + clang::DiagnosticsEngine::Error, "unable to load plugin '%0': '%1'"); + flang->diagnostics().Report(diagID) << Path << Error; + } + } + + // If there were errors in processing arguments, don't do anything else. + if (flang->diagnostics().hasErrorOccurred()) { + return false; + } + // Create and execute the frontend action. std::unique_ptr<FrontendAction> act(CreateFrontendAction(*flang)); if (!act) |