diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-12-14 23:17:03 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-12-14 23:17:03 +0000 |
commit | 7a1fc2d33e22333b6ebe8f1ef2f6c14ad82bd114 (patch) | |
tree | e1e664377457567029f570b7483288082199f350 /tools | |
parent | 265bc7dab126aadfb12f7ea40f25ae0bf85cff33 (diff) |
Use diagnostic handler in the LLVMContext
This patch converts code that has access to a LLVMContext to not take a
diagnostic handler.
This has a few advantages
* It is easier to use a consistent diagnostic handler in a single program.
* Less clutter since we are not passing a handler around.
It does make it a bit awkward to implement some C APIs that return a
diagnostic string. I will propose new versions of these APIs and
deprecate the current ones.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255571 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bugpoint/BugDriver.cpp | 9 | ||||
-rw-r--r-- | tools/bugpoint/Miscompilation.cpp | 19 | ||||
-rw-r--r-- | tools/gold/gold-plugin.cpp | 2 | ||||
-rw-r--r-- | tools/llvm-link/llvm-link.cpp | 8 |
4 files changed, 13 insertions, 25 deletions
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp index 9edc242d470..39887d5d59d 100644 --- a/tools/bugpoint/BugDriver.cpp +++ b/tools/bugpoint/BugDriver.cpp @@ -15,7 +15,6 @@ #include "BugDriver.h" #include "ToolRunner.h" -#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" #include "llvm/IRReader/IRReader.h" @@ -113,12 +112,6 @@ std::unique_ptr<Module> llvm::parseInputFile(StringRef Filename, return Result; } -static void diagnosticHandler(const DiagnosticInfo &DI) { - DiagnosticPrinterRawOStream DP(errs()); - DI.print(DP); - errs() << '\n'; -} - // This method takes the specified list of LLVM input files, attempts to load // them, either as assembly or bitcode, then link them together. It returns // true on failure (if, for example, an input bitcode file could not be @@ -139,7 +132,7 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) { if (!M.get()) return true; outs() << "Linking in input file: '" << Filenames[i] << "'\n"; - if (Linker::linkModules(*Program, *M, diagnosticHandler)) + if (Linker::linkModules(*Program, *M)) return true; } diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 5c9f0271cec..2c64e372256 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -18,7 +18,6 @@ #include "llvm/Config/config.h" // for HAVE_LINK_R #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" @@ -211,14 +210,6 @@ namespace { }; } -static void diagnosticHandler(const DiagnosticInfo &DI) { - DiagnosticPrinterRawOStream DP(errs()); - DI.print(DP); - errs() << '\n'; - if (DI.getSeverity() == DS_Error) - exit(1); -} - /// Given two modules, link them together and run the program, checking to see /// if the program matches the diff. If there is an error, return NULL. If not, /// return the merged module. The Broken argument will be set to true if the @@ -230,7 +221,7 @@ static std::unique_ptr<Module> testMergedProgram(const BugDriver &BD, std::unique_ptr<Module> M2, std::string &Error, bool &Broken) { - if (Linker::linkModules(*M1, *M2, diagnosticHandler)) + if (Linker::linkModules(*M1, *M2)) exit(1); // Execute the program. @@ -396,8 +387,7 @@ static bool ExtractLoops(BugDriver &BD, MisCompFunctions.emplace_back(F->getName(), F->getFunctionType()); } - if (Linker::linkModules(*ToNotOptimize, *ToOptimizeLoopExtracted, - diagnosticHandler)) + if (Linker::linkModules(*ToNotOptimize, *ToOptimizeLoopExtracted)) exit(1); MiscompiledFunctions.clear(); @@ -424,8 +414,7 @@ static bool ExtractLoops(BugDriver &BD, // extraction both didn't break the program, and didn't mask the problem. // Replace the current program with the loop extracted version, and try to // extract another loop. - if (Linker::linkModules(*ToNotOptimize, *ToOptimizeLoopExtracted, - diagnosticHandler)) + if (Linker::linkModules(*ToNotOptimize, *ToOptimizeLoopExtracted)) exit(1); // All of the Function*'s in the MiscompiledFunctions list are in the old @@ -593,7 +582,7 @@ static bool ExtractBlocks(BugDriver &BD, if (!I->isDeclaration()) MisCompFunctions.emplace_back(I->getName(), I->getFunctionType()); - if (Linker::linkModules(*ProgClone, *Extracted, diagnosticHandler)) + if (Linker::linkModules(*ProgClone, *Extracted)) exit(1); // Set the new program and delete the old one. diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index e52606b8828..186097fccf6 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -879,7 +879,7 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) { Context.setDiagnosticHandler(diagnosticHandlerForContext, nullptr, true); std::unique_ptr<Module> Combined(new Module("ld-temp.o", Context)); - IRMover L(*Combined, diagnosticHandler); + IRMover L(*Combined); std::string DefaultTriple = sys::getDefaultTargetTriple(); diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index 6f90f4056f7..8030f4c9037 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -141,6 +141,10 @@ static void diagnosticHandler(const DiagnosticInfo &DI) { errs() << '\n'; } +static void diagnosticHandlerWithContext(const DiagnosticInfo &DI, void *C) { + diagnosticHandler(DI); +} + /// Import any functions requested via the -import option. static bool importFunctions(const char *argv0, LLVMContext &Context, Linker &L) { @@ -265,11 +269,13 @@ int main(int argc, char **argv) { PrettyStackTraceProgram X(argc, argv); LLVMContext &Context = getGlobalContext(); + Context.setDiagnosticHandler(diagnosticHandlerWithContext, nullptr, true); + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argc, argv, "llvm linker\n"); auto Composite = make_unique<Module>("llvm-link", Context); - Linker L(*Composite, diagnosticHandler); + Linker L(*Composite); unsigned Flags = Linker::Flags::None; if (Internalize) |