diff options
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/llc/llc.cpp | 40 | ||||
| -rw-r--r-- | llvm/tools/llvm-dis/llvm-dis.cpp | 43 | ||||
| -rw-r--r-- | llvm/tools/llvm-link/llvm-link.cpp | 45 | ||||
| -rw-r--r-- | llvm/tools/llvm-lto/llvm-lto.cpp | 66 | ||||
| -rw-r--r-- | llvm/tools/lto/lto.cpp | 35 |
5 files changed, 101 insertions, 128 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index bbbec221208..aad237c42dc 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -235,24 +235,20 @@ GetOutputStream(const char *TargetName, Triple::OSType OS, return FDOut; } -struct LLCDiagnosticHandler : public DiagnosticHandler { - bool *HasError; - LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {} - bool handleDiagnostics(const DiagnosticInfo &DI) override { - if (DI.getSeverity() == DS_Error) - *HasError = true; - - if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) - if (!Remark->isEnabled()) - return true; - - DiagnosticPrinterRawOStream DP(errs()); - errs() << LLVMContext::getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; - DI.print(DP); - errs() << "\n"; - return true; - } -}; +static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context) { + bool *HasError = static_cast<bool *>(Context); + if (DI.getSeverity() == DS_Error) + *HasError = true; + + if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) + if (!Remark->isEnabled()) + return; + + DiagnosticPrinterRawOStream DP(errs()); + errs() << LLVMContext::getDiagnosticMessagePrefix(DI.getSeverity()) << ": "; + DI.print(DP); + errs() << "\n"; +} static void InlineAsmDiagHandler(const SMDiagnostic &SMD, void *Context, unsigned LocCookie) { @@ -312,8 +308,7 @@ int main(int argc, char **argv) { // Set a diagnostic handler that doesn't exit on the first error bool HasError = false; - Context.setDiagnosticHandler( - llvm::make_unique<LLCDiagnosticHandler>(&HasError)); + Context.setDiagnosticHandler(DiagnosticHandler, &HasError); Context.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, &HasError); if (PassRemarksWithHotness) @@ -569,9 +564,8 @@ static int compileModule(char **argv, LLVMContext &Context) { PM.run(*M); - auto HasError = - ((const LLCDiagnosticHandler *)(Context.getDiagHandlerPtr()))->HasError; - if (*HasError) + auto HasError = *static_cast<bool *>(Context.getDiagnosticContext()); + if (HasError) return 1; // Compare the two outputs and make sure they're the same diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp index 6828b69abe8..82dbaa5e3c6 100644 --- a/llvm/tools/llvm-dis/llvm-dis.cpp +++ b/llvm/tools/llvm-dis/llvm-dis.cpp @@ -122,29 +122,25 @@ public: } }; -struct LLVMDisDiagnosticHandler : public DiagnosticHandler { - char *Prefix; - LLVMDisDiagnosticHandler(char *PrefixPtr) : Prefix(PrefixPtr) {} - bool handleDiagnostics(const DiagnosticInfo &DI) override { - raw_ostream &OS = errs(); - OS << Prefix << ": "; - switch (DI.getSeverity()) { - case DS_Error: OS << "error: "; break; - case DS_Warning: OS << "warning: "; break; - case DS_Remark: OS << "remark: "; break; - case DS_Note: OS << "note: "; break; - } - - DiagnosticPrinterRawOStream DP(OS); - DI.print(DP); - OS << '\n'; +} // end anon namespace - if (DI.getSeverity() == DS_Error) - exit(1); - return true; +static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) { + raw_ostream &OS = errs(); + OS << (char *)Context << ": "; + switch (DI.getSeverity()) { + case DS_Error: OS << "error: "; break; + case DS_Warning: OS << "warning: "; break; + case DS_Remark: OS << "remark: "; break; + case DS_Note: OS << "note: "; break; } -}; -} // end anon namespace + + DiagnosticPrinterRawOStream DP(OS); + DI.print(DP); + OS << '\n'; + + if (DI.getSeverity() == DS_Error) + exit(1); +} static ExitOnError ExitOnErr; @@ -170,8 +166,9 @@ int main(int argc, char **argv) { LLVMContext Context; llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. - Context.setDiagnosticHandler( - llvm::make_unique<LLVMDisDiagnosticHandler>(argv[0])); + + Context.setDiagnosticHandler(diagnosticHandler, argv[0]); + cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n"); std::unique_ptr<Module> M = openInputFile(Context); diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp index 805ea73b3f6..568e5f8d2d5 100644 --- a/llvm/tools/llvm-link/llvm-link.cpp +++ b/llvm/tools/llvm-link/llvm-link.cpp @@ -182,30 +182,25 @@ Module &ModuleLazyLoaderCache::operator()(const char *argv0, } } // anonymous namespace -namespace { -struct LLVMLinkDiagnosticHandler : public DiagnosticHandler { - bool handleDiagnostics(const DiagnosticInfo &DI) override { - unsigned Severity = DI.getSeverity(); - switch (Severity) { - case DS_Error: - errs() << "ERROR: "; - break; - case DS_Warning: - if (SuppressWarnings) - return true; - errs() << "WARNING: "; - break; - case DS_Remark: - case DS_Note: - llvm_unreachable("Only expecting warnings and errors"); - } - - DiagnosticPrinterRawOStream DP(errs()); - DI.print(DP); - errs() << '\n'; - return true; +static void diagnosticHandler(const DiagnosticInfo &DI, void *C) { + unsigned Severity = DI.getSeverity(); + switch (Severity) { + case DS_Error: + errs() << "ERROR: "; + break; + case DS_Warning: + if (SuppressWarnings) + return; + errs() << "WARNING: "; + break; + case DS_Remark: + case DS_Note: + llvm_unreachable("Only expecting warnings and errors"); } -}; + + DiagnosticPrinterRawOStream DP(errs()); + DI.print(DP); + errs() << '\n'; } /// Import any functions requested via the -import option. @@ -352,8 +347,8 @@ int main(int argc, char **argv) { ExitOnErr.setBanner(std::string(argv[0]) + ": "); LLVMContext Context; - Context.setDiagnosticHandler( - llvm::make_unique<LLVMLinkDiagnosticHandler>(), true); + Context.setDiagnosticHandler(diagnosticHandler, nullptr, true); + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index bbd0edac108..dd4199112ee 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -235,40 +235,34 @@ static void handleDiagnostics(lto_codegen_diagnostic_severity_t Severity, } static std::string CurrentActivity; - -namespace { - struct LLVMLTODiagnosticHandler : public DiagnosticHandler { - bool handleDiagnostics(const DiagnosticInfo &DI) override { - raw_ostream &OS = errs(); - OS << "llvm-lto: "; - switch (DI.getSeverity()) { - case DS_Error: - OS << "error"; - break; - case DS_Warning: - OS << "warning"; - break; - case DS_Remark: - OS << "remark"; - break; - case DS_Note: - OS << "note"; - break; - } - if (!CurrentActivity.empty()) - OS << ' ' << CurrentActivity; - OS << ": "; - - DiagnosticPrinterRawOStream DP(OS); - DI.print(DP); - OS << '\n'; - - if (DI.getSeverity() == DS_Error) - exit(1); - return true; - } - }; +static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) { + raw_ostream &OS = errs(); + OS << "llvm-lto: "; + switch (DI.getSeverity()) { + case DS_Error: + OS << "error"; + break; + case DS_Warning: + OS << "warning"; + break; + case DS_Remark: + OS << "remark"; + break; + case DS_Note: + OS << "note"; + break; } + if (!CurrentActivity.empty()) + OS << ' ' << CurrentActivity; + OS << ": "; + + DiagnosticPrinterRawOStream DP(OS); + DI.print(DP); + OS << '\n'; + + if (DI.getSeverity() == DS_Error) + exit(1); +} static void error(const Twine &Msg) { errs() << "llvm-lto: " << Msg << '\n'; @@ -299,8 +293,7 @@ getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer, Buffer = std::move(BufferOrErr.get()); CurrentActivity = ("loading file '" + Path + "'").str(); std::unique_ptr<LLVMContext> Context = llvm::make_unique<LLVMContext>(); - Context->setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(), - true); + Context->setDiagnosticHandler(diagnosticHandler, nullptr, true); ErrorOr<std::unique_ptr<LTOModule>> Ret = LTOModule::createInLocalContext( std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(), Options, Path); @@ -844,8 +837,7 @@ int main(int argc, char **argv) { unsigned BaseArg = 0; LLVMContext Context; - Context.setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(), - true); + Context.setDiagnosticHandler(diagnosticHandler, nullptr, true); LTOCodeGenerator CodeGen(Context); diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp index 11885211797..1b218a64cbf 100644 --- a/llvm/tools/lto/lto.cpp +++ b/llvm/tools/lto/lto.cpp @@ -75,23 +75,20 @@ static bool parsedOptions = false; static LLVMContext *LTOContext = nullptr; -struct LTOToolDiagnosticHandler : public DiagnosticHandler { - bool handleDiagnostics(const DiagnosticInfo &DI) override { - if (DI.getSeverity() != DS_Error) { - DiagnosticPrinterRawOStream DP(errs()); - DI.print(DP); - errs() << '\n'; - return true; - } - sLastErrorString = ""; - { - raw_string_ostream Stream(sLastErrorString); - DiagnosticPrinterRawOStream DP(Stream); - DI.print(DP); - } - return true; +static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) { + if (DI.getSeverity() != DS_Error) { + DiagnosticPrinterRawOStream DP(errs()); + DI.print(DP); + errs() << '\n'; + return; } -}; + sLastErrorString = ""; + { + raw_string_ostream Stream(sLastErrorString); + DiagnosticPrinterRawOStream DP(Stream); + DI.print(DP); + } +} // Initialize the configured targets if they have not been initialized. static void lto_initialize() { @@ -111,8 +108,7 @@ static void lto_initialize() { static LLVMContext Context; LTOContext = &Context; - LTOContext->setDiagnosticHandler( - llvm::make_unique<LTOToolDiagnosticHandler>(), true); + LTOContext->setDiagnosticHandler(diagnosticHandler, nullptr, true); initialized = true; } } @@ -278,8 +274,7 @@ lto_module_t lto_module_create_in_local_context(const void *mem, size_t length, // Create a local context. Ownership will be transferred to LTOModule. std::unique_ptr<LLVMContext> Context = llvm::make_unique<LLVMContext>(); - Context->setDiagnosticHandler(llvm::make_unique<LTOToolDiagnosticHandler>(), - true); + Context->setDiagnosticHandler(diagnosticHandler, nullptr, true); ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createInLocalContext( std::move(Context), mem, length, Options, StringRef(path)); |

