[llvm-commits] [llvm] r99216 - in /llvm/trunk: include/llvm/MC/MCInst.h lib/MC/MCAsmStreamer.cpp lib/MC/MCInst.cpp
Daniel Dunbar
daniel at zuster.org
Mon Mar 22 14:49:34 PDT 2010
Author: ddunbar
Date: Mon Mar 22 16:49:34 2010
New Revision: 99216
URL: http://llvm.org/viewvc/llvm-project?rev=99216&view=rev
Log:
MCInst: Add ::dump_pretty.
Modified:
llvm/trunk/include/llvm/MC/MCInst.h
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/MC/MCInst.cpp
Modified: llvm/trunk/include/llvm/MC/MCInst.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCInst.h?rev=99216&r1=99215&r2=99216&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCInst.h (original)
+++ llvm/trunk/include/llvm/MC/MCInst.h Mon Mar 22 16:49:34 2010
@@ -17,11 +17,13 @@
#define LLVM_MC_MCINST_H
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/System/DataTypes.h"
namespace llvm {
class raw_ostream;
class MCAsmInfo;
+class MCInstPrinter;
class MCExpr;
/// MCOperand - Instances of this class represent operands of the MCInst class.
@@ -125,6 +127,13 @@
void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
void dump() const;
+
+ /// \brief Dump the MCInst as prettily as possible using the additional MC
+ /// structures, if given. Operators are separated by the \arg Separator
+ /// string.
+ void dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI = 0,
+ const MCInstPrinter *Printer = 0,
+ StringRef Separator = " ") const;
};
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=99216&r1=99215&r2=99216&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Mon Mar 22 16:49:34 2010
@@ -623,24 +623,10 @@
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
Modified: llvm/trunk/lib/MC/MCInst.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCInst.cpp?rev=99216&r1=99215&r2=99216&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCInst.cpp (original)
+++ llvm/trunk/lib/MC/MCInst.cpp Mon Mar 22 16:49:34 2010
@@ -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 @@
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";
More information about the llvm-commits
mailing list