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
This commit is contained in:
Rafael Espindola
2014-01-30 02:49:50 +00:00
parent 6bf3966f7f
commit efdbec8b0a
25 changed files with 147 additions and 365 deletions

View File

@@ -87,13 +87,10 @@ const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const {
return Addr;
}
error_code COFFObjectFile::getSymbolNext(DataRefImpl Ref,
SymbolRef &Result) const {
void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const {
const coff_symbol *Symb = toSymb(Ref);
Symb += 1 + Symb->NumberOfAuxSymbols;
Ref.p = reinterpret_cast<uintptr_t>(Symb);
Result = SymbolRef(Ref, this);
return object_error::success;
}
error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
@@ -221,13 +218,10 @@ error_code COFFObjectFile::getSymbolValue(DataRefImpl Ref,
report_fatal_error("getSymbolValue unimplemented in COFFObjectFile");
}
error_code COFFObjectFile::getSectionNext(DataRefImpl Ref,
SectionRef &Result) const {
void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const {
const coff_section *Sec = toSec(Ref);
Sec += 1;
Ref.p = reinterpret_cast<uintptr_t>(Sec);
Result = SectionRef(Ref, this);
return object_error::success;
}
error_code COFFObjectFile::getSectionName(DataRefImpl Ref,
@@ -386,11 +380,8 @@ error_code COFFObjectFile::initSymbolTablePtr() {
// Returns the file offset for the given RVA.
error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const {
error_code EC;
for (section_iterator I = begin_sections(), E = end_sections(); I != E;
I.increment(EC)) {
if (EC)
return EC;
++I) {
const coff_section *Section = getCOFFSection(I);
uint32_t SectionStart = Section->VirtualAddress;
uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
@@ -801,12 +792,9 @@ const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
return reinterpret_cast<const coff_relocation*>(Rel.p);
}
error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
RelocationRef &Res) const {
void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
Rel.p = reinterpret_cast<uintptr_t>(
reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
Res = RelocationRef(Rel, this);
return object_error::success;
}
error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
@@ -932,10 +920,8 @@ operator==(const ImportDirectoryEntryRef &Other) const {
return ImportTable == Other.ImportTable && Index == Other.Index;
}
error_code
ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const {
Result = ImportDirectoryEntryRef(ImportTable, Index + 1, OwningObject);
return object_error::success;
void ImportDirectoryEntryRef::moveNext() {
++Index;
}
error_code ImportDirectoryEntryRef::
@@ -967,10 +953,8 @@ operator==(const ExportDirectoryEntryRef &Other) const {
return ExportTable == Other.ExportTable && Index == Other.Index;
}
error_code
ExportDirectoryEntryRef::getNext(ExportDirectoryEntryRef &Result) const {
Result = ExportDirectoryEntryRef(ExportTable, Index + 1, OwningObject);
return object_error::success;
void ExportDirectoryEntryRef::moveNext() {
++Index;
}
// Returns the name of the current export symbol. If the symbol is exported only