[llvm-objdump/MachO] Don't cut'n'paste the same code over and over.

Use the appropriate helper instead.

llvm-svn: 254990
This commit is contained in:
Davide Italiano 2015-12-08 02:45:59 +00:00
parent 7e77ee21fb
commit 6c5eaeb369
3 changed files with 10 additions and 21 deletions

View File

@ -1495,11 +1495,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
printArchiveHeaders(A, !NonVerbose, ArchiveMemberOffsets);
for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
I != E; ++I) {
if (std::error_code EC = I->getError()) {
errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
<< ".\n";
exit(1);
}
if (std::error_code EC = I->getError())
report_error(Filename, EC);
auto &C = I->get();
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (ChildOrErr.getError())
@ -1549,11 +1546,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
for (Archive::child_iterator AI = A->child_begin(),
AE = A->child_end();
AI != AE; ++AI) {
if (std::error_code EC = AI->getError()) {
errs() << "llvm-objdump: '" << Filename
<< "': " << EC.message() << ".\n";
exit(1);
}
if (std::error_code EC = AI->getError())
report_error(Filename, EC);
auto &C = AI->get();
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (ChildOrErr.getError())
@ -1597,11 +1591,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
for (Archive::child_iterator AI = A->child_begin(),
AE = A->child_end();
AI != AE; ++AI) {
if (std::error_code EC = AI->getError()) {
errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
<< ".\n";
exit(1);
}
if (std::error_code EC = AI->getError())
report_error(Filename, EC);
auto &C = AI->get();
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (ChildOrErr.getError())
@ -1639,11 +1630,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
AI != AE; ++AI) {
if (std::error_code EC = AI->getError()) {
errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
<< ".\n";
exit(1);
}
if (std::error_code EC = AI->getError())
report_error(Filename, EC);
auto &C = AI->get();
ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (ChildOrErr.getError())

View File

@ -252,7 +252,7 @@ void llvm::error(std::error_code EC) {
exit(1);
}
static void report_error(StringRef File, std::error_code EC) {
void llvm::report_error(StringRef File, std::error_code EC) {
assert(EC);
errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n";
exit(1);

View File

@ -78,6 +78,7 @@ void PrintRelocations(const object::ObjectFile *o);
void PrintSectionHeaders(const object::ObjectFile *o);
void PrintSectionContents(const object::ObjectFile *o);
void PrintSymbolTable(const object::ObjectFile *o);
void report_error(StringRef File, std::error_code EC);
} // end namespace llvm