[llvm] r219383 - Object: Add range iterators for COFF import/export table
Rui Ueyama
ruiu at google.com
Wed Oct 8 19:16:39 PDT 2014
Author: ruiu
Date: Wed Oct 8 21:16:38 2014
New Revision: 219383
URL: http://llvm.org/viewvc/llvm-project?rev=219383&view=rev
Log:
Object: Add range iterators for COFF import/export table
Modified:
llvm/trunk/include/llvm/Object/COFF.h
llvm/trunk/lib/Object/COFFObjectFile.cpp
llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=219383&r1=219382&r2=219383&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Wed Oct 8 21:16:38 2014
@@ -600,6 +600,11 @@ public:
export_directory_iterator export_directory_begin() const;
export_directory_iterator export_directory_end() const;
+ iterator_range<import_directory_iterator> import_directories() const;
+ iterator_range<delay_import_directory_iterator>
+ delay_import_directories() const;
+ iterator_range<export_directory_iterator> 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_symbol_iterator> 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_symbol_iterator> imported_symbols() const;
std::error_code getName(StringRef &Result) const;
std::error_code getDelayImportTable(
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=219383&r1=219382&r2=219383&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Wed Oct 8 21:16:38 2014
@@ -730,6 +730,22 @@ unsigned COFFObjectFile::getArch() const
}
}
+iterator_range<import_directory_iterator>
+COFFObjectFile::import_directories() const {
+ return make_range(import_directory_begin(), import_directory_end());
+}
+
+iterator_range<delay_import_directory_iterator>
+COFFObjectFile::delay_import_directories() const {
+ return make_range(delay_import_directory_begin(),
+ delay_import_directory_end());
+}
+
+iterator_range<export_directory_iterator>
+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
OwningObject);
}
+iterator_range<imported_symbol_iterator>
+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_s
OwningObject);
}
+iterator_range<imported_symbol_iterator>
+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))
Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=219383&r1=219382&r2=219383&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Wed Oct 8 21:16:38 2014
@@ -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<imported_symbol_iterator> Range);
typedef DenseMap<const coff_section*, std::vector<RelocationRef> > 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<imported_symbol_iterator> 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);
}
}
-
More information about the llvm-commits
mailing list