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
This commit is contained in:
Rui Ueyama 2014-01-16 03:13:19 +00:00
parent 2666b15908
commit 6a8151dba1
2 changed files with 21 additions and 40 deletions

View File

@ -369,9 +369,9 @@ public:
class ImportDirectoryEntryRef { class ImportDirectoryEntryRef {
public: public:
ImportDirectoryEntryRef() : OwningObject(0) {} ImportDirectoryEntryRef() : OwningObject(0) {}
ImportDirectoryEntryRef(DataRefImpl ImportDirectory, ImportDirectoryEntryRef(const import_directory_table_entry *Table, uint32_t I,
const COFFObjectFile *Owner) const COFFObjectFile *Owner)
: ImportDirectoryPimpl(ImportDirectory), OwningObject(Owner) {} : ImportTable(Table), Index(I), OwningObject(Owner) {}
bool operator==(const ImportDirectoryEntryRef &Other) const; bool operator==(const ImportDirectoryEntryRef &Other) const;
error_code getNext(ImportDirectoryEntryRef &Result) const; error_code getNext(ImportDirectoryEntryRef &Result) const;
@ -384,7 +384,8 @@ public:
getImportLookupEntry(const import_lookup_table_entry32 *&Result) const; getImportLookupEntry(const import_lookup_table_entry32 *&Result) const;
private: private:
DataRefImpl ImportDirectoryPimpl; const import_directory_table_entry *ImportTable;
uint32_t Index;
const COFFObjectFile *OwningObject; const COFFObjectFile *OwningObject;
}; };
} // end namespace object } // end namespace object

View File

@ -563,20 +563,13 @@ StringRef COFFObjectFile::getLoadName() const {
} }
import_directory_iterator COFFObjectFile::import_directory_begin() const { import_directory_iterator COFFObjectFile::import_directory_begin() const {
DataRefImpl Imp; return import_directory_iterator(
Imp.p = reinterpret_cast<uintptr_t>(ImportDirectory); ImportDirectoryEntryRef(ImportDirectory, 0, this));
return import_directory_iterator(ImportDirectoryEntryRef(Imp, this));
} }
import_directory_iterator COFFObjectFile::import_directory_end() const { import_directory_iterator COFFObjectFile::import_directory_end() const {
DataRefImpl Imp; return import_directory_iterator(
if (ImportDirectory) { ImportDirectoryEntryRef(ImportDirectory, NumberOfImportDirectory, this));
Imp.p = reinterpret_cast<uintptr_t>(
ImportDirectory + (NumberOfImportDirectory - 1));
} else {
Imp.p = 0;
}
return import_directory_iterator(ImportDirectoryEntryRef(Imp, this));
} }
section_iterator COFFObjectFile::begin_sections() const { section_iterator COFFObjectFile::begin_sections() const {
@ -884,55 +877,42 @@ error_code COFFObjectFile::getLibraryPath(DataRefImpl LibData,
bool ImportDirectoryEntryRef:: bool ImportDirectoryEntryRef::
operator==(const ImportDirectoryEntryRef &Other) const { operator==(const ImportDirectoryEntryRef &Other) const {
return ImportDirectoryPimpl == Other.ImportDirectoryPimpl; return ImportTable == Other.ImportTable && Index == Other.Index;
}
static const import_directory_table_entry *toImportEntry(DataRefImpl Imp) {
return reinterpret_cast<const import_directory_table_entry *>(Imp.p);
} }
error_code error_code
ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const { ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const {
const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl); Result = ImportDirectoryEntryRef(ImportTable, Index + 1, OwningObject);
Dir += 1;
DataRefImpl Next;
Next.p = reinterpret_cast<uintptr_t>(Dir);
Result = ImportDirectoryEntryRef(Next, OwningObject);
return object_error::success; return object_error::success;
} }
error_code ImportDirectoryEntryRef:: error_code ImportDirectoryEntryRef::
getImportTableEntry(const import_directory_table_entry *&Result) const { getImportTableEntry(const import_directory_table_entry *&Result) const {
Result = toImportEntry(ImportDirectoryPimpl); Result = ImportTable;
return object_error::success; return object_error::success;
} }
error_code ImportDirectoryEntryRef::getName(StringRef &Result) const { error_code ImportDirectoryEntryRef::getName(StringRef &Result) const {
const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl);
uintptr_t IntPtr = 0; uintptr_t IntPtr = 0;
if (error_code ec = OwningObject->getRvaPtr(Dir->NameRVA, IntPtr)) if (error_code EC = OwningObject->getRvaPtr(ImportTable->NameRVA, IntPtr))
return ec; return EC;
const char *Ptr = reinterpret_cast<const char *>(IntPtr); Result = StringRef(reinterpret_cast<const char *>(IntPtr));
Result = StringRef(Ptr);
return object_error::success; return object_error::success;
} }
error_code ImportDirectoryEntryRef::getImportLookupEntry( error_code ImportDirectoryEntryRef::getImportLookupEntry(
const import_lookup_table_entry32 *&Result) const { const import_lookup_table_entry32 *&Result) const {
const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl);
uintptr_t IntPtr = 0; uintptr_t IntPtr = 0;
if (error_code ec = OwningObject->getRvaPtr( if (error_code EC =
Dir->ImportLookupTableRVA, IntPtr)) OwningObject->getRvaPtr(ImportTable->ImportLookupTableRVA, IntPtr))
return ec; return EC;
Result = reinterpret_cast<const import_lookup_table_entry32 *>(IntPtr); Result = reinterpret_cast<const import_lookup_table_entry32 *>(IntPtr);
return object_error::success; return object_error::success;
} }
namespace llvm { namespace llvm {
ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) { ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
error_code ec; error_code ec;
return new COFFObjectFile(Object, ec); return new COFFObjectFile(Object, ec);
} }
} // end namespace llvm } // end namespace llvm