ErrorOr<std::unique_ptr<LTOModule>> LTOModule::createFromFile(LLVMContext &Context, StringRef path, const TargetOptions &options) { ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = MemoryBuffer::getFile(path); if (std::error_code EC = BufferOrErr.getError()) { Context.emitError(EC.message()); return EC; } std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get()); return makeLTOModule(Buffer->getMemBufferRef(), options, Context, /* ShouldBeLazy*/ false); }
static ErrorOr<std::unique_ptr<Module>> parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldBeLazy) { // Find the buffer. ErrorOr<MemoryBufferRef> MBOrErr = IRObjectFile::findBitcodeInMemBuffer(Buffer); if (std::error_code EC = MBOrErr.getError()) { Context.emitError(EC.message()); return EC; } if (!ShouldBeLazy) { // Parse the full file. return expectedToErrorOrAndEmitErrors(Context, parseBitcodeFile(*MBOrErr, Context)); } // Parse lazily. return expectedToErrorOrAndEmitErrors( Context, getLazyBitcodeModule(*MBOrErr, Context, true /*ShouldLazyLoadMetadata*/)); }