From db4d40136441a962913842d84ba4c49498855b39 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 18 Mar 2015 19:27:31 +0000 Subject: [PATCH] [Objdump] DumpBytes of uint8_t from ArrayRef instead of char from StringRef. Removing reinterpret_casts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232659 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objdump/MachODump.cpp | 25 ++++++++++--------------- tools/llvm-objdump/llvm-objdump.cpp | 5 ++--- tools/llvm-objdump/llvm-objdump.h | 2 +- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 3c8b9bce4c9..812818a4354 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -205,7 +205,7 @@ static bool compareDiceTableEntries(const DiceTableEntry &i, return j.first >= i.first && j.first < i.first + Length; } -static uint64_t DumpDataInCode(const char *bytes, uint64_t Length, +static uint64_t DumpDataInCode(const uint8_t *bytes, uint64_t Length, unsigned short Kind) { uint32_t Value, Size = 1; @@ -214,19 +214,19 @@ static uint64_t DumpDataInCode(const char *bytes, uint64_t Length, case MachO::DICE_KIND_DATA: if (Length >= 4) { if (!NoShowRawInsn) - DumpBytes(StringRef(bytes, 4)); + DumpBytes(ArrayRef(bytes, 4)); Value = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0]; outs() << "\t.long " << Value; Size = 4; } else if (Length >= 2) { if (!NoShowRawInsn) - DumpBytes(StringRef(bytes, 2)); + DumpBytes(ArrayRef(bytes, 2)); Value = bytes[1] << 8 | bytes[0]; outs() << "\t.short " << Value; Size = 2; } else { if (!NoShowRawInsn) - DumpBytes(StringRef(bytes, 2)); + DumpBytes(ArrayRef(bytes, 2)); Value = bytes[0]; outs() << "\t.byte " << Value; Size = 1; @@ -238,14 +238,14 @@ static uint64_t DumpDataInCode(const char *bytes, uint64_t Length, break; case MachO::DICE_KIND_JUMP_TABLE8: if (!NoShowRawInsn) - DumpBytes(StringRef(bytes, 1)); + DumpBytes(ArrayRef(bytes, 1)); Value = bytes[0]; outs() << "\t.byte " << format("%3u", Value) << "\t@ KIND_JUMP_TABLE8\n"; Size = 1; break; case MachO::DICE_KIND_JUMP_TABLE16: if (!NoShowRawInsn) - DumpBytes(StringRef(bytes, 2)); + DumpBytes(ArrayRef(bytes, 2)); Value = bytes[1] << 8 | bytes[0]; outs() << "\t.short " << format("%5u", Value & 0xffff) << "\t@ KIND_JUMP_TABLE16\n"; @@ -254,7 +254,7 @@ static uint64_t DumpDataInCode(const char *bytes, uint64_t Length, case MachO::DICE_KIND_JUMP_TABLE32: case MachO::DICE_KIND_ABS_JUMP_TABLE32: if (!NoShowRawInsn) - DumpBytes(StringRef(bytes, 4)); + DumpBytes(ArrayRef(bytes, 4)); Value = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0]; outs() << "\t.long " << Value; if (Kind == MachO::DICE_KIND_JUMP_TABLE32) @@ -3323,9 +3323,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, DTI->second.getLength(Length); uint16_t Kind; DTI->second.getKind(Kind); - Size = DumpDataInCode(reinterpret_cast(Bytes.data()) + - Index, - Length, Kind); + Size = DumpDataInCode(Bytes.data() + Index, Length, Kind); if ((Kind == MachO::DICE_KIND_JUMP_TABLE8) && (PC == (DTI->first + Length - 1)) && (Length & 1)) Size++; @@ -3344,8 +3342,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, DebugOut, Annotations); if (gotInst) { if (!NoShowRawInsn) { - DumpBytes(StringRef( - reinterpret_cast(Bytes.data()) + Index, Size)); + DumpBytes(ArrayRef(Bytes.data() + Index, Size)); } formatted_raw_ostream FormattedOS(outs()); Annotations.flush(); @@ -3410,9 +3407,7 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, } if (!NoShowRawInsn) { outs() << "\t"; - DumpBytes( - StringRef(reinterpret_cast(Bytes.data()) + Index, - InstSize)); + DumpBytes(ArrayRef(Bytes.data() + Index, InstSize)); } IP->printInst(&Inst, outs(), ""); outs() << "\n"; diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 365d2ff5e37..7bec062070a 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -194,7 +194,7 @@ static const Target *getTarget(const ObjectFile *Obj = nullptr) { return TheTarget; } -void llvm::DumpBytes(StringRef bytes) { +void llvm::DumpBytes(ArrayRef bytes) { static const char hex_rep[] = "0123456789abcdef"; SmallString<64> output; @@ -399,8 +399,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { outs() << format("%8" PRIx64 ":", SectionAddr + Index); if (!NoShowRawInsn) { outs() << "\t"; - DumpBytes(StringRef( - reinterpret_cast(Bytes.data()) + Index, Size)); + DumpBytes(ArrayRef(Bytes.data() + Index, Size)); } IP->printInst(&Inst, outs(), ""); outs() << CommentStream.str(); diff --git a/tools/llvm-objdump/llvm-objdump.h b/tools/llvm-objdump/llvm-objdump.h index b846e1018f8..c1d5ff8c211 100644 --- a/tools/llvm-objdump/llvm-objdump.h +++ b/tools/llvm-objdump/llvm-objdump.h @@ -54,7 +54,7 @@ extern cl::opt UnwindInfo; // Various helper functions. bool error(std::error_code ec); bool RelocAddressLess(object::RelocationRef a, object::RelocationRef b); -void DumpBytes(StringRef bytes); +void DumpBytes(ArrayRef bytes); void ParseInputMachO(StringRef Filename); void printCOFFUnwindInfo(const object::COFFObjectFile* o); void printMachOUnwindInfo(const object::MachOObjectFile* o); -- 2.34.1