mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-28 23:17:10 +00:00
Pass a std::unique_ptr<MemoryBuffer>& to getLazyBitcodeModule.
By taking a reference we can do the ownership transfer in one place instead of expecting every caller to do it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216492 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -3519,11 +3519,11 @@ const std::error_category &llvm::BitcodeErrorCategory() {
|
||||
///
|
||||
/// \param[in] WillMaterializeAll Set to \c true if the caller promises to
|
||||
/// materialize everything -- in particular, if this isn't truly lazy.
|
||||
static ErrorOr<Module *> getLazyBitcodeModuleImpl(MemoryBuffer *Buffer,
|
||||
LLVMContext &Context,
|
||||
bool WillMaterializeAll) {
|
||||
static ErrorOr<Module *>
|
||||
getLazyBitcodeModuleImpl(std::unique_ptr<MemoryBuffer> &Buffer,
|
||||
LLVMContext &Context, bool WillMaterializeAll) {
|
||||
Module *M = new Module(Buffer->getBufferIdentifier(), Context);
|
||||
BitcodeReader *R = new BitcodeReader(Buffer, Context);
|
||||
BitcodeReader *R = new BitcodeReader(Buffer.get(), Context);
|
||||
M->setMaterializer(R);
|
||||
|
||||
auto cleanupOnError = [&](std::error_code EC) {
|
||||
@@ -3540,11 +3540,13 @@ static ErrorOr<Module *> getLazyBitcodeModuleImpl(MemoryBuffer *Buffer,
|
||||
if (std::error_code EC = R->materializeForwardReferencedFunctions())
|
||||
return cleanupOnError(EC);
|
||||
|
||||
Buffer.release(); // The BitcodeReader owns it now.
|
||||
return M;
|
||||
}
|
||||
|
||||
ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
|
||||
LLVMContext &Context) {
|
||||
ErrorOr<Module *>
|
||||
llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &Buffer,
|
||||
LLVMContext &Context) {
|
||||
return getLazyBitcodeModuleImpl(Buffer, Context, false);
|
||||
}
|
||||
|
||||
@@ -3567,11 +3569,9 @@ Module *llvm::getStreamedBitcodeModule(const std::string &name,
|
||||
ErrorOr<Module *> llvm::parseBitcodeFile(MemoryBufferRef Buffer,
|
||||
LLVMContext &Context) {
|
||||
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
|
||||
ErrorOr<Module *> ModuleOrErr =
|
||||
getLazyBitcodeModuleImpl(Buf.get(), Context, true);
|
||||
ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModuleImpl(Buf, Context, true);
|
||||
if (!ModuleOrErr)
|
||||
return ModuleOrErr;
|
||||
Buf.release(); // The BitcodeReader owns it now.
|
||||
Module *M = ModuleOrErr.get();
|
||||
// Read in the entire module, and destroy the BitcodeReader.
|
||||
if (std::error_code EC = M->materializeAllPermanently()) {
|
||||
|
Reference in New Issue
Block a user