summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorColin LeMahieu <colinl@codeaurora.org>2015-05-28 19:07:14 +0000
committerColin LeMahieu <colinl@codeaurora.org>2015-05-28 19:07:14 +0000
commitfb76b007d33813c637c7829f79f88bd0512cd497 (patch)
tree21eda5e7ba7ebaf94f661372ab733be42cfc14b4 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parentb04fb5ed25d6f1cfcbebc52443c6ed721f59f66c (diff)
downloadbcm5719-llvm-fb76b007d33813c637c7829f79f88bd0512cd497.tar.gz
bcm5719-llvm-fb76b007d33813c637c7829f79f88bd0512cd497.zip
[Objdump] Allow instruction pretty printing to be specialized by the target triple.
Differential Revision: http://reviews.llvm.org/D8427 llvm-svn: 238457
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 66de213fc2a..a78d1d267dd 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -201,6 +201,30 @@ bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) {
return a_addr < b_addr;
}
+namespace {
+class PrettyPrinter {
+public:
+ virtual void printInst(MCInstPrinter &IP, const MCInst *MI, bool ShowRawInsn,
+ ArrayRef<uint8_t> Bytes, uint64_t Address,
+ raw_ostream &OS, StringRef Annot,
+ MCSubtargetInfo const &STI) {
+ outs() << format("%8" PRIx64 ":", Address);
+ if (!NoShowRawInsn) {
+ outs() << "\t";
+ dumpBytes(Bytes, outs());
+ }
+ IP.printInst(MI, outs(), "", STI);
+ }
+};
+PrettyPrinter PrettyPrinterInst;
+PrettyPrinter &selectPrettyPrinter(Triple const &Triple, MCInstPrinter &IP) {
+ switch(Triple.getArch()) {
+ default:
+ return PrettyPrinterInst;
+ }
+}
+}
+
static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
const Target *TheTarget = getTarget(Obj);
// getTarget() will have already issued a diagnostic if necessary, so
@@ -267,6 +291,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
<< '\n';
return;
}
+ PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName), *IP);
StringRef Fmt = Obj->getBytesInAddress() > 4 ? "\t\t%016" PRIx64 ": " :
"\t\t\t%08" PRIx64 ": ";
@@ -383,12 +408,9 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
if (DisAsm->getInstruction(Inst, Size, Bytes.slice(Index),
SectionAddr + Index, DebugOut,
CommentStream)) {
- outs() << format("%8" PRIx64 ":", SectionAddr + Index);
- if (!NoShowRawInsn) {
- outs() << "\t";
- dumpBytes(ArrayRef<uint8_t>(Bytes.data() + Index, Size), outs());
- }
- IP->printInst(&Inst, outs(), "", *STI);
+ PIP.printInst(*IP, &Inst, !NoShowRawInsn,
+ Bytes.slice(Index, Size),
+ SectionAddr + Index, outs(), "", *STI);
outs() << CommentStream.str();
Comments.clear();
outs() << "\n";
OpenPOWER on IntegriCloud