Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit befaca2

Browse files
committed
Merging r242288:
------------------------------------------------------------------------ r242288 | d0k | 2015-07-15 05:56:19 -0700 (Wed, 15 Jul 2015) | 3 lines [PPC] Disassemble little endian ppc instructions in the right byte order PR24122. The test is simply a byte swapped version of ppc64-encoding.txt. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_37@242327 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 445ea38 commit befaca2

File tree

2 files changed

+681
-8
lines changed

2 files changed

+681
-8
lines changed

lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/MC/MCFixedLenDisassembler.h"
1313
#include "llvm/MC/MCInst.h"
1414
#include "llvm/MC/MCSubtargetInfo.h"
15+
#include "llvm/Support/Endian.h"
1516
#include "llvm/Support/TargetRegistry.h"
1617

1718
using namespace llvm;
@@ -22,10 +23,12 @@ typedef MCDisassembler::DecodeStatus DecodeStatus;
2223

2324
namespace {
2425
class PPCDisassembler : public MCDisassembler {
26+
bool IsLittleEndian;
27+
2528
public:
26-
PPCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx)
27-
: MCDisassembler(STI, Ctx) {}
28-
~PPCDisassembler() override {}
29+
PPCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
30+
bool IsLittleEndian)
31+
: MCDisassembler(STI, Ctx), IsLittleEndian(IsLittleEndian) {}
2932

3033
DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
3134
ArrayRef<uint8_t> Bytes, uint64_t Address,
@@ -37,7 +40,13 @@ class PPCDisassembler : public MCDisassembler {
3740
static MCDisassembler *createPPCDisassembler(const Target &T,
3841
const MCSubtargetInfo &STI,
3942
MCContext &Ctx) {
40-
return new PPCDisassembler(STI, Ctx);
43+
return new PPCDisassembler(STI, Ctx, /*IsLittleEndian=*/false);
44+
}
45+
46+
static MCDisassembler *createPPCLEDisassembler(const Target &T,
47+
const MCSubtargetInfo &STI,
48+
MCContext &Ctx) {
49+
return new PPCDisassembler(STI, Ctx, /*IsLittleEndian=*/true);
4150
}
4251

4352
extern "C" void LLVMInitializePowerPCDisassembler() {
@@ -47,7 +56,7 @@ extern "C" void LLVMInitializePowerPCDisassembler() {
4756
TargetRegistry::RegisterMCDisassembler(ThePPC64Target,
4857
createPPCDisassembler);
4958
TargetRegistry::RegisterMCDisassembler(ThePPC64LETarget,
50-
createPPCDisassembler);
59+
createPPCLEDisassembler);
5160
}
5261

5362
// FIXME: These can be generated by TableGen from the existing register
@@ -383,9 +392,9 @@ DecodeStatus PPCDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
383392
return MCDisassembler::Fail;
384393
}
385394

386-
// The instruction is big-endian encoded.
387-
uint32_t Inst =
388-
(Bytes[0] << 24) | (Bytes[1] << 16) | (Bytes[2] << 8) | (Bytes[3] << 0);
395+
// Read the instruction in the proper endianness.
396+
uint32_t Inst = IsLittleEndian ? support::endian::read32le(Bytes.data())
397+
: support::endian::read32be(Bytes.data());
389398

390399
if (STI.getFeatureBits()[PPC::FeatureQPX]) {
391400
DecodeStatus result =

0 commit comments

Comments
 (0)