diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-03-22 21:49:34 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-03-22 21:49:34 +0000 |
commit | 67c076cf59d14fc96feb5c915447f8ea79cf8325 (patch) | |
tree | e676c343c12b0facebe91324bd2e451e879afa4c /lib/MC | |
parent | a69ec09364213311f1ced39271a30f39076b207e (diff) | |
download | external_llvm-67c076cf59d14fc96feb5c915447f8ea79cf8325.zip external_llvm-67c076cf59d14fc96feb5c915447f8ea79cf8325.tar.gz external_llvm-67c076cf59d14fc96feb5c915447f8ea79cf8325.tar.bz2 |
MCInst: Add ::dump_pretty.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99216 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 20 | ||||
-rw-r--r-- | lib/MC/MCInst.cpp | 17 |
2 files changed, 20 insertions, 17 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 2025463..7a23aec 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -623,24 +623,10 @@ void MCAsmStreamer::EmitInstruction(const MCInst &Inst) { AddEncodingComment(Inst); // Show the MCInst if enabled. - if (ShowInst) { - raw_ostream &OS = GetCommentOS(); - OS << "<MCInst #" << Inst.getOpcode(); - - StringRef InstName; - if (InstPrinter) - InstName = InstPrinter->getOpcodeName(Inst.getOpcode()); - if (!InstName.empty()) - OS << ' ' << InstName; - - for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i) { - OS << "\n "; - Inst.getOperand(i).print(OS, &MAI); - } - OS << ">\n"; - } + if (ShowInst) + Inst.dump_pretty(GetCommentOS(), &MAI, InstPrinter.get(), "\n "); - // If we have an AsmPrinter, use that to print, otherwise dump the MCInst. + // If we have an AsmPrinter, use that to print, otherwise print the MCInst. if (InstPrinter) InstPrinter->printInst(&Inst); else diff --git a/lib/MC/MCInst.cpp b/lib/MC/MCInst.cpp index 0634c9f..de142dc 100644 --- a/lib/MC/MCInst.cpp +++ b/lib/MC/MCInst.cpp @@ -9,6 +9,7 @@ #include "llvm/MC/MCInst.h" #include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCInstPrinter.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -43,6 +44,22 @@ void MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const { OS << ">"; } +void MCInst::dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI, + const MCInstPrinter *Printer, + StringRef Separator) const { + OS << "<MCInst #" << getOpcode(); + + // Show the instruction opcode name if we have access to a printer. + if (Printer) + OS << ' ' << Printer->getOpcodeName(getOpcode()); + + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { + OS << Separator; + getOperand(i).print(OS, MAI); + } + OS << ">\n"; +} + void MCInst::dump() const { print(dbgs(), 0); dbgs() << "\n"; |