diff options
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/COFFObjectFile.cpp | 32 | ||||
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 49 | ||||
-rw-r--r-- | llvm/lib/Object/Object.cpp | 13 |
3 files changed, 24 insertions, 70 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index 1558d9d15fd..6439056dfad 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 diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index 2409314e12c..49e3148ac8f 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -275,18 +275,9 @@ static StringRef parseSegmentOrSectionName(const char *P) { // Helper to advance a section or symbol iterator multiple increments at a time. template<class T> -static error_code advance(T &it, size_t Val) { - error_code ec; - while (Val--) { - it.increment(ec); - } - return ec; -} - -template<class T> -static void advanceTo(T &it, size_t Val) { - if (error_code ec = advance(it, Val)) - report_fatal_error(ec.message()); +static void advance(T &it, size_t Val) { + while (Val--) + ++it; } static unsigned getCPUType(const MachOObjectFile *O) { @@ -305,11 +296,9 @@ static void printRelocationTargetName(const MachOObjectFile *O, if (IsScattered) { uint32_t Val = O->getPlainRelocationSymbolNum(RE); - error_code ec; for (symbol_iterator SI = O->begin_symbols(), SE = O->end_symbols(); - SI != SE; SI.increment(ec)) { - if (ec) report_fatal_error(ec.message()); - + SI != SE; ++SI) { + error_code ec; uint64_t Addr; StringRef Name; @@ -325,9 +314,8 @@ static void printRelocationTargetName(const MachOObjectFile *O, // If we couldn't find a symbol that this relocation refers to, try // to find a section beginning instead. for (section_iterator SI = O->begin_sections(), SE = O->end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) report_fatal_error(ec.message()); - + SI != SE; ++SI) { + error_code ec; uint64_t Addr; StringRef Name; @@ -350,12 +338,12 @@ static void printRelocationTargetName(const MachOObjectFile *O, if (isExtern) { symbol_iterator SI = O->begin_symbols(); - advanceTo(SI, Val); + advance(SI, Val); SI->getName(S); } else { section_iterator SI = O->begin_sections(); // Adjust for the fact that sections are 1-indexed. - advanceTo(SI, Val - 1); + advance(SI, Val - 1); SI->getName(S); } @@ -454,14 +442,11 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, } } -error_code MachOObjectFile::getSymbolNext(DataRefImpl Symb, - SymbolRef &Res) const { +void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const { unsigned SymbolTableEntrySize = is64Bit() ? sizeof(MachO::nlist_64) : sizeof(MachO::nlist); Symb.p += SymbolTableEntrySize; - Res = SymbolRef(Symb, this); - return object_error::success; } error_code MachOObjectFile::getSymbolName(DataRefImpl Symb, @@ -545,9 +530,7 @@ error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI, } // Unfortunately symbols are unsorted so we need to touch all // symbols from load command - error_code ec; - for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E; - I.increment(ec)) { + for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E; ++I) { DataRefImpl DRI = I->getRawDataRefImpl(); Entry = getSymbolTableEntryBase(this, DRI); getSymbolAddress(DRI, Value); @@ -648,11 +631,8 @@ error_code MachOObjectFile::getSymbolValue(DataRefImpl Symb, report_fatal_error("getSymbolValue unimplemented in MachOObjectFile"); } -error_code MachOObjectFile::getSectionNext(DataRefImpl Sec, - SectionRef &Res) const { +void MachOObjectFile::moveSectionNext(DataRefImpl &Sec) const { Sec.d.a++; - Res = SectionRef(Sec, this); - return object_error::success; } error_code @@ -834,13 +814,10 @@ MachOObjectFile::section_rel_end(DataRefImpl Sec) const { return relocation_iterator(RelocationRef(Ret, this)); } -error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel, - RelocationRef &Res) const { +void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const { const MachO::any_relocation_info *P = reinterpret_cast<const MachO::any_relocation_info *>(Rel.p); Rel.p = reinterpret_cast<uintptr_t>(P + 1); - Res = RelocationRef(Rel, this); - return object_error::success; } error_code diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp index e454d8eec79..399d460f8ce 100644 --- a/llvm/lib/Object/Object.cpp +++ b/llvm/lib/Object/Object.cpp @@ -84,9 +84,7 @@ LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, } void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) { - error_code ec; - unwrap(SI)->increment(ec); - if (ec) report_fatal_error("LLVMMoveToNextSection failed: " + ec.message()); + ++(*unwrap(SI)); } void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, @@ -111,9 +109,7 @@ LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, } void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) { - error_code ec; - unwrap(SI)->increment(ec); - if (ec) report_fatal_error("LLVMMoveToNextSymbol failed: " + ec.message()); + ++(*unwrap(SI)); } // SectionRef accessors @@ -169,10 +165,7 @@ LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, } void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) { - error_code ec; - unwrap(SI)->increment(ec); - if (ec) report_fatal_error("LLVMMoveToNextRelocation failed: " + - ec.message()); + ++(*unwrap(SI)); } |