summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-01-30 02:49:50 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-01-30 02:49:50 +0000
commit5e812afaeb3db56db706e81e448db46c08298abd (patch)
tree86d091fea3f71879287f607d9f616e410866099c /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent980f2dc4fc9a27fa950f6f9c6baf554aa7cef351 (diff)
downloadbcm5719-llvm-5e812afaeb3db56db706e81e448db46c08298abd.tar.gz
bcm5719-llvm-5e812afaeb3db56db706e81e448db46c08298abd.zip
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. llvm-svn: 200442
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp39
1 files changed, 9 insertions, 30 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 9a56bf9b4c0..325e7006ed8 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -387,18 +387,14 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
error_code EC;
std::map<SectionRef, SmallVector<SectionRef, 1> > SectionRelocMap;
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
- I != E; I.increment(EC)) {
- if (error(EC))
- break;
+ I != E; ++I) {
section_iterator Sec2 = I->getRelocatedSection();
if (Sec2 != Obj->end_sections())
SectionRelocMap[*Sec2].push_back(*I);
}
for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
- I != E; I.increment(EC)) {
- if (error(EC))
- break;
+ I != E; ++I) {
bool Text;
if (error(I->isText(Text)))
break;
@@ -412,7 +408,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
// Make a list of all the symbols in this section.
std::vector<std::pair<uint64_t, StringRef> > Symbols;
for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols();
- SI != SE; SI.increment(EC)) {
+ SI != SE; ++SI) {
bool contains;
if (!error(I->containsSymbol(*SI, contains)) && contains) {
uint64_t Address;
@@ -441,11 +437,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
RelocSec != E; ++RelocSec) {
for (relocation_iterator RI = RelocSec->begin_relocations(),
RE = RelocSec->end_relocations();
- RI != RE; RI.increment(EC)) {
- if (error(EC))
- break;
+ RI != RE; ++RI)
Rels.push_back(*RI);
- }
}
}
@@ -559,11 +552,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
}
static void PrintRelocations(const ObjectFile *o) {
- error_code EC;
for (section_iterator si = o->begin_sections(), se = o->end_sections();
- si != se; si.increment(EC)) {
- if (error(EC))
- return;
+ si != se; ++si) {
if (si->begin_relocations() == si->end_relocations())
continue;
StringRef secname;
@@ -571,10 +561,7 @@ static void PrintRelocations(const ObjectFile *o) {
outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n";
for (relocation_iterator ri = si->begin_relocations(),
re = si->end_relocations();
- ri != re; ri.increment(EC)) {
- if (error(EC))
- return;
-
+ ri != re; ++ri) {
bool hidden;
uint64_t address;
SmallString<32> relocname;
@@ -593,12 +580,9 @@ static void PrintRelocations(const ObjectFile *o) {
static void PrintSectionHeaders(const ObjectFile *o) {
outs() << "Sections:\n"
"Idx Name Size Address Type\n";
- error_code EC;
unsigned i = 0;
for (section_iterator si = o->begin_sections(), se = o->end_sections();
- si != se; si.increment(EC)) {
- if (error(EC))
- return;
+ si != se; ++si) {
StringRef Name;
if (error(si->getName(Name)))
return;
@@ -621,9 +605,7 @@ static void PrintSectionHeaders(const ObjectFile *o) {
static void PrintSectionContents(const ObjectFile *o) {
error_code EC;
for (section_iterator si = o->begin_sections(), se = o->end_sections();
- si != se; si.increment(EC)) {
- if (error(EC))
- return;
+ si != se; ++si) {
StringRef Name;
StringRef Contents;
uint64_t BaseAddr;
@@ -714,11 +696,8 @@ static void PrintSymbolTable(const ObjectFile *o) {
if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o))
PrintCOFFSymbolTable(coff);
else {
- error_code EC;
for (symbol_iterator si = o->begin_symbols(), se = o->end_symbols();
- si != se; si.increment(EC)) {
- if (error(EC))
- return;
+ si != se; ++si) {
StringRef Name;
uint64_t Address;
SymbolRef::Type Type;
OpenPOWER on IntegriCloud