summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2014-01-16 03:13:19 +0000
committerRui Ueyama <ruiu@google.com>2014-01-16 03:13:19 +0000
commit6a8151dba16a2315e1b2a7daf27ff454c26d0ad5 (patch)
treeefb2c9aea692aa1dd4ce36159815c6c7a4cb14b0
parent2666b15908125479cea95066593873168127be72 (diff)
downloadllvm-6a8151dba16a2315e1b2a7daf27ff454c26d0ad5.tar.gz
llvm-6a8151dba16a2315e1b2a7daf27ff454c26d0ad5.tar.bz2
llvm-6a8151dba16a2315e1b2a7daf27ff454c26d0ad5.tar.xz
Don't use DataRefImpl to implement ImportDirectoryEntryRef.
DataRefImpl (a union of two integers and a pointer) is not the ideal data type to represent a reference to an import directory entity. We should just use the pointer to the import table and an offset instead to simplify. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199349 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Object/COFF.h7
-rw-r--r--lib/Object/COFFObjectFile.cpp54
2 files changed, 21 insertions, 40 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index aaffbbcb5e..431029045f 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -369,9 +369,9 @@ public:
class ImportDirectoryEntryRef {
public:
ImportDirectoryEntryRef() : OwningObject(0) {}
- ImportDirectoryEntryRef(DataRefImpl ImportDirectory,
+ ImportDirectoryEntryRef(const import_directory_table_entry *Table, uint32_t I,
const COFFObjectFile *Owner)
- : ImportDirectoryPimpl(ImportDirectory), OwningObject(Owner) {}
+ : ImportTable(Table), Index(I), OwningObject(Owner) {}
bool operator==(const ImportDirectoryEntryRef &Other) const;
error_code getNext(ImportDirectoryEntryRef &Result) const;
@@ -384,7 +384,8 @@ public:
getImportLookupEntry(const import_lookup_table_entry32 *&Result) const;
private:
- DataRefImpl ImportDirectoryPimpl;
+ const import_directory_table_entry *ImportTable;
+ uint32_t Index;
const COFFObjectFile *OwningObject;
};
} // end namespace object
diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp
index 42066c372b..dc8a718c7a 100644
--- a/lib/Object/COFFObjectFile.cpp
+++ b/lib/Object/COFFObjectFile.cpp
@@ -563,20 +563,13 @@ StringRef COFFObjectFile::getLoadName() const {
}
import_directory_iterator COFFObjectFile::import_directory_begin() const {
- DataRefImpl Imp;
- Imp.p = reinterpret_cast<uintptr_t>(ImportDirectory);
- return import_directory_iterator(ImportDirectoryEntryRef(Imp, this));
+ return import_directory_iterator(
+ ImportDirectoryEntryRef(ImportDirectory, 0, this));
}
import_directory_iterator COFFObjectFile::import_directory_end() const {
- DataRefImpl Imp;
- if (ImportDirectory) {
- Imp.p = reinterpret_cast<uintptr_t>(
- ImportDirectory + (NumberOfImportDirectory - 1));
- } else {
- Imp.p = 0;
- }
- return import_directory_iterator(ImportDirectoryEntryRef(Imp, this));
+ return import_directory_iterator(
+ ImportDirectoryEntryRef(ImportDirectory, NumberOfImportDirectory, this));
}
section_iterator COFFObjectFile::begin_sections() const {
@@ -884,55 +877,42 @@ error_code COFFObjectFile::getLibraryPath(DataRefImpl LibData,
bool ImportDirectoryEntryRef::
operator==(const ImportDirectoryEntryRef &Other) const {
- return ImportDirectoryPimpl == Other.ImportDirectoryPimpl;
-}
-
-static const import_directory_table_entry *toImportEntry(DataRefImpl Imp) {
- return reinterpret_cast<const import_directory_table_entry *>(Imp.p);
+ return ImportTable == Other.ImportTable && Index == Other.Index;
}
error_code
ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const {
- const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl);
- Dir += 1;
- DataRefImpl Next;
- Next.p = reinterpret_cast<uintptr_t>(Dir);
- Result = ImportDirectoryEntryRef(Next, OwningObject);
+ Result = ImportDirectoryEntryRef(ImportTable, Index + 1, OwningObject);
return object_error::success;
}
error_code ImportDirectoryEntryRef::
getImportTableEntry(const import_directory_table_entry *&Result) const {
- Result = toImportEntry(ImportDirectoryPimpl);
+ Result = ImportTable;
return object_error::success;
}
error_code ImportDirectoryEntryRef::getName(StringRef &Result) const {
- const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl);
uintptr_t IntPtr = 0;
- if (error_code ec = OwningObject->getRvaPtr(Dir->NameRVA, IntPtr))
- return ec;
- const char *Ptr = reinterpret_cast<const char *>(IntPtr);
- Result = StringRef(Ptr);
+ if (error_code EC = OwningObject->getRvaPtr(ImportTable->NameRVA, IntPtr))
+ return EC;
+ Result = StringRef(reinterpret_cast<const char *>(IntPtr));
return object_error::success;
}
error_code ImportDirectoryEntryRef::getImportLookupEntry(
const import_lookup_table_entry32 *&Result) const {
- const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl);
uintptr_t IntPtr = 0;
- if (error_code ec = OwningObject->getRvaPtr(
- Dir->ImportLookupTableRVA, IntPtr))
- return ec;
+ if (error_code EC =
+ OwningObject->getRvaPtr(ImportTable->ImportLookupTableRVA, IntPtr))
+ return EC;
Result = reinterpret_cast<const import_lookup_table_entry32 *>(IntPtr);
return object_error::success;
}
namespace llvm {
-
- ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
- error_code ec;
- return new COFFObjectFile(Object, ec);
- }
-
+ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
+ error_code ec;
+ return new COFFObjectFile(Object, ec);
+}
} // end namespace llvm