diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-11-13 07:00:17 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-11-13 07:00:17 +0000 |
commit | d9445c49ad47c227f5981ad1f8f211dff9aaa9f1 (patch) | |
tree | 81677338f0d0d86208f35bc7cf3acbc898999a71 /llvm/lib/Bitcode/Reader/BitReader.cpp | |
parent | 8dff03911c5efa7a3abd6fb43f09233758075b20 (diff) | |
download | bcm5719-llvm-d9445c49ad47c227f5981ad1f8f211dff9aaa9f1.tar.gz bcm5719-llvm-d9445c49ad47c227f5981ad1f8f211dff9aaa9f1.zip |
Bitcode: Change module reader functions to return an llvm::Expected.
Differential Revision: https://reviews.llvm.org/D26562
llvm-svn: 286752
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitReader.cpp | 49 |
1 files changed, 17 insertions, 32 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitReader.cpp b/llvm/lib/Bitcode/Reader/BitReader.cpp index 8aa82bfc5ee..63854307b7b 100644 --- a/llvm/lib/Bitcode/Reader/BitReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitReader.cpp @@ -34,13 +34,6 @@ LLVMBool LLVMParseBitcode2(LLVMMemoryBufferRef MemBuf, return LLVMParseBitcodeInContext2(LLVMGetGlobalContext(), MemBuf, OutModule); } -static void diagnosticHandler(const DiagnosticInfo &DI, void *C) { - auto *Message = reinterpret_cast<std::string *>(C); - raw_string_ostream Stream(*Message); - DiagnosticPrinterRawOStream DP(Stream); - DI.print(DP); -} - LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef, LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutModule, @@ -48,17 +41,12 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef, MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef(); LLVMContext &Ctx = *unwrap(ContextRef); - LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler = - Ctx.getDiagnosticHandler(); - void *OldDiagnosticContext = Ctx.getDiagnosticContext(); - std::string Message; - Ctx.setDiagnosticHandler(diagnosticHandler, &Message, true); - - ErrorOr<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx); - - Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext, true); - - if (ModuleOrErr.getError()) { + Expected<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx); + if (Error Err = ModuleOrErr.takeError()) { + std::string Message; + handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) { + Message = EIB.message(); + }); if (OutMessage) *OutMessage = strdup(Message.c_str()); *OutModule = wrap((Module *)nullptr); @@ -75,7 +63,8 @@ LLVMBool LLVMParseBitcodeInContext2(LLVMContextRef ContextRef, MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef(); LLVMContext &Ctx = *unwrap(ContextRef); - ErrorOr<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx); + ErrorOr<std::unique_ptr<Module>> ModuleOrErr = + expectedToErrorOrAndEmitErrors(Ctx, parseBitcodeFile(Buf, Ctx)); if (ModuleOrErr.getError()) { *OutModule = wrap((Module *)nullptr); return 1; @@ -92,23 +81,19 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef, LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM, char **OutMessage) { LLVMContext &Ctx = *unwrap(ContextRef); - LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler = - Ctx.getDiagnosticHandler(); - void *OldDiagnosticContext = Ctx.getDiagnosticContext(); - - std::string Message; - Ctx.setDiagnosticHandler(diagnosticHandler, &Message, true); std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf)); - - ErrorOr<std::unique_ptr<Module>> ModuleOrErr = + Expected<std::unique_ptr<Module>> ModuleOrErr = getOwningLazyBitcodeModule(std::move(Owner), Ctx); Owner.release(); - Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext, true); - if (ModuleOrErr.getError()) { - *OutM = wrap((Module *)nullptr); + if (Error Err = ModuleOrErr.takeError()) { + std::string Message; + handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) { + Message = EIB.message(); + }); if (OutMessage) *OutMessage = strdup(Message.c_str()); + *OutM = wrap((Module *)nullptr); return 1; } @@ -123,8 +108,8 @@ LLVMBool LLVMGetBitcodeModuleInContext2(LLVMContextRef ContextRef, LLVMContext &Ctx = *unwrap(ContextRef); std::unique_ptr<MemoryBuffer> Owner(unwrap(MemBuf)); - ErrorOr<std::unique_ptr<Module>> ModuleOrErr = - getOwningLazyBitcodeModule(std::move(Owner), Ctx); + ErrorOr<std::unique_ptr<Module>> ModuleOrErr = expectedToErrorOrAndEmitErrors( + Ctx, getOwningLazyBitcodeModule(std::move(Owner), Ctx)); Owner.release(); if (ModuleOrErr.getError()) { |