[llvm] r204120 - [C++11] Change the interface of getCOFF{Section, Relocation, Symbol} to make it work with range-based for loops.
Alexey Samsonov
samsonov at google.com
Mon Mar 17 23:53:02 PDT 2014
Author: samsonov
Date: Tue Mar 18 01:53:02 2014
New Revision: 204120
URL: http://llvm.org/viewvc/llvm-project?rev=204120&view=rev
Log:
[C++11] Change the interface of getCOFF{Section,Relocation,Symbol} to make it work with range-based for loops.
Reviewers: ruiu
Reviewed By: ruiu
CC: llvm-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D3097
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
llvm/trunk/tools/llvm-objdump/COFFDump.cpp
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
llvm/trunk/tools/obj2yaml/coff2yaml.cpp
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=204120&r1=204119&r2=204120&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Tue Mar 18 01:53:02 2014
@@ -356,9 +356,9 @@ public:
section_iterator section_begin() const override;
section_iterator section_end() const override;
- const coff_section *getCOFFSection(section_iterator &It) const;
- const coff_symbol *getCOFFSymbol(symbol_iterator &It) const;
- const coff_relocation *getCOFFRelocation(relocation_iterator &It) const;
+ const coff_section *getCOFFSection(const SectionRef &Section) const;
+ const coff_symbol *getCOFFSymbol(const SymbolRef &Symbol) const;
+ const coff_relocation *getCOFFRelocation(const RelocationRef &Reloc) const;
uint8_t getBytesInAddress() const override;
StringRef getFileFormatName() const override;
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=204120&r1=204119&r2=204120&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Tue Mar 18 01:53:02 2014
@@ -431,9 +431,8 @@ error_code COFFObjectFile::getVaPtr(uint
// Returns the file offset for the given RVA.
error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const {
- for (section_iterator I = section_begin(), E = section_end(); I != E;
- ++I) {
- const coff_section *Section = getCOFFSection(I);
+ for (const SectionRef &S : sections()) {
+ const coff_section *Section = getCOFFSection(S);
uint32_t SectionStart = Section->VirtualAddress;
uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
if (SectionStart <= Addr && Addr < SectionEnd) {
@@ -872,21 +871,25 @@ error_code COFFObjectFile::getRelocation
return object_error::success;
}
-const coff_section *COFFObjectFile::getCOFFSection(section_iterator &It) const {
- return toSec(It->getRawDataRefImpl());
+const coff_section *
+COFFObjectFile::getCOFFSection(const SectionRef &Section) const {
+ return toSec(Section.getRawDataRefImpl());
}
-const coff_symbol *COFFObjectFile::getCOFFSymbol(symbol_iterator &It) const {
- return toSymb(It->getRawDataRefImpl());
+const coff_symbol *
+COFFObjectFile::getCOFFSymbol(const SymbolRef &Symbol) const {
+ return toSymb(Symbol.getRawDataRefImpl());
}
const coff_relocation *
-COFFObjectFile::getCOFFRelocation(relocation_iterator &It) const {
- return toRel(It->getRawDataRefImpl());
+COFFObjectFile::getCOFFRelocation(const RelocationRef &Reloc) const {
+ return toRel(Reloc.getRawDataRefImpl());
}
-#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \
- case COFF::enum: Res = #enum; break;
+#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type) \
+ case COFF::reloc_type: \
+ Res = #reloc_type; \
+ break;
error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const {
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=204120&r1=204119&r2=204120&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Tue Mar 18 01:53:02 2014
@@ -300,7 +300,7 @@ static char getSymbolNMTypeChar(ELFObjec
}
static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {
- const coff_symbol *Symb = Obj.getCOFFSymbol(I);
+ const coff_symbol *Symb = Obj.getCOFFSymbol(*I);
// OK, this is COFF.
symbol_iterator SymI(I);
@@ -323,7 +323,7 @@ static char getSymbolNMTypeChar(COFFObje
section_iterator SecI = Obj.section_end();
if (error(SymI->getSection(SecI)))
return '?';
- const coff_section *Section = Obj.getCOFFSection(SecI);
+ const coff_section *Section = Obj.getCOFFSection(*SecI);
Characteristics = Section->Characteristics;
}
Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=204120&r1=204119&r2=204120&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Tue Mar 18 01:53:02 2014
@@ -166,7 +166,7 @@ static error_code resolveSectionAndAddre
section_iterator iter(Obj->section_begin());
if (error_code EC = Sym.getSection(iter))
return EC;
- ResolvedSection = Obj->getCOFFSection(iter);
+ ResolvedSection = Obj->getCOFFSection(*iter);
return object_error::success;
}
@@ -381,16 +381,15 @@ static void printExportTable(const COFFO
static bool getPDataSection(const COFFObjectFile *Obj,
std::vector<RelocationRef> &Rels,
const RuntimeFunction *&RFStart, int &NumRFs) {
- for (section_iterator SI = Obj->section_begin(), SE = Obj->section_end();
- SI != SE; ++SI) {
+ for (const SectionRef &Section : Obj->sections()) {
StringRef Name;
- if (error(SI->getName(Name)))
+ if (error(Section.getName(Name)))
continue;
if (Name != ".pdata")
continue;
- const coff_section *Pdata = Obj->getCOFFSection(SI);
- for (const RelocationRef &Reloc : SI->relocations())
+ const coff_section *Pdata = Obj->getCOFFSection(Section);
+ for (const RelocationRef &Reloc : Section.relocations())
Rels.push_back(Reloc);
// Sort relocations by address.
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=204120&r1=204119&r2=204120&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Tue Mar 18 01:53:02 2014
@@ -55,8 +55,8 @@ public:
virtual void printUnwindInfo() override;
private:
- void printSymbol(symbol_iterator SymI);
- void printRelocation(section_iterator SecI, const RelocationRef &Reloc);
+ void printSymbol(const SymbolRef &Sym);
+ void printRelocation(const SectionRef &Section, const RelocationRef &Reloc);
void printDataDirectory(uint32_t Index, const std::string &FieldName);
void printX64UnwindInfo();
@@ -74,9 +74,9 @@ private:
uint64_t OffsetInSection,
const std::vector<RelocationRef> &Rels);
- void printUnwindCode(const Win64EH::UnwindInfo& UI, ArrayRef<UnwindCode> UCs);
+ void printUnwindCode(const Win64EH::UnwindInfo &UI, ArrayRef<UnwindCode> UCs);
- void printCodeViewLineTables(section_iterator SecI);
+ void printCodeViewLineTables(const SectionRef &Section);
void cacheRelocations();
@@ -188,7 +188,7 @@ static error_code resolveSectionAndAddre
if (error_code EC = Sym.getSection(iter))
return EC;
- ResolvedSection = Obj->getCOFFSection(iter);
+ ResolvedSection = Obj->getCOFFSection(*iter);
return object_error::success;
}
@@ -540,11 +540,10 @@ error_code COFFDumper::getSection(
}
void COFFDumper::cacheRelocations() {
- for (section_iterator SecI = Obj->section_begin(), SecE = Obj->section_end();
- SecI != SecE; ++SecI) {
- const coff_section *Section = Obj->getCOFFSection(SecI);
+ for (const SectionRef &S : Obj->sections()) {
+ const coff_section *Section = Obj->getCOFFSection(S);
- for (const RelocationRef &Reloc : SecI->relocations())
+ for (const RelocationRef &Reloc : S.relocations())
RelocMap[Section].push_back(Reloc);
// Sort relocations by address.
@@ -653,9 +652,10 @@ void COFFDumper::printBaseOfDataField(co
void COFFDumper::printBaseOfDataField(const pe32plus_header *) {}
-void COFFDumper::printCodeViewLineTables(section_iterator SecI) {
+void COFFDumper::printCodeViewLineTables(const SectionRef &Section) {
StringRef Data;
- if (error(SecI->getContents(Data))) return;
+ if (error(Section.getContents(Data)))
+ return;
SmallVector<StringRef, 10> FunctionNames;
StringMap<StringRef> FunctionLineTables;
@@ -706,8 +706,8 @@ void COFFDumper::printCodeViewLineTables
}
StringRef FunctionName;
- if (error(resolveSymbolName(RelocMap[Obj->getCOFFSection(SecI)], Offset,
- FunctionName)))
+ if (error(resolveSymbolName(RelocMap[Obj->getCOFFSection(Section)],
+ Offset, FunctionName)))
return;
W.printString("FunctionName", FunctionName);
if (FunctionLineTables.count(FunctionName) != 0) {
@@ -814,15 +814,13 @@ void COFFDumper::printCodeViewLineTables
void COFFDumper::printSections() {
ListScope SectionsD(W, "Sections");
int SectionNumber = 0;
- for (section_iterator SecI = Obj->section_begin(),
- SecE = Obj->section_end();
- SecI != SecE; ++SecI) {
+ for (const SectionRef &Sec : Obj->sections()) {
++SectionNumber;
- const coff_section *Section = Obj->getCOFFSection(SecI);
+ const coff_section *Section = Obj->getCOFFSection(Sec);
StringRef Name;
- if (error(SecI->getName(Name)))
- Name = "";
+ if (error(Sec.getName(Name)))
+ Name = "";
DictScope D(W, "Section");
W.printNumber("Number", SectionNumber);
@@ -841,29 +839,28 @@ void COFFDumper::printSections() {
if (opts::SectionRelocations) {
ListScope D(W, "Relocations");
- for (const RelocationRef &Reloc : SecI->relocations())
- printRelocation(SecI, Reloc);
+ for (const RelocationRef &Reloc : Sec.relocations())
+ printRelocation(Sec, Reloc);
}
if (opts::SectionSymbols) {
ListScope D(W, "Symbols");
- for (symbol_iterator SymI = Obj->symbol_begin(),
- SymE = Obj->symbol_end();
- SymI != SymE; ++SymI) {
+ for (const SymbolRef &Symbol : Obj->symbols()) {
bool Contained = false;
- if (SecI->containsSymbol(*SymI, Contained) || !Contained)
+ if (Sec.containsSymbol(Symbol, Contained) || !Contained)
continue;
- printSymbol(SymI);
+ printSymbol(Symbol);
}
}
if (Name == ".debug$S" && opts::CodeViewLineTables)
- printCodeViewLineTables(SecI);
+ printCodeViewLineTables(Sec);
if (opts::SectionData) {
StringRef Data;
- if (error(SecI->getContents(Data))) break;
+ if (error(Sec.getContents(Data)))
+ break;
W.printBinaryBlock("SectionData", Data);
}
@@ -874,23 +871,21 @@ void COFFDumper::printRelocations() {
ListScope D(W, "Relocations");
int SectionNumber = 0;
- for (section_iterator SecI = Obj->section_begin(),
- SecE = Obj->section_end();
- SecI != SecE; ++SecI) {
+ for (const SectionRef &Section : Obj->sections()) {
++SectionNumber;
StringRef Name;
- if (error(SecI->getName(Name)))
+ if (error(Section.getName(Name)))
continue;
bool PrintedGroup = false;
- for (const RelocationRef &Reloc : SecI->relocations()) {
+ for (const RelocationRef &Reloc : Section.relocations()) {
if (!PrintedGroup) {
W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n";
W.indent();
PrintedGroup = true;
}
- printRelocation(SecI, Reloc);
+ printRelocation(Section, Reloc);
}
if (PrintedGroup) {
@@ -900,7 +895,7 @@ void COFFDumper::printRelocations() {
}
}
-void COFFDumper::printRelocation(section_iterator SecI,
+void COFFDumper::printRelocation(const SectionRef &Section,
const RelocationRef &Reloc) {
uint64_t Offset;
uint64_t RelocType;
@@ -916,7 +911,7 @@ void COFFDumper::printRelocation(section
symbol_iterator Symbol = Reloc.getSymbol();
if (error(Symbol->getName(SymbolName)))
return;
- if (error(SecI->getContents(Contents)))
+ if (error(Section.getContents(Contents)))
return;
if (opts::ExpandRelocs) {
@@ -936,19 +931,16 @@ void COFFDumper::printRelocation(section
void COFFDumper::printSymbols() {
ListScope Group(W, "Symbols");
- for (symbol_iterator SymI = Obj->symbol_begin(), SymE = Obj->symbol_end();
- SymI != SymE; ++SymI)
- printSymbol(SymI);
+ for (const SymbolRef &Symbol : Obj->symbols())
+ printSymbol(Symbol);
}
-void COFFDumper::printDynamicSymbols() {
- ListScope Group(W, "DynamicSymbols");
-}
+void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); }
-void COFFDumper::printSymbol(symbol_iterator SymI) {
+void COFFDumper::printSymbol(const SymbolRef &Sym) {
DictScope D(W, "Symbol");
- const coff_symbol *Symbol = Obj->getCOFFSymbol(SymI);
+ const coff_symbol *Symbol = Obj->getCOFFSymbol(Sym);
const coff_section *Section;
if (error_code EC = Obj->getSection(Symbol->SectionNumber, Section)) {
W.startLine() << "Invalid section number: " << EC.message() << "\n";
@@ -1095,20 +1087,17 @@ void COFFDumper::printUnwindInfo() {
}
void COFFDumper::printX64UnwindInfo() {
- for (section_iterator SecI = Obj->section_begin(),
- SecE = Obj->section_end();
- SecI != SecE; ++SecI) {
+ for (const SectionRef &Section : Obj->sections()) {
StringRef Name;
- if (error(SecI->getName(Name)))
+ if (error(Section.getName(Name)))
continue;
if (Name != ".pdata" && !Name.startswith(".pdata$"))
continue;
- const coff_section *PData = Obj->getCOFFSection(SecI);
+ const coff_section *PData = Obj->getCOFFSection(Section);
ArrayRef<uint8_t> Contents;
- if (error(Obj->getSectionContents(PData, Contents)) ||
- Contents.empty())
+ if (error(Obj->getSectionContents(PData, Contents)) || Contents.empty())
continue;
ArrayRef<RuntimeFunction> RFs(
Modified: llvm/trunk/tools/obj2yaml/coff2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/coff2yaml.cpp?rev=204120&r1=204119&r2=204120&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/coff2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/coff2yaml.cpp Tue Mar 18 01:53:02 2014
@@ -51,9 +51,8 @@ void COFFDumper::dumpHeader(const object
void COFFDumper::dumpSections(unsigned NumSections) {
std::vector<COFFYAML::Section> &Sections = YAMLObj.Sections;
- for (object::section_iterator iter = Obj.section_begin();
- iter != Obj.section_end(); ++iter) {
- const object::coff_section *Sect = Obj.getCOFFSection(iter);
+ for (const auto &Section : Obj.sections()) {
+ const object::coff_section *Sect = Obj.getCOFFSection(Section);
COFFYAML::Section Sec;
Sec.Name = Sect->Name; // FIXME: check the null termination!
uint32_t Characteristics = Sect->Characteristics;
@@ -65,11 +64,10 @@ void COFFDumper::dumpSections(unsigned N
Sec.SectionData = object::yaml::BinaryRef(sectionData);
std::vector<COFFYAML::Relocation> Relocations;
- for (object::relocation_iterator rIter = iter->relocation_begin();
- rIter != iter->relocation_end(); ++rIter) {
- const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
+ for (const auto &Reloc : Section.relocations()) {
+ const object::coff_relocation *reloc = Obj.getCOFFRelocation(Reloc);
COFFYAML::Relocation Rel;
- object::symbol_iterator Sym = rIter->getSymbol();
+ object::symbol_iterator Sym = Reloc.getSymbol();
Sym->getName(Rel.SymbolName);
Rel.VirtualAddress = reloc->VirtualAddress;
Rel.Type = reloc->Type;
@@ -82,9 +80,8 @@ void COFFDumper::dumpSections(unsigned N
void COFFDumper::dumpSymbols(unsigned NumSymbols) {
std::vector<COFFYAML::Symbol> &Symbols = YAMLObj.Symbols;
- for (object::symbol_iterator iter = Obj.symbol_begin();
- iter != Obj.symbol_end(); ++iter) {
- const object::coff_symbol *Symbol = Obj.getCOFFSymbol(iter);
+ for (const auto &S : Obj.symbols()) {
+ const object::coff_symbol *Symbol = Obj.getCOFFSymbol(S);
COFFYAML::Symbol Sym;
Obj.getSymbolName(Symbol, Sym.Name);
Sym.SimpleType = COFF::SymbolBaseType(Symbol->getBaseType());
More information about the llvm-commits
mailing list