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 | 5e812afaeb3db56db706e81e448db46c08298abd (patch) | |
tree | 86d091fea3f71879287f607d9f616e410866099c /llvm/lib/Object/COFFObjectFile.cpp | |
parent | 980f2dc4fc9a27fa950f6f9c6baf554aa7cef351 (diff) | |
download | llvm-5e812afaeb3db56db706e81e448db46c08298abd.zip llvm-5e812afaeb3db56db706e81e448db46c08298abd.tar.gz llvm-5e812afaeb3db56db706e81e448db46c08298abd.tar.bz2 |
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/lib/Object/COFFObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index 1558d9d..6439056 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -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 |