summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llc/llc.cpp40
-rw-r--r--llvm/tools/llvm-dis/llvm-dis.cpp43
-rw-r--r--llvm/tools/llvm-link/llvm-link.cpp45
-rw-r--r--llvm/tools/llvm-lto/llvm-lto.cpp66
-rw-r--r--llvm/tools/lto/lto.cpp35
5 files changed, 128 insertions, 101 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index aad237c42dc..bbbec221208 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -235,20 +235,24 @@ GetOutputStream(const char *TargetName, Triple::OSType OS,
return FDOut;
}
-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";
-}
+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 InlineAsmDiagHandler(const SMDiagnostic &SMD, void *Context,
unsigned LocCookie) {
@@ -308,7 +312,8 @@ int main(int argc, char **argv) {
// Set a diagnostic handler that doesn't exit on the first error
bool HasError = false;
- Context.setDiagnosticHandler(DiagnosticHandler, &HasError);
+ Context.setDiagnosticHandler(
+ llvm::make_unique<LLCDiagnosticHandler>(&HasError));
Context.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, &HasError);
if (PassRemarksWithHotness)
@@ -564,8 +569,9 @@ static int compileModule(char **argv, LLVMContext &Context) {
PM.run(*M);
- auto HasError = *static_cast<bool *>(Context.getDiagnosticContext());
- if (HasError)
+ auto HasError =
+ ((const LLCDiagnosticHandler *)(Context.getDiagHandlerPtr()))->HasError;
+ 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 82dbaa5e3c6..6828b69abe8 100644
--- a/llvm/tools/llvm-dis/llvm-dis.cpp
+++ b/llvm/tools/llvm-dis/llvm-dis.cpp
@@ -122,25 +122,29 @@ public:
}
};
-} // end anon namespace
-
-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;
- }
+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';
+ DiagnosticPrinterRawOStream DP(OS);
+ DI.print(DP);
+ OS << '\n';
- if (DI.getSeverity() == DS_Error)
- exit(1);
-}
+ if (DI.getSeverity() == DS_Error)
+ exit(1);
+ return true;
+ }
+};
+} // end anon namespace
static ExitOnError ExitOnErr;
@@ -166,9 +170,8 @@ int main(int argc, char **argv) {
LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
- Context.setDiagnosticHandler(diagnosticHandler, argv[0]);
-
+ Context.setDiagnosticHandler(
+ llvm::make_unique<LLVMDisDiagnosticHandler>(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 568e5f8d2d5..805ea73b3f6 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -182,25 +182,30 @@ Module &ModuleLazyLoaderCache::operator()(const char *argv0,
}
} // anonymous namespace
-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");
- }
+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';
+ DiagnosticPrinterRawOStream DP(errs());
+ DI.print(DP);
+ errs() << '\n';
+ return true;
+ }
+};
}
/// Import any functions requested via the -import option.
@@ -347,8 +352,8 @@ int main(int argc, char **argv) {
ExitOnErr.setBanner(std::string(argv[0]) + ": ");
LLVMContext Context;
- Context.setDiagnosticHandler(diagnosticHandler, nullptr, true);
-
+ Context.setDiagnosticHandler(
+ llvm::make_unique<LLVMLinkDiagnosticHandler>(), 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 dd4199112ee..bbd0edac108 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -235,34 +235,40 @@ static void handleDiagnostics(lto_codegen_diagnostic_severity_t Severity,
}
static std::string CurrentActivity;
-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);
-}
+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 error(const Twine &Msg) {
errs() << "llvm-lto: " << Msg << '\n';
@@ -293,7 +299,8 @@ 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(diagnosticHandler, nullptr, true);
+ Context->setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(),
+ true);
ErrorOr<std::unique_ptr<LTOModule>> Ret = LTOModule::createInLocalContext(
std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(),
Options, Path);
@@ -837,7 +844,8 @@ int main(int argc, char **argv) {
unsigned BaseArg = 0;
LLVMContext Context;
- Context.setDiagnosticHandler(diagnosticHandler, nullptr, true);
+ Context.setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(),
+ true);
LTOCodeGenerator CodeGen(Context);
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index 1b218a64cbf..11885211797 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -75,20 +75,23 @@ static bool parsedOptions = false;
static LLVMContext *LTOContext = nullptr;
-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);
+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;
}
-}
+};
// Initialize the configured targets if they have not been initialized.
static void lto_initialize() {
@@ -108,7 +111,8 @@ static void lto_initialize() {
static LLVMContext Context;
LTOContext = &Context;
- LTOContext->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+ LTOContext->setDiagnosticHandler(
+ llvm::make_unique<LTOToolDiagnosticHandler>(), true);
initialized = true;
}
}
@@ -274,7 +278,8 @@ 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(diagnosticHandler, nullptr, true);
+ Context->setDiagnosticHandler(llvm::make_unique<LTOToolDiagnosticHandler>(),
+ true);
ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createInLocalContext(
std::move(Context), mem, length, Options, StringRef(path));
OpenPOWER on IntegriCloud