Bitcode: Change module reader functions to return an llvm::Expected.
Differential Revision: https://reviews.llvm.org/D26562 llvm-svn: 286752
This commit is contained in:
@@ -6571,13 +6571,13 @@ const std::error_category &llvm::BitcodeErrorCategory() {
|
||||
///
|
||||
/// \param[in] MaterializeAll Set to \c true if we should materialize
|
||||
/// everything.
|
||||
static ErrorOr<std::unique_ptr<Module>>
|
||||
static Expected<std::unique_ptr<Module>>
|
||||
getLazyBitcodeModuleImpl(MemoryBufferRef Buffer, LLVMContext &Context,
|
||||
bool MaterializeAll,
|
||||
bool ShouldLazyLoadMetadata = false) {
|
||||
Expected<BitstreamCursor> StreamOrErr = initStream(Buffer);
|
||||
if (!StreamOrErr)
|
||||
return errorToErrorCodeAndEmitErrors(Context, StreamOrErr.takeError());
|
||||
return StreamOrErr.takeError();
|
||||
|
||||
BitcodeReader *R = new BitcodeReader(std::move(*StreamOrErr), Context);
|
||||
|
||||
@@ -6587,28 +6587,28 @@ getLazyBitcodeModuleImpl(MemoryBufferRef Buffer, LLVMContext &Context,
|
||||
|
||||
// Delay parsing Metadata if ShouldLazyLoadMetadata is true.
|
||||
if (Error Err = R->parseBitcodeInto(M.get(), ShouldLazyLoadMetadata))
|
||||
return errorToErrorCodeAndEmitErrors(Context, std::move(Err));
|
||||
return std::move(Err);
|
||||
|
||||
if (MaterializeAll) {
|
||||
// Read in the entire module, and destroy the BitcodeReader.
|
||||
if (Error Err = M->materializeAll())
|
||||
return errorToErrorCodeAndEmitErrors(Context, std::move(Err));
|
||||
return std::move(Err);
|
||||
} else {
|
||||
// Resolve forward references from blockaddresses.
|
||||
if (Error Err = R->materializeForwardReferencedFunctions())
|
||||
return errorToErrorCodeAndEmitErrors(Context, std::move(Err));
|
||||
return std::move(Err);
|
||||
}
|
||||
return std::move(M);
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<Module>>
|
||||
Expected<std::unique_ptr<Module>>
|
||||
llvm::getLazyBitcodeModule(MemoryBufferRef Buffer,
|
||||
LLVMContext &Context, bool ShouldLazyLoadMetadata) {
|
||||
return getLazyBitcodeModuleImpl(Buffer, Context, false,
|
||||
ShouldLazyLoadMetadata);
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<Module>>
|
||||
Expected<std::unique_ptr<Module>>
|
||||
llvm::getOwningLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
|
||||
LLVMContext &Context,
|
||||
bool ShouldLazyLoadMetadata) {
|
||||
@@ -6618,8 +6618,8 @@ llvm::getOwningLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
|
||||
return MOrErr;
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<Module>> llvm::parseBitcodeFile(MemoryBufferRef Buffer,
|
||||
LLVMContext &Context) {
|
||||
Expected<std::unique_ptr<Module>> llvm::parseBitcodeFile(MemoryBufferRef Buffer,
|
||||
LLVMContext &Context) {
|
||||
return getLazyBitcodeModuleImpl(Buffer, Context, true);
|
||||
// TODO: Restore the use-lists to the in-memory state when the bitcode was
|
||||
// written. We must defer until the Module has been fully materialized.
|
||||
|
||||
Reference in New Issue
Block a user