[llvm-commits] [llvm] r74593 - /llvm/trunk/lib/MC/MCAsmStreamer.cpp

Daniel Dunbar daniel at zuster.org
Tue Jun 30 23:35:04 PDT 2009


Author: ddunbar
Date: Wed Jul  1 01:35:03 2009
New Revision: 74593

URL: http://llvm.org/viewvc/llvm-project?rev=74593&view=rev
Log:
Dump MCInsts in the MC .s printer, for now.

Modified:
    llvm/trunk/lib/MC/MCAsmStreamer.cpp

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=74593&r1=74592&r2=74593&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Wed Jul  1 01:35:03 2009
@@ -10,6 +10,7 @@
 #include "llvm/MC/MCStreamer.h"
 
 #include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCSymbol.h"
 #include "llvm/MC/MCValue.h"
@@ -195,10 +196,30 @@
   OS << ".org " << Offset << ", " << (unsigned) Value << '\n';
 }
 
+static raw_ostream &operator<<(raw_ostream &OS, const MCOperand &Op) {
+  if (Op.isReg())
+    return OS << "reg:" << Op.getReg();
+  if (Op.isImm())
+    return OS << "imm:" << Op.getImm();
+  if (Op.isMBBLabel())
+    return OS << "mbblabel:(" 
+              << Op.getMBBLabelFunction() << ", " << Op.getMBBLabelBlock();
+  assert(Op.isMCValue() && "Invalid operand!");
+  return OS << "val:" << Op.getMCValue();
+}
+
 void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
   assert(CurSection && "Cannot emit contents before setting section!");
-  // FIXME: Implement.
-  OS << "# FIXME: Implement instruction printing!\n";
+  // FIXME: Implement proper printing.
+  OS << "MCInst("
+     << "opcode=" << Inst.getOpcode() << ", "
+     << "operands=[";
+  for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i) {
+    if (i)
+      OS << ", ";
+    OS << Inst.getOperand(i);
+  }
+  OS << "])\n";
 }
 
 void MCAsmStreamer::Finish() {





More information about the llvm-commits mailing list