aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/MC/MCInst.h7
-rw-r--r--lib/MC/CMakeLists.txt1
-rw-r--r--lib/MC/MCInst.cpp52
3 files changed, 60 insertions, 0 deletions
diff --git a/include/llvm/MC/MCInst.h b/include/llvm/MC/MCInst.h
index 36011b9b65..857d29411e 100644
--- a/include/llvm/MC/MCInst.h
+++ b/include/llvm/MC/MCInst.h
@@ -22,6 +22,7 @@
#include "llvm/Support/DebugLoc.h"
namespace llvm {
+class raw_ostream;
/// MCOperand - Instances of this class represent operands of the MCInst class.
/// This is a simple discriminated union.
@@ -119,6 +120,9 @@ public:
Op.MCValueVal = Val;
return Op;
}
+
+ void print(raw_ostream &OS) const;
+ void dump() const;
};
@@ -142,6 +146,9 @@ public:
void addOperand(const MCOperand &Op) {
Operands.push_back(Op);
}
+
+ void print(raw_ostream &OS) const;
+ void dump() const;
};
diff --git a/lib/MC/CMakeLists.txt b/lib/MC/CMakeLists.txt
index ecb8440575..672d9b76a9 100644
--- a/lib/MC/CMakeLists.txt
+++ b/lib/MC/CMakeLists.txt
@@ -8,6 +8,7 @@ add_llvm_library(LLVMMC
MCAssembler.cpp
MCCodeEmitter.cpp
MCContext.cpp
+ MCInst.cpp
MCMachOStreamer.cpp
MCNullStreamer.cpp
MCSection.cpp
diff --git a/lib/MC/MCInst.cpp b/lib/MC/MCInst.cpp
new file mode 100644
index 0000000000..469dc7975e
--- /dev/null
+++ b/lib/MC/MCInst.cpp
@@ -0,0 +1,52 @@
+//===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/MC/MCInst.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+void MCOperand::print(raw_ostream &OS) const {
+ OS << "<MCOperand ";
+ if (!isValid())
+ OS << "INVALID";
+ else if (isReg())
+ OS << "Reg:" << getReg();
+ else if (isImm())
+ OS << "Imm:" << getImm();
+ else if (isMBBLabel())
+ OS << "MBB:(" << getMBBLabelFunction() << ","
+ << getMBBLabelBlock() << ")";
+ else if (isMCValue()) {
+ OS << "Value:(";
+ getMCValue().print(OS);
+ OS << ")";
+ } else
+ OS << "UNDEFINED";
+ OS << ">";
+}
+
+void MCOperand::dump() const {
+ print(errs());
+ errs() << "\n";
+}
+
+void MCInst::print(raw_ostream &OS) const {
+ OS << "<MCInst " << getOpcode();
+ for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
+ OS << " ";
+ getOperand(i).print(OS);
+ }
+ OS << ">";
+}
+
+void MCInst::dump() const {
+ print(errs());
+ errs() << "\n";
+}