mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:12:47 +01:00
Change Archive::create() from ErrorOr<...> to Expected<...> and update
its clients. This commit will break the next lld builds. I’ll be committing the matching change for lld next. llvm-svn: 274160
This commit is contained in:
parent
fc048e0add
commit
af671d1c6b
@ -176,8 +176,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
Archive(MemoryBufferRef Source, std::error_code &EC);
|
||||
static ErrorOr<std::unique_ptr<Archive>> create(MemoryBufferRef Source);
|
||||
Archive(MemoryBufferRef Source, Error &Err);
|
||||
static Expected<std::unique_ptr<Archive>> create(MemoryBufferRef Source);
|
||||
|
||||
enum Kind {
|
||||
K_GNU,
|
||||
|
@ -263,11 +263,11 @@ Archive::Child::getAsBinary(LLVMContext *Context) const {
|
||||
return BinaryOrErr.takeError();
|
||||
}
|
||||
|
||||
ErrorOr<std::unique_ptr<Archive>> Archive::create(MemoryBufferRef Source) {
|
||||
std::error_code EC;
|
||||
std::unique_ptr<Archive> Ret(new Archive(Source, EC));
|
||||
if (EC)
|
||||
return EC;
|
||||
Expected<std::unique_ptr<Archive>> Archive::create(MemoryBufferRef Source) {
|
||||
Error Err;
|
||||
std::unique_ptr<Archive> Ret(new Archive(Source, Err));
|
||||
if (Err)
|
||||
return std::move(Err);
|
||||
return std::move(Ret);
|
||||
}
|
||||
|
||||
@ -276,8 +276,9 @@ void Archive::setFirstRegular(const Child &C) {
|
||||
FirstRegularStartOfFile = C.StartOfFile;
|
||||
}
|
||||
|
||||
Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
Archive::Archive(MemoryBufferRef Source, Error &Err)
|
||||
: Binary(Binary::ID_Archive, Source) {
|
||||
ErrorAsOutParameter ErrAsOutParam(Err);
|
||||
StringRef Buffer = Data.getBuffer();
|
||||
// Check for sufficient magic.
|
||||
if (Buffer.startswith(ThinMagic)) {
|
||||
@ -285,14 +286,18 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
} else if (Buffer.startswith(Magic)) {
|
||||
IsThin = false;
|
||||
} else {
|
||||
ec = object_error::invalid_file_type;
|
||||
Err = make_error<GenericBinaryError>("File too small to be an archive",
|
||||
object_error::invalid_file_type);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the special members.
|
||||
child_iterator I = child_begin(false);
|
||||
if ((ec = I->getError()))
|
||||
std::error_code ec;
|
||||
if ((ec = I->getError())) {
|
||||
Err = errorCodeToError(ec);
|
||||
return;
|
||||
}
|
||||
child_iterator E = child_end();
|
||||
|
||||
// This is at least a valid empty archive. Since an empty archive is the
|
||||
@ -301,14 +306,14 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
Format = K_GNU;
|
||||
|
||||
if (I == E) {
|
||||
ec = std::error_code();
|
||||
Err = Error::success();
|
||||
return;
|
||||
}
|
||||
const Child *C = &**I;
|
||||
|
||||
auto Increment = [&]() {
|
||||
++I;
|
||||
if ((ec = I->getError()))
|
||||
if ((Err = errorCodeToError(I->getError())))
|
||||
return true;
|
||||
C = &**I;
|
||||
return false;
|
||||
@ -347,7 +352,7 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
return;
|
||||
setFirstRegular(*C);
|
||||
|
||||
ec = std::error_code();
|
||||
Err = Error::success();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -356,8 +361,10 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
// We know this is BSD, so getName will work since there is no string table.
|
||||
ErrorOr<StringRef> NameOrErr = C->getName();
|
||||
ec = NameOrErr.getError();
|
||||
if (ec)
|
||||
if (ec) {
|
||||
Err = errorCodeToError(ec);
|
||||
return;
|
||||
}
|
||||
Name = NameOrErr.get();
|
||||
if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
|
||||
// We know that the symbol table is not an external file, so we just
|
||||
@ -394,7 +401,7 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
if (Increment())
|
||||
return;
|
||||
if (I == E) {
|
||||
ec = std::error_code();
|
||||
Err = Error::success();
|
||||
return;
|
||||
}
|
||||
Name = C->getRawName();
|
||||
@ -408,19 +415,19 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
if (Increment())
|
||||
return;
|
||||
setFirstRegular(*C);
|
||||
ec = std::error_code();
|
||||
Err = Error::success();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Name[0] != '/') {
|
||||
Format = has64SymTable ? K_MIPS64 : K_GNU;
|
||||
setFirstRegular(*C);
|
||||
ec = std::error_code();
|
||||
Err = Error::success();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Name != "/") {
|
||||
ec = object_error::parse_failed;
|
||||
Err = errorCodeToError(object_error::parse_failed);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -434,7 +441,7 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
|
||||
if (I == E) {
|
||||
setFirstRegular(*C);
|
||||
ec = std::error_code();
|
||||
Err = Error::success();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -449,7 +456,7 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
|
||||
}
|
||||
|
||||
setFirstRegular(*C);
|
||||
ec = std::error_code();
|
||||
Err = Error::success();
|
||||
}
|
||||
|
||||
Archive::child_iterator Archive::child_begin(bool SkipInternal) const {
|
||||
|
@ -42,7 +42,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
|
||||
|
||||
switch (Type) {
|
||||
case sys::fs::file_magic::archive:
|
||||
return errorOrToExpected(Archive::create(Buffer));
|
||||
return Archive::create(Buffer);
|
||||
case sys::fs::file_magic::elf:
|
||||
case sys::fs::file_magic::elf_relocatable:
|
||||
case sys::fs::file_magic::elf_executable:
|
||||
|
@ -96,7 +96,7 @@ MachOUniversalBinary::ObjectForArch::getAsArchive() const {
|
||||
ObjectData = ParentData.substr(Header64.offset, Header64.size);
|
||||
StringRef ObjectName = Parent->getFileName();
|
||||
MemoryBufferRef ObjBuffer(ObjectData, ObjectName);
|
||||
return errorOrToExpected(Archive::create(ObjBuffer));
|
||||
return Archive::create(ObjBuffer);
|
||||
}
|
||||
|
||||
void MachOUniversalBinary::anchor() { }
|
||||
|
@ -159,8 +159,8 @@ BinaryHolder::MapArchiveAndGetMemberBuffers(StringRef Filename,
|
||||
|
||||
for (auto MemRef : ArchiveBuffers) {
|
||||
auto ErrOrArchive = object::Archive::create(MemRef);
|
||||
if (auto Err = ErrOrArchive.getError())
|
||||
return Err;
|
||||
if (!ErrOrArchive)
|
||||
return errorToErrorCode(ErrOrArchive.takeError());
|
||||
CurrentArchives.push_back(std::move(*ErrOrArchive));
|
||||
}
|
||||
return GetArchiveMemberBuffers(Filename, Timestamp);
|
||||
|
@ -511,10 +511,14 @@ int main(int argc, char **argv, char * const *envp) {
|
||||
}
|
||||
std::unique_ptr<MemoryBuffer> &ArBuf = ArBufOrErr.get();
|
||||
|
||||
ErrorOr<std::unique_ptr<object::Archive>> ArOrErr =
|
||||
Expected<std::unique_ptr<object::Archive>> ArOrErr =
|
||||
object::Archive::create(ArBuf->getMemBufferRef());
|
||||
if (std::error_code EC = ArOrErr.getError()) {
|
||||
errs() << EC.message();
|
||||
if (!ArOrErr) {
|
||||
std::string Buf;
|
||||
raw_string_ostream OS(Buf);
|
||||
logAllUnhandledErrors(ArOrErr.takeError(), OS, "");
|
||||
OS.flush();
|
||||
errs() << Buf;
|
||||
return 1;
|
||||
}
|
||||
std::unique_ptr<object::Archive> &Ar = ArOrErr.get();
|
||||
|
@ -713,7 +713,9 @@ static int performOperation(ArchiveOperation Operation,
|
||||
fail("error opening '" + ArchiveName + "': " + EC.message() + "!");
|
||||
|
||||
if (!EC) {
|
||||
object::Archive Archive(Buf.get()->getMemBufferRef(), EC);
|
||||
Error Err;
|
||||
object::Archive Archive(Buf.get()->getMemBufferRef(), Err);
|
||||
EC = errorToErrorCode(std::move(Err));
|
||||
failIfError(EC,
|
||||
"error loading '" + ArchiveName + "': " + EC.message() + "!");
|
||||
performOperation(Operation, &Archive, std::move(Buf.get()), NewMembers);
|
||||
@ -768,7 +770,8 @@ static void runMRIScript() {
|
||||
ArchiveBuffers.push_back(std::move(*BufOrErr));
|
||||
auto LibOrErr =
|
||||
object::Archive::create(ArchiveBuffers.back()->getMemBufferRef());
|
||||
failIfError(LibOrErr.getError(), "Could not parse library");
|
||||
failIfError(errorToErrorCode(LibOrErr.takeError()),
|
||||
"Could not parse library");
|
||||
Archives.push_back(std::move(*LibOrErr));
|
||||
object::Archive &Lib = *Archives.back();
|
||||
for (auto &MemberOrErr : Lib.children()) {
|
||||
|
Loading…
Reference in New Issue
Block a user