mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
Convert a few methods to use ErrorOr.
It used to be inconvenient to mix ErrorOr and UniquePtr, but with c++11 they work OK together. llvm-svn: 211532
This commit is contained in:
parent
dd8e45c6d7
commit
e0f3ded593
@ -57,7 +57,7 @@ public:
|
||||
return Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
|
||||
}
|
||||
|
||||
std::error_code getAsObjectFile(std::unique_ptr<ObjectFile> &Result) const;
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> getAsObjectFile() const;
|
||||
|
||||
std::error_code getAsArchive(std::unique_ptr<Archive> &Result) const;
|
||||
};
|
||||
@ -100,8 +100,8 @@ public:
|
||||
return V->isMachOUniversalBinary();
|
||||
}
|
||||
|
||||
std::error_code getObjectForArch(Triple::ArchType Arch,
|
||||
std::unique_ptr<ObjectFile> &Result) const;
|
||||
ErrorOr<std::unique_ptr<ObjectFile>>
|
||||
getObjectForArch(Triple::ArchType Arch) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -67,19 +67,15 @@ MachOUniversalBinary::ObjectForArch::ObjectForArch(
|
||||
}
|
||||
}
|
||||
|
||||
std::error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile(
|
||||
std::unique_ptr<ObjectFile> &Result) const {
|
||||
ErrorOr<std::unique_ptr<ObjectFile>>
|
||||
MachOUniversalBinary::ObjectForArch::getAsObjectFile() const {
|
||||
if (Parent) {
|
||||
StringRef ParentData = Parent->getData();
|
||||
StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
|
||||
std::string ObjectName = Parent->getFileName().str();
|
||||
MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer(
|
||||
ObjectData, ObjectName, false);
|
||||
ErrorOr<ObjectFile *> Obj = ObjectFile::createMachOObjectFile(ObjBuffer);
|
||||
if (std::error_code EC = Obj.getError())
|
||||
return EC;
|
||||
Result.reset(Obj.get());
|
||||
return object_error::success;
|
||||
return ObjectFile::createMachOObjectFile(ObjBuffer);
|
||||
}
|
||||
return object_error::parse_failed;
|
||||
}
|
||||
@ -145,14 +141,14 @@ static bool getCTMForArch(Triple::ArchType Arch, MachO::CPUType &CTM) {
|
||||
}
|
||||
}
|
||||
|
||||
std::error_code MachOUniversalBinary::getObjectForArch(
|
||||
Triple::ArchType Arch, std::unique_ptr<ObjectFile> &Result) const {
|
||||
ErrorOr<std::unique_ptr<ObjectFile>>
|
||||
MachOUniversalBinary::getObjectForArch(Triple::ArchType Arch) const {
|
||||
MachO::CPUType CTM;
|
||||
if (!getCTMForArch(Arch, CTM))
|
||||
return object_error::arch_not_found;
|
||||
for (object_iterator I = begin_objects(), E = end_objects(); I != E; ++I) {
|
||||
if (I->getCPUType() == static_cast<uint32_t>(CTM))
|
||||
return I->getAsObjectFile(Result);
|
||||
return I->getAsObjectFile();
|
||||
}
|
||||
return object_error::arch_not_found;
|
||||
}
|
||||
|
@ -773,9 +773,10 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
|
||||
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
|
||||
E = UB->end_objects();
|
||||
I != E; ++I) {
|
||||
std::unique_ptr<ObjectFile> Obj;
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr = I->getAsObjectFile();
|
||||
std::unique_ptr<Archive> A;
|
||||
if (!I->getAsObjectFile(Obj)) {
|
||||
if (ObjOrErr) {
|
||||
std::unique_ptr<ObjectFile> Obj = std::move(ObjOrErr.get());
|
||||
if (moreThanOneArch)
|
||||
outs() << "\n";
|
||||
outs() << Obj->getFileName();
|
||||
|
@ -466,9 +466,9 @@ static void PrintFileSectionSizes(StringRef file) {
|
||||
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
|
||||
E = UB->end_objects();
|
||||
I != E; ++I) {
|
||||
std::unique_ptr<ObjectFile> UO;
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> UO = I->getAsObjectFile();
|
||||
std::unique_ptr<Archive> UA;
|
||||
if (!I->getAsObjectFile(UO)) {
|
||||
if (UO) {
|
||||
if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
|
||||
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
|
||||
if (OutputFormat == sysv)
|
||||
|
@ -349,10 +349,11 @@ LLVMSymbolizer::getObjectFileFromBinary(Binary *Bin, const std::string &ArchName
|
||||
std::make_pair(UB, ArchName));
|
||||
if (I != ObjectFileForArch.end())
|
||||
return I->second;
|
||||
std::unique_ptr<ObjectFile> ParsedObj;
|
||||
if (!UB->getObjectForArch(Triple(ArchName).getArch(), ParsedObj)) {
|
||||
Res = ParsedObj.get();
|
||||
ParsedBinariesAndObjects.push_back(std::move(ParsedObj));
|
||||
ErrorOr<std::unique_ptr<ObjectFile>> ParsedObj =
|
||||
UB->getObjectForArch(Triple(ArchName).getArch());
|
||||
if (ParsedObj) {
|
||||
Res = ParsedObj.get().get();
|
||||
ParsedBinariesAndObjects.push_back(std::move(ParsedObj.get()));
|
||||
}
|
||||
ObjectFileForArch[std::make_pair(UB, ArchName)] = Res;
|
||||
} else if (Bin->isObject()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user