diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index c643dbacb0f..75857c954d8 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -600,6 +600,11 @@ public: export_directory_iterator export_directory_begin() const; export_directory_iterator export_directory_end() const; + iterator_range import_directories() const; + iterator_range + delay_import_directories() const; + iterator_range export_directories() const; + std::error_code getPE32Header(const pe32_header *&Res) const; std::error_code getPE32PlusHeader(const pe32plus_header *&Res) const; std::error_code getDataDirectory(uint32_t index, @@ -676,6 +681,7 @@ public: imported_symbol_iterator imported_symbol_begin() const; imported_symbol_iterator imported_symbol_end() const; + iterator_range imported_symbols() const; std::error_code getName(StringRef &Result) const; std::error_code getImportLookupTableRVA(uint32_t &Result) const; @@ -705,6 +711,7 @@ public: imported_symbol_iterator imported_symbol_begin() const; imported_symbol_iterator imported_symbol_end() const; + iterator_range imported_symbols() const; std::error_code getName(StringRef &Result) const; std::error_code getDelayImportTable( diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index ebf24a931ce..adc68ec62c5 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -730,6 +730,22 @@ unsigned COFFObjectFile::getArch() const { } } +iterator_range +COFFObjectFile::import_directories() const { + return make_range(import_directory_begin(), import_directory_end()); +} + +iterator_range +COFFObjectFile::delay_import_directories() const { + return make_range(delay_import_directory_begin(), + delay_import_directory_end()); +} + +iterator_range +COFFObjectFile::export_directories() const { + return make_range(export_directory_begin(), export_directory_end()); +} + std::error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const { Res = PE32Header; return object_error::success; @@ -1094,6 +1110,11 @@ ImportDirectoryEntryRef::imported_symbol_end() const { OwningObject); } +iterator_range +ImportDirectoryEntryRef::imported_symbols() const { + return make_range(imported_symbol_begin(), imported_symbol_end()); +} + std::error_code ImportDirectoryEntryRef::getName(StringRef &Result) const { uintptr_t IntPtr = 0; if (std::error_code EC = @@ -1146,6 +1167,11 @@ DelayImportDirectoryEntryRef::imported_symbol_end() const { OwningObject); } +iterator_range +DelayImportDirectoryEntryRef::imported_symbols() const { + return make_range(imported_symbol_begin(), imported_symbol_end()); +} + std::error_code DelayImportDirectoryEntryRef::getName(StringRef &Result) const { uintptr_t IntPtr = 0; if (std::error_code EC = OwningObject->getRvaPtr(Table[Index].Name, IntPtr)) diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 6d04c0e989c..dc280a634dc 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -75,9 +75,7 @@ private: SymbolRef &Sym); std::error_code resolveSymbolName(const coff_section *Section, uint64_t Offset, StringRef &Name); - - void printImportedSymbols(imported_symbol_iterator I, - imported_symbol_iterator E); + void printImportedSymbols(iterator_range Range); typedef DenseMap > RelocMapTy; @@ -886,50 +884,47 @@ void COFFDumper::printUnwindInfo() { } } -void COFFDumper::printImportedSymbols(imported_symbol_iterator I, - imported_symbol_iterator E) { - for (; I != E; ++I) { +void COFFDumper::printImportedSymbols( + iterator_range Range) { + for (const ImportedSymbolRef &I : Range) { StringRef Sym; - if (error(I->getSymbolName(Sym))) return; + if (error(I.getSymbolName(Sym))) return; uint16_t Ordinal; - if (error(I->getOrdinal(Ordinal))) return; + if (error(I.getOrdinal(Ordinal))) return; W.printNumber("Symbol", Sym, Ordinal); } } void COFFDumper::printCOFFImports() { // Regular imports - for (auto I = Obj->import_directory_begin(), E = Obj->import_directory_end(); - I != E; ++I) { + for (const ImportDirectoryEntryRef &I : Obj->import_directories()) { DictScope Import(W, "Import"); StringRef Name; - if (error(I->getName(Name))) return; + if (error(I.getName(Name))) return; W.printString("Name", Name); uint32_t Addr; - if (error(I->getImportLookupTableRVA(Addr))) return; + if (error(I.getImportLookupTableRVA(Addr))) return; W.printHex("ImportLookupTableRVA", Addr); - if (error(I->getImportAddressTableRVA(Addr))) return; + if (error(I.getImportAddressTableRVA(Addr))) return; W.printHex("ImportAddressTableRVA", Addr); - printImportedSymbols(I->imported_symbol_begin(), I->imported_symbol_end()); + printImportedSymbols(I.imported_symbols()); } // Delay imports - for (auto I = Obj->delay_import_directory_begin(), - E = Obj->delay_import_directory_end(); - I != E; ++I) { + for (const DelayImportDirectoryEntryRef &I : Obj->delay_import_directories()) { DictScope Import(W, "DelayImport"); StringRef Name; - if (error(I->getName(Name))) return; + if (error(I.getName(Name))) return; W.printString("Name", Name); const delay_import_directory_table_entry *Table; - if (error(I->getDelayImportTable(Table))) return; + if (error(I.getDelayImportTable(Table))) return; W.printHex("Attributes", Table->Attributes); W.printHex("ModuleHandle", Table->ModuleHandle); W.printHex("ImportAddressTable", Table->DelayImportAddressTable); W.printHex("ImportNameTable", Table->DelayImportNameTable); W.printHex("BoundDelayImportTable", Table->BoundDelayImportTable); W.printHex("UnloadDelayImportTable", Table->UnloadDelayImportTable); - printImportedSymbols(I->imported_symbol_begin(), I->imported_symbol_end()); + printImportedSymbols(I.imported_symbols()); } } @@ -949,4 +944,3 @@ void COFFDumper::printCOFFDirectives() { W.printString("Directive(s)", Contents); } } -