Skip to content

Commit 8d09927

Browse files
committed
MCInt: Change dump functions to accept MCContext instead of MCRegiserInfo
* MCContext is more accessible to callers. * With MCContext available, printExpr can be used to print an MCExpr (MCOperand::print) seamlessly.
1 parent 7138397 commit 8d09927

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

llvm/include/llvm/MC/MCInst.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
namespace llvm {
2929

30+
class MCContext;
3031
class MCExpr;
3132
class MCInst;
3233
class MCInstPrinter;
@@ -175,8 +176,7 @@ class MCOperand {
175176
return Op;
176177
}
177178

178-
LLVM_ABI void print(raw_ostream &OS,
179-
const MCRegisterInfo *RegInfo = nullptr) const;
179+
LLVM_ABI void print(raw_ostream &OS, const MCContext *Ctx = nullptr) const;
180180
LLVM_ABI void dump() const;
181181
LLVM_ABI bool isBareSymbolRef() const;
182182
LLVM_ABI bool evaluateAsConstantImm(int64_t &Imm) const;
@@ -228,8 +228,7 @@ class MCInst {
228228
return Operands.insert(I, Op);
229229
}
230230

231-
LLVM_ABI void print(raw_ostream &OS,
232-
const MCRegisterInfo *RegInfo = nullptr) const;
231+
LLVM_ABI void print(raw_ostream &OS, const MCContext *Ctx = nullptr) const;
233232
LLVM_ABI void dump() const;
234233

235234
/// Dump the MCInst as prettily as possible using the additional MC
@@ -238,10 +237,10 @@ class MCInst {
238237
LLVM_ABI void dump_pretty(raw_ostream &OS,
239238
const MCInstPrinter *Printer = nullptr,
240239
StringRef Separator = " ",
241-
const MCRegisterInfo *RegInfo = nullptr) const;
240+
const MCContext *Ctx = nullptr) const;
242241
LLVM_ABI void dump_pretty(raw_ostream &OS, StringRef Name,
243242
StringRef Separator = " ",
244-
const MCRegisterInfo *RegInfo = nullptr) const;
243+
const MCContext *Ctx = nullptr) const;
245244
};
246245

247246
inline raw_ostream& operator<<(raw_ostream &OS, const MCOperand &MO) {

llvm/lib/MC/MCInst.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "llvm/MC/MCInst.h"
1010
#include "llvm/Config/llvm-config.h"
11+
#include "llvm/MC/MCAsmInfo.h"
12+
#include "llvm/MC/MCContext.h"
1113
#include "llvm/MC/MCExpr.h"
1214
#include "llvm/MC/MCInstPrinter.h"
1315
#include "llvm/MC/MCRegisterInfo.h"
@@ -18,14 +20,14 @@
1820

1921
using namespace llvm;
2022

21-
void MCOperand::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
23+
void MCOperand::print(raw_ostream &OS, const MCContext *Ctx) const {
2224
OS << "<MCOperand ";
2325
if (!isValid())
2426
OS << "INVALID";
2527
else if (isReg()) {
2628
OS << "Reg:";
27-
if (RegInfo)
28-
OS << RegInfo->getName(getReg());
29+
if (Ctx && Ctx->getRegisterInfo())
30+
OS << Ctx->getRegisterInfo()->getName(getReg());
2931
else
3032
OS << getReg();
3133
} else if (isImm())
@@ -36,11 +38,14 @@ void MCOperand::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
3638
OS << "DFPImm:" << bit_cast<double>(getDFPImm());
3739
else if (isExpr()) {
3840
OS << "Expr:";
39-
getExpr()->print(OS, nullptr);
41+
if (Ctx)
42+
Ctx->getAsmInfo()->printExpr(OS, *getExpr());
43+
else
44+
getExpr()->print(OS, nullptr);
4045
} else if (isInst()) {
4146
OS << "Inst:(";
4247
if (const auto *Inst = getInst())
43-
Inst->print(OS, RegInfo);
48+
Inst->print(OS, Ctx);
4449
else
4550
OS << "NULL";
4651
OS << ")";
@@ -73,24 +78,23 @@ LLVM_DUMP_METHOD void MCOperand::dump() const {
7378
}
7479
#endif
7580

76-
void MCInst::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
81+
void MCInst::print(raw_ostream &OS, const MCContext *Ctx) const {
7782
OS << "<MCInst " << getOpcode();
7883
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
7984
OS << " ";
80-
getOperand(i).print(OS, RegInfo);
85+
getOperand(i).print(OS, Ctx);
8186
}
8287
OS << ">";
8388
}
8489

8590
void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
86-
StringRef Separator,
87-
const MCRegisterInfo *RegInfo) const {
91+
StringRef Separator, const MCContext *Ctx) const {
8892
StringRef InstName = Printer ? Printer->getOpcodeName(getOpcode()) : "";
89-
dump_pretty(OS, InstName, Separator, RegInfo);
93+
dump_pretty(OS, InstName, Separator, Ctx);
9094
}
9195

9296
void MCInst::dump_pretty(raw_ostream &OS, StringRef Name, StringRef Separator,
93-
const MCRegisterInfo *RegInfo) const {
97+
const MCContext *Ctx) const {
9498
OS << "<MCInst #" << getOpcode();
9599

96100
// Show the instruction opcode name if we have it.
@@ -99,7 +103,7 @@ void MCInst::dump_pretty(raw_ostream &OS, StringRef Name, StringRef Separator,
99103

100104
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
101105
OS << Separator;
102-
getOperand(i).print(OS, RegInfo);
106+
getOperand(i).print(OS, Ctx);
103107
}
104108
OS << ">";
105109
}

0 commit comments

Comments
 (0)