Skip to content

Commit 212b6d8

Browse files
committed
Add {MCInst,MCOperand}::{print,dump}
llvm-svn: 80231
1 parent d18dd1d commit 212b6d8

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

llvm/include/llvm/MC/MCInst.h

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/Support/DebugLoc.h"
2323

2424
namespace llvm {
25+
class raw_ostream;
2526

2627
/// MCOperand - Instances of this class represent operands of the MCInst class.
2728
/// This is a simple discriminated union.
@@ -119,6 +120,9 @@ class MCOperand {
119120
Op.MCValueVal = Val;
120121
return Op;
121122
}
123+
124+
void print(raw_ostream &OS) const;
125+
void dump() const;
122126
};
123127

124128

@@ -142,6 +146,9 @@ class MCInst {
142146
void addOperand(const MCOperand &Op) {
143147
Operands.push_back(Op);
144148
}
149+
150+
void print(raw_ostream &OS) const;
151+
void dump() const;
145152
};
146153

147154

llvm/lib/MC/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_llvm_library(LLVMMC
88
MCAssembler.cpp
99
MCCodeEmitter.cpp
1010
MCContext.cpp
11+
MCInst.cpp
1112
MCMachOStreamer.cpp
1213
MCNullStreamer.cpp
1314
MCSection.cpp

llvm/lib/MC/MCInst.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "llvm/MC/MCInst.h"
11+
#include "llvm/Support/raw_ostream.h"
12+
13+
using namespace llvm;
14+
15+
void MCOperand::print(raw_ostream &OS) const {
16+
OS << "<MCOperand ";
17+
if (!isValid())
18+
OS << "INVALID";
19+
else if (isReg())
20+
OS << "Reg:" << getReg();
21+
else if (isImm())
22+
OS << "Imm:" << getImm();
23+
else if (isMBBLabel())
24+
OS << "MBB:(" << getMBBLabelFunction() << ","
25+
<< getMBBLabelBlock() << ")";
26+
else if (isMCValue()) {
27+
OS << "Value:(";
28+
getMCValue().print(OS);
29+
OS << ")";
30+
} else
31+
OS << "UNDEFINED";
32+
OS << ">";
33+
}
34+
35+
void MCOperand::dump() const {
36+
print(errs());
37+
errs() << "\n";
38+
}
39+
40+
void MCInst::print(raw_ostream &OS) const {
41+
OS << "<MCInst " << getOpcode();
42+
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
43+
OS << " ";
44+
getOperand(i).print(OS);
45+
}
46+
OS << ">";
47+
}
48+
49+
void MCInst::dump() const {
50+
print(errs());
51+
errs() << "\n";
52+
}

0 commit comments

Comments
 (0)