/// \brief Finds and returns bitcode embedded in the given object file, or an
/// error code if not found.
- static ErrorOr<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
+ static Expected<MemoryBufferRef> findBitcodeInObject(const ObjectFile &Obj);
/// \brief Finds and returns bitcode in the given memory buffer (which may
/// be either a bitcode file or a native object file with embedded bitcode),
/// or an error code if not found.
- static ErrorOr<MemoryBufferRef>
+ static Expected<MemoryBufferRef>
findBitcodeInMemBuffer(MemoryBufferRef Object);
static Expected<std::unique_ptr<IRObjectFile>> create(MemoryBufferRef Object,
/// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM
/// bitcode.
bool LTOModule::isBitcodeFile(const void *Mem, size_t Length) {
- ErrorOr<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
+ Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
MemoryBufferRef(StringRef((const char *)Mem, Length), "<mem>"));
return bool(BCData);
}
if (!BufferOrErr)
return false;
- ErrorOr<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
+ Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer(
BufferOrErr.get()->getMemBufferRef());
return bool(BCData);
}
bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer,
StringRef TriplePrefix) {
- ErrorOr<MemoryBufferRef> BCOrErr =
+ Expected<MemoryBufferRef> BCOrErr =
IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef());
if (!BCOrErr)
return false;
}
std::string LTOModule::getProducerString(MemoryBuffer *Buffer) {
- ErrorOr<MemoryBufferRef> BCOrErr =
+ Expected<MemoryBufferRef> BCOrErr =
IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef());
if (!BCOrErr)
return "";
static ErrorOr<std::unique_ptr<Module>>
parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context,
bool ShouldBeLazy) {
-
// Find the buffer.
- ErrorOr<MemoryBufferRef> MBOrErr =
+ Expected<MemoryBufferRef> MBOrErr =
IRObjectFile::findBitcodeInMemBuffer(Buffer);
- if (std::error_code EC = MBOrErr.getError()) {
+ if (Error E = MBOrErr.takeError()) {
+ std::error_code EC = errorToErrorCode(std::move(E));
Context.emitError(EC.message());
return EC;
}
return Mods[0]->getTargetTriple();
}
-ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
+Expected<MemoryBufferRef>
+IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
for (const SectionRef &Sec : Obj.sections()) {
if (Sec.isBitcode()) {
StringRef SecContents;
if (std::error_code EC = Sec.getContents(SecContents))
- return EC;
+ return errorCodeToError(EC);
return MemoryBufferRef(SecContents, Obj.getFileName());
}
}
- return object_error::bitcode_section_not_found;
+ return errorCodeToError(object_error::bitcode_section_not_found);
}
-ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Object) {
+Expected<MemoryBufferRef>
+IRObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Object) {
file_magic Type = identify_magic(Object.getBuffer());
switch (Type) {
case file_magic::bitcode:
Expected<std::unique_ptr<ObjectFile>> ObjFile =
ObjectFile::createObjectFile(Object, Type);
if (!ObjFile)
- return errorToErrorCode(ObjFile.takeError());
+ return ObjFile.takeError();
return findBitcodeInObject(*ObjFile->get());
}
default:
- return object_error::invalid_file_type;
+ return errorCodeToError(object_error::invalid_file_type);
}
}
Expected<std::unique_ptr<IRObjectFile>>
IRObjectFile::create(MemoryBufferRef Object, LLVMContext &Context) {
- ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object);
+ Expected<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object);
if (!BCOrErr)
- return errorCodeToError(BCOrErr.getError());
+ return BCOrErr.takeError();
Expected<std::vector<BitcodeModule>> BMsOrErr =
getBitcodeModuleList(*BCOrErr);
Expected<IRSymtabFile> object::readIRSymtab(MemoryBufferRef MBRef) {
IRSymtabFile F;
- ErrorOr<MemoryBufferRef> BCOrErr =
+ Expected<MemoryBufferRef> BCOrErr =
IRObjectFile::findBitcodeInMemBuffer(MBRef);
if (!BCOrErr)
- return errorCodeToError(BCOrErr.getError());
+ return BCOrErr.takeError();
Expected<BitcodeFileContents> BFCOrErr = getBitcodeFileContents(*BCOrErr);
if (!BFCOrErr)
if (!Obj || !Context)
return std::move(Obj);
- ErrorOr<MemoryBufferRef> BCData =
+ Expected<MemoryBufferRef> BCData =
IRObjectFile::findBitcodeInObject(*Obj->get());
- if (!BCData)
+ if (!BCData) {
+ consumeError(BCData.takeError());
return std::move(Obj);
+ }
return IRObjectFile::create(
MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),