From 6f07b35b8f7cd4e7ad85d25a968db1daa86535ff Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 14 Mar 2014 14:22:49 +0000 Subject: [C++11] Introduce SectionRef::relocations() to use range-based loops Reviewers: rafael Reviewed By: rafael CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3077 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203927 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/COFFDumper.cpp | 42 ++++++++++++++++++-------------------- tools/llvm-readobj/MachODumper.cpp | 35 +++++++++++++++---------------- 2 files changed, 36 insertions(+), 41 deletions(-) (limited to 'tools/llvm-readobj') diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 613cc5b7c9..dfe89d69ec 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -56,7 +56,7 @@ public: private: void printSymbol(symbol_iterator SymI); - void printRelocation(section_iterator SecI, relocation_iterator RelI); + void printRelocation(section_iterator SecI, const RelocationRef &Reloc); void printDataDirectory(uint32_t Index, const std::string &FieldName); void printX64UnwindInfo(); @@ -540,15 +540,12 @@ error_code COFFDumper::getSection( } void COFFDumper::cacheRelocations() { - for (section_iterator SecI = Obj->section_begin(), - SecE = Obj->section_end(); + for (section_iterator SecI = Obj->section_begin(), SecE = Obj->section_end(); SecI != SecE; ++SecI) { const coff_section *Section = Obj->getCOFFSection(SecI); - for (relocation_iterator RelI = SecI->relocation_begin(), - RelE = SecI->relocation_end(); - RelI != RelE; ++RelI) - RelocMap[Section].push_back(*RelI); + for (const RelocationRef &Reloc : SecI->relocations()) + RelocMap[Section].push_back(Reloc); // Sort relocations by address. std::sort(RelocMap[Section].begin(), RelocMap[Section].end(), @@ -844,10 +841,8 @@ void COFFDumper::printSections() { if (opts::SectionRelocations) { ListScope D(W, "Relocations"); - for (relocation_iterator RelI = SecI->relocation_begin(), - RelE = SecI->relocation_end(); - RelI != RelE; ++RelI) - printRelocation(SecI, RelI); + for (const RelocationRef &Reloc : SecI->relocations()) + printRelocation(SecI, Reloc); } if (opts::SectionSymbols) { @@ -888,16 +883,14 @@ void COFFDumper::printRelocations() { continue; bool PrintedGroup = false; - for (relocation_iterator RelI = SecI->relocation_begin(), - RelE = SecI->relocation_end(); - RelI != RelE; ++RelI) { + for (const RelocationRef &Reloc : SecI->relocations()) { if (!PrintedGroup) { W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n"; W.indent(); PrintedGroup = true; } - printRelocation(SecI, RelI); + printRelocation(SecI, Reloc); } if (PrintedGroup) { @@ -908,18 +901,23 @@ void COFFDumper::printRelocations() { } void COFFDumper::printRelocation(section_iterator SecI, - relocation_iterator RelI) { + const RelocationRef &Reloc) { uint64_t Offset; uint64_t RelocType; SmallString<32> RelocName; StringRef SymbolName; StringRef Contents; - if (error(RelI->getOffset(Offset))) return; - if (error(RelI->getType(RelocType))) return; - if (error(RelI->getTypeName(RelocName))) return; - symbol_iterator Symbol = RelI->getSymbol(); - if (error(Symbol->getName(SymbolName))) return; - if (error(SecI->getContents(Contents))) return; + if (error(Reloc.getOffset(Offset))) + return; + if (error(Reloc.getType(RelocType))) + return; + if (error(Reloc.getTypeName(RelocName))) + return; + symbol_iterator Symbol = Reloc.getSymbol(); + if (error(Symbol->getName(SymbolName))) + return; + if (error(SecI->getContents(Contents))) + return; if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index 79a04c81a6..a5f29b9c12 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -40,9 +40,9 @@ public: private: void printSymbol(symbol_iterator SymI); - void printRelocation(relocation_iterator RelI); + void printRelocation(const RelocationRef &Reloc); - void printRelocation(const MachOObjectFile *Obj, relocation_iterator RelI); + void printRelocation(const MachOObjectFile *Obj, const RelocationRef &Reloc); void printSections(const MachOObjectFile *Obj); @@ -249,10 +249,8 @@ void MachODumper::printSections(const MachOObjectFile *Obj) { if (opts::SectionRelocations) { ListScope D(W, "Relocations"); - for (relocation_iterator RelI = Section.relocation_begin(), - RelE = Section.relocation_end(); - RelI != RelE; ++RelI) - printRelocation(RelI); + for (const RelocationRef &Reloc : Section.relocations()) + printRelocation(Reloc); } if (opts::SectionSymbols) { @@ -287,16 +285,14 @@ void MachODumper::printRelocations() { continue; bool PrintedGroup = false; - for (relocation_iterator RelI = Section.relocation_begin(), - RelE = Section.relocation_end(); - RelI != RelE; ++RelI) { + for (const RelocationRef &Reloc : Section.relocations()) { if (!PrintedGroup) { W.startLine() << "Section " << Name << " {\n"; W.indent(); PrintedGroup = true; } - printRelocation(RelI); + printRelocation(Reloc); } if (PrintedGroup) { @@ -306,23 +302,24 @@ void MachODumper::printRelocations() { } } -void MachODumper::printRelocation(relocation_iterator RelI) { - return printRelocation(Obj, RelI); +void MachODumper::printRelocation(const RelocationRef &Reloc) { + return printRelocation(Obj, Reloc); } void MachODumper::printRelocation(const MachOObjectFile *Obj, - relocation_iterator RelI) { + const RelocationRef &Reloc) { uint64_t Offset; SmallString<32> RelocName; StringRef SymbolName; - if (error(RelI->getOffset(Offset))) return; - if (error(RelI->getTypeName(RelocName))) return; - symbol_iterator Symbol = RelI->getSymbol(); - if (Symbol != Obj->symbol_end() && - error(Symbol->getName(SymbolName))) + if (error(Reloc.getOffset(Offset))) + return; + if (error(Reloc.getTypeName(RelocName))) + return; + symbol_iterator Symbol = Reloc.getSymbol(); + if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName))) return; - DataRefImpl DR = RelI->getRawDataRefImpl(); + DataRefImpl DR = Reloc.getRawDataRefImpl(); MachO::any_relocation_info RE = Obj->getRelocation(DR); bool IsScattered = Obj->isRelocationScattered(RE); -- cgit v1.2.3