[llvm] r240563 - Refactor duplicated code. NFC.
Rafael Espindola
rafael.espindola at gmail.com
Wed Jun 24 11:14:41 PDT 2015
Author: rafael
Date: Wed Jun 24 13:14:41 2015
New Revision: 240563
URL: http://llvm.org/viewvc/llvm-project?rev=240563&view=rev
Log:
Refactor duplicated code. NFC.
Modified:
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/lib/Object/MachOObjectFile.cpp
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=240563&r1=240562&r2=240563&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Wed Jun 24 13:14:41 2015
@@ -197,6 +197,8 @@ public:
std::error_code &EC);
void moveSymbolNext(DataRefImpl &Symb) const override;
+
+ uint64_t getNValue(DataRefImpl Sym) const;
std::error_code getSymbolName(DataRefImpl Symb,
StringRef &Res) const override;
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=240563&r1=240562&r2=240563&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Wed Jun 24 13:14:41 2015
@@ -345,23 +345,24 @@ unsigned MachOObjectFile::getSectionType
return Flags & MachO::SECTION_TYPE;
}
+uint64_t MachOObjectFile::getNValue(DataRefImpl Sym) const {
+ if (is64Bit()) {
+ MachO::nlist_64 Entry = getSymbol64TableEntry(Sym);
+ return Entry.n_value;
+ }
+ MachO::nlist Entry = getSymbolTableEntry(Sym);
+ return Entry.n_value;
+}
+
// getIndirectName() returns the name of the alias'ed symbol who's string table
// index is in the n_value field.
std::error_code MachOObjectFile::getIndirectName(DataRefImpl Symb,
StringRef &Res) const {
StringRef StringTable = getStringTableData();
- uint64_t NValue;
- if (is64Bit()) {
- MachO::nlist_64 Entry = getSymbol64TableEntry(Symb);
- NValue = Entry.n_value;
- if ((Entry.n_type & MachO::N_TYPE) != MachO::N_INDR)
- return object_error::parse_failed;
- } else {
- MachO::nlist Entry = getSymbolTableEntry(Symb);
- NValue = Entry.n_value;
- if ((Entry.n_type & MachO::N_TYPE) != MachO::N_INDR)
- return object_error::parse_failed;
- }
+ MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
+ if ((Entry.n_type & MachO::N_TYPE) != MachO::N_INDR)
+ return object_error::parse_failed;
+ uint64_t NValue = getNValue(Symb);
if (NValue >= StringTable.size())
return object_error::parse_failed;
const char *Start = &StringTable.data()[NValue];
@@ -371,21 +372,12 @@ std::error_code MachOObjectFile::getIndi
std::error_code MachOObjectFile::getSymbolAddress(DataRefImpl Symb,
uint64_t &Res) const {
- if (is64Bit()) {
- MachO::nlist_64 Entry = getSymbol64TableEntry(Symb);
- if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF &&
- Entry.n_value == 0)
- Res = UnknownAddress;
- else
- Res = Entry.n_value;
- } else {
- MachO::nlist Entry = getSymbolTableEntry(Symb);
- if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF &&
- Entry.n_value == 0)
- Res = UnknownAddress;
- else
- Res = Entry.n_value;
- }
+ uint64_t NValue = getNValue(Symb);
+ MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
+ if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF && NValue == 0)
+ Res = UnknownAddress;
+ else
+ Res = NValue;
return std::error_code();
}
More information about the llvm-commits
mailing list