diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-30 02:49:50 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-30 02:49:50 +0000 |
commit | efdbec8b0a49fb67c3844be703548fdc6c1dded0 (patch) | |
tree | 040894fc0c18d09dfdfec8693a253bcf998cb8c5 /tools/llvm-readobj | |
parent | 6bf3966f7fd92217360877d1c04ea8ffe47c11cc (diff) |
Simplify the handling of iterators in ObjectFile.
None of the object file formats reported error on iterator increment. In
retrospect, that is not too surprising: no object format stores symbols or
sections in a linked list or other structure that requires chasing pointers.
As a consequence, all error checking can be done on begin() and end().
This reduces the text segment of bin/llvm-readobj in my machine from 521233 to
518526 bytes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200442 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-readobj')
-rw-r--r-- | tools/llvm-readobj/COFFDumper.cpp | 52 | ||||
-rw-r--r-- | tools/llvm-readobj/MachODumper.cpp | 30 |
2 files changed, 17 insertions, 65 deletions
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 803e3f67330..08153ebd047 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -541,23 +541,15 @@ error_code COFFDumper::getSection( } void COFFDumper::cacheRelocations() { - error_code EC; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) - break; - + SecI != SecE; ++SecI) { const coff_section *Section = Obj->getCOFFSection(SecI); for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) - break; - + RelI != RelE; ++RelI) RelocMap[Section].push_back(*RelI); - } // Sort relocations by address. std::sort(RelocMap[Section].begin(), RelocMap[Section].end(), @@ -824,16 +816,11 @@ void COFFDumper::printCodeViewLineTables(section_iterator SecI) { } void COFFDumper::printSections() { - error_code EC; - ListScope SectionsD(W, "Sections"); int SectionNumber = 0; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) - break; - + SecI != SecE; ++SecI) { ++SectionNumber; const coff_section *Section = Obj->getCOFFSection(SecI); @@ -860,20 +847,15 @@ void COFFDumper::printSections() { ListScope D(W, "Relocations"); for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) break; - + RelI != RelE; ++RelI) printRelocation(SecI, RelI); - } } if (opts::SectionSymbols) { ListScope D(W, "Symbols"); for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols(); - SymI != SymE; SymI.increment(EC)) { - if (error(EC)) break; - + SymI != SymE; ++SymI) { bool Contained = false; if (SecI->containsSymbol(*SymI, Contained) || !Contained) continue; @@ -897,15 +879,11 @@ void COFFDumper::printSections() { void COFFDumper::printRelocations() { ListScope D(W, "Relocations"); - error_code EC; int SectionNumber = 0; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { + SecI != SecE; ++SecI) { ++SectionNumber; - if (error(EC)) - break; - StringRef Name; if (error(SecI->getName(Name))) continue; @@ -913,9 +891,7 @@ void COFFDumper::printRelocations() { bool PrintedGroup = false; for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) break; - + RelI != RelE; ++RelI) { if (!PrintedGroup) { W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n"; W.indent(); @@ -963,14 +939,9 @@ void COFFDumper::printRelocation(section_iterator SecI, void COFFDumper::printSymbols() { ListScope Group(W, "Symbols"); - error_code EC; - for (symbol_iterator SymI = Obj->begin_symbols(), - SymE = Obj->end_symbols(); - SymI != SymE; SymI.increment(EC)) { - if (error(EC)) break; - + for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols(); + SymI != SymE; ++SymI) printSymbol(SymI); - } } void COFFDumper::printDynamicSymbols() { @@ -1116,12 +1087,9 @@ void COFFDumper::printUnwindInfo() { } void COFFDumper::printX64UnwindInfo() { - error_code EC; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) break; - + SecI != SecE; ++SecI) { StringRef Name; if (error(SecI->getName(Name))) continue; diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index 6626f4082f8..af76901a3f1 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -222,12 +222,9 @@ void MachODumper::printSections(const MachOObjectFile *Obj) { ListScope Group(W, "Sections"); int SectionIndex = -1; - error_code EC; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) break; - + SecI != SecE; ++SecI) { ++SectionIndex; MachOSection Section; @@ -263,20 +260,15 @@ void MachODumper::printSections(const MachOObjectFile *Obj) { ListScope D(W, "Relocations"); for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) break; - + RelI != RelE; ++RelI) printRelocation(SecI, RelI); - } } if (opts::SectionSymbols) { ListScope D(W, "Symbols"); for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols(); - SymI != SymE; SymI.increment(EC)) { - if (error(EC)) break; - + SymI != SymE; ++SymI) { bool Contained = false; if (SecI->containsSymbol(*SymI, Contained) || !Contained) continue; @@ -300,9 +292,7 @@ void MachODumper::printRelocations() { error_code EC; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) break; - + SecI != SecE; ++SecI) { StringRef Name; if (error(SecI->getName(Name))) continue; @@ -310,9 +300,7 @@ void MachODumper::printRelocations() { bool PrintedGroup = false; for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) break; - + RelI != RelE; ++RelI) { if (!PrintedGroup) { W.startLine() << "Section " << Name << " {\n"; W.indent(); @@ -382,12 +370,8 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj, void MachODumper::printSymbols() { ListScope Group(W, "Symbols"); - error_code EC; - for (symbol_iterator SymI = Obj->begin_symbols(), - SymE = Obj->end_symbols(); - SymI != SymE; SymI.increment(EC)) { - if (error(EC)) break; - + for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols(); + SymI != SymE; ++SymI) { printSymbol(SymI); } } |