[llvm] r255569 - Factor out some duplication. NFC.
Pete Cooper via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 14 15:10:53 PST 2015
Author: pete
Date: Mon Dec 14 17:10:52 2015
New Revision: 255569
URL: http://llvm.org/viewvc/llvm-project?rev=255569&view=rev
Log:
Factor out some duplication. NFC.
Modified:
llvm/trunk/tools/llvm-objdump/MachODump.cpp
Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=255569&r1=255568&r2=255569&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Mon Dec 14 17:10:52 2015
@@ -6771,6 +6771,22 @@ static unsigned getSizeForEncoding(bool
}
}
+static uint64_t readPointer(const char *&Pos, bool is64Bit, unsigned Encoding) {
+ switch (getSizeForEncoding(is64Bit, Encoding)) {
+ case 2:
+ return readNext<uint16_t>(Pos);
+ break;
+ case 4:
+ return readNext<uint32_t>(Pos);
+ break;
+ case 8:
+ return readNext<uint64_t>(Pos);
+ break;
+ default:
+ llvm_unreachable("Illegal data size");
+ }
+}
+
static void printMachOEHFrameSection(const MachOObjectFile *Obj,
std::map<uint64_t, SymbolRef> &Symbols,
const SectionRef &EHFrame) {
@@ -6867,19 +6883,7 @@ static void printMachOEHFrameSection(con
case 'P': {
assert(!Personality && "Duplicate personality");
PersonalityEncoding = readNext<uint8_t>(Pos);
- switch (getSizeForEncoding(is64Bit, *PersonalityEncoding)) {
- case 2:
- Personality = readNext<uint16_t>(Pos);
- break;
- case 4:
- Personality = readNext<uint32_t>(Pos);
- break;
- case 8:
- Personality = readNext<uint64_t>(Pos);
- break;
- default:
- llvm_unreachable("Illegal data size");
- }
+ Personality = readPointer(Pos, is64Bit, *PersonalityEncoding);
break;
}
case 'R':
@@ -6953,24 +6957,8 @@ static void printMachOEHFrameSection(con
uint64_t PCPointerSize = getSizeForEncoding(is64Bit,
*CIE.FDEPointerEncoding);
- uint64_t PCBegin;
- uint64_t PCRange;
- switch (PCPointerSize) {
- case 2:
- PCBegin = readNext<uint16_t>(Pos);
- PCRange = readNext<uint16_t>(Pos);
- break;
- case 4:
- PCBegin = readNext<uint32_t>(Pos);
- PCRange = readNext<uint32_t>(Pos);
- break;
- case 8:
- PCBegin = readNext<uint64_t>(Pos);
- PCRange = readNext<uint64_t>(Pos);
- break;
- default:
- llvm_unreachable("Illegal data size");
- }
+ uint64_t PCBegin = readPointer(Pos, is64Bit, *CIE.FDEPointerEncoding);
+ uint64_t PCRange = readPointer(Pos, is64Bit, *CIE.FDEPointerEncoding);
Optional<uint64_t> AugmentationLength;
uint32_t LSDAPointerSize;
@@ -6984,19 +6972,7 @@ static void printMachOEHFrameSection(con
// Decode the LSDA if the CIE augmentation string said we should.
if (CIE.LSDAPointerEncoding) {
LSDAPointerSize = getSizeForEncoding(is64Bit, *CIE.LSDAPointerEncoding);
- switch (LSDAPointerSize) {
- case 2:
- LSDAPointer = readNext<uint16_t>(Pos);
- break;
- case 4:
- LSDAPointer = readNext<uint32_t>(Pos);
- break;
- case 8:
- LSDAPointer = readNext<uint64_t>(Pos);
- break;
- default:
- llvm_unreachable("Illegal data size");
- }
+ LSDAPointer = readPointer(Pos, is64Bit, *CIE.LSDAPointerEncoding);
}
}
More information about the llvm-commits
mailing list