diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-10-25 04:31:08 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-10-25 04:31:08 +0000 |
commit | 98ab63ce987d8aa4bda414edcb493d646acdaad9 (patch) | |
tree | 3e73c71cc7a87bd012463c65db3ddbe4822e03dc /llvm/lib/Linker | |
parent | 8f2d615252df282334118596da424e4773ec6ded (diff) | |
download | bcm5719-llvm-98ab63ce987d8aa4bda414edcb493d646acdaad9.tar.gz bcm5719-llvm-98ab63ce987d8aa4bda414edcb493d646acdaad9.zip |
Allow the C API users to keep relying on the OutMessages parameter.
Should fix the Ocaml tests.
llvm-svn: 220611
Diffstat (limited to 'llvm/lib/Linker')
-rw-r--r-- | llvm/lib/Linker/LinkModules.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index c9563e6c272..2467f678316 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -1766,8 +1766,33 @@ bool Linker::LinkModules(Module *Dest, Module *Src, unsigned Mode) { // C API. //===----------------------------------------------------------------------===// +static void bindingDiagnosticHandler(const llvm::DiagnosticInfo &DI, + void *Context) { + if (DI.getSeverity() != DS_Error) + return; + + std::string *Message = (std::string *)Context; + { + raw_string_ostream Stream(*Message); + DiagnosticPrinterRawOStream DP(Stream); + DI.print(DP); + } +} + + LLVMBool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src, LLVMLinkerMode Mode, char **OutMessages) { - LLVMBool Result = Linker::LinkModules(unwrap(Dest), unwrap(Src), Mode); + Module *D = unwrap(Dest); + LLVMContext &Ctx = D->getContext(); + + LLVMContext::DiagnosticHandlerTy OldHandler = Ctx.getDiagnosticHandler(); + void *OldDiagnosticContext = Ctx.getDiagnosticContext(); + std::string Message; + Ctx.setDiagnosticHandler(bindingDiagnosticHandler, &Message); + LLVMBool Result = Linker::LinkModules(D, unwrap(Src), Mode); + Ctx.setDiagnosticHandler(OldHandler, OldDiagnosticContext); + + if (OutMessages && Result) + *OutMessages = strdup(Message.c_str()); return Result; } |