16
16
#include " llvm/MC/MCAsmInfo.h"
17
17
#include " llvm/MC/MCExpr.h"
18
18
#include " llvm/MC/MCInst.h"
19
+ #include " llvm/MC/MCInstPrinter.h"
19
20
#include " llvm/MC/MCRegisterInfo.h"
20
21
#include " llvm/MC/MCSubtargetInfo.h"
21
22
#include " llvm/MC/MCSymbol.h"
@@ -75,7 +76,7 @@ void RISCVInstPrinter::printInst(const MCInst *MI, uint64_t Address,
75
76
}
76
77
77
78
void RISCVInstPrinter::printRegName (raw_ostream &O, MCRegister Reg) const {
78
- O << getRegisterName (Reg);
79
+ markup (O, Markup::Register) << getRegisterName (Reg);
79
80
}
80
81
81
82
void RISCVInstPrinter::printOperand (const MCInst *MI, unsigned OpNo,
@@ -90,7 +91,7 @@ void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
90
91
}
91
92
92
93
if (MO.isImm ()) {
93
- O << MO.getImm ();
94
+ markup (O, Markup::Immediate) << MO.getImm ();
94
95
return ;
95
96
}
96
97
@@ -110,9 +111,9 @@ void RISCVInstPrinter::printBranchOperand(const MCInst *MI, uint64_t Address,
110
111
uint64_t Target = Address + MO.getImm ();
111
112
if (!STI.hasFeature (RISCV::Feature64Bit))
112
113
Target &= 0xffffffff ;
113
- O << formatHex (Target);
114
+ markup (O, Markup::Target) << formatHex (Target);
114
115
} else {
115
- O << MO.getImm ();
116
+ markup (O, Markup::Target) << MO.getImm ();
116
117
}
117
118
}
118
119
@@ -123,11 +124,11 @@ void RISCVInstPrinter::printCSRSystemRegister(const MCInst *MI, unsigned OpNo,
123
124
auto SiFiveReg = RISCVSysReg::lookupSiFiveRegByEncoding (Imm);
124
125
auto SysReg = RISCVSysReg::lookupSysRegByEncoding (Imm);
125
126
if (SiFiveReg && SiFiveReg->haveVendorRequiredFeatures (STI.getFeatureBits ()))
126
- O << SiFiveReg->Name ;
127
+ markup (O, Markup::Register) << SiFiveReg->Name ;
127
128
else if (SysReg && SysReg->haveRequiredFeatures (STI.getFeatureBits ()))
128
- O << SysReg->Name ;
129
+ markup (O, Markup::Register) << SysReg->Name ;
129
130
else
130
- O << Imm;
131
+ markup (O, Markup::Register) << Imm;
131
132
}
132
133
133
134
void RISCVInstPrinter::printFenceArg (const MCInst *MI, unsigned OpNo,
@@ -162,21 +163,21 @@ void RISCVInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNo,
162
163
raw_ostream &O) {
163
164
unsigned Imm = MI->getOperand (OpNo).getImm ();
164
165
if (Imm == 1 ) {
165
- O << " min" ;
166
+ markup (O, Markup::Immediate) << " min" ;
166
167
} else if (Imm == 30 ) {
167
- O << " inf" ;
168
+ markup (O, Markup::Immediate) << " inf" ;
168
169
} else if (Imm == 31 ) {
169
- O << " nan" ;
170
+ markup (O, Markup::Immediate) << " nan" ;
170
171
} else {
171
172
float FPVal = RISCVLoadFPImm::getFPImm (Imm);
172
173
// If the value is an integer, print a .0 fraction. Otherwise, use %g to
173
174
// which will not print trailing zeros and will use scientific notation
174
175
// if it is shorter than printing as a decimal. The smallest value requires
175
176
// 12 digits of precision including the decimal.
176
177
if (FPVal == (int )(FPVal))
177
- O << format (" %.1f" , FPVal);
178
+ markup (O, Markup::Immediate) << format (" %.1f" , FPVal);
178
179
else
179
- O << format (" %.12g" , FPVal);
180
+ markup (O, Markup::Immediate) << format (" %.12g" , FPVal);
180
181
}
181
182
}
182
183
@@ -208,19 +209,20 @@ void RISCVInstPrinter::printVTypeI(const MCInst *MI, unsigned OpNo,
208
209
void RISCVInstPrinter::printRlist (const MCInst *MI, unsigned OpNo,
209
210
const MCSubtargetInfo &STI, raw_ostream &O) {
210
211
unsigned Imm = MI->getOperand (OpNo).getImm ();
211
- O << " {" ;
212
+ auto OS = markup (O, Markup::Register);
213
+ OS << " {" ;
212
214
switch (Imm) {
213
215
case RISCVZC::RLISTENCODE::RA:
214
- O << (ArchRegNames ? " x1" : " ra" );
216
+ OS << (ArchRegNames ? " x1" : " ra" );
215
217
break ;
216
218
case RISCVZC::RLISTENCODE::RA_S0:
217
- O << (ArchRegNames ? " x1, x8" : " ra, s0" );
219
+ OS << (ArchRegNames ? " x1, x8" : " ra, s0" );
218
220
break ;
219
221
case RISCVZC::RLISTENCODE::RA_S0_S1:
220
- O << (ArchRegNames ? " x1, x8-x9" : " ra, s0-s1" );
222
+ OS << (ArchRegNames ? " x1, x8-x9" : " ra, s0-s1" );
221
223
break ;
222
224
case RISCVZC::RLISTENCODE::RA_S0_S2:
223
- O << (ArchRegNames ? " x1, x8-x9, x18" : " ra, s0-s2" );
225
+ OS << (ArchRegNames ? " x1, x8-x9, x18" : " ra, s0-s2" );
224
226
break ;
225
227
case RISCVZC::RLISTENCODE::RA_S0_S3:
226
228
case RISCVZC::RLISTENCODE::RA_S0_S4:
@@ -229,16 +231,16 @@ void RISCVInstPrinter::printRlist(const MCInst *MI, unsigned OpNo,
229
231
case RISCVZC::RLISTENCODE::RA_S0_S7:
230
232
case RISCVZC::RLISTENCODE::RA_S0_S8:
231
233
case RISCVZC::RLISTENCODE::RA_S0_S9:
232
- O << (ArchRegNames ? " x1, x8-x9, x18-" : " ra, s0-" )
233
- << getRegisterName (RISCV::X19 + (Imm - RISCVZC::RLISTENCODE::RA_S0_S3));
234
+ OS << (ArchRegNames ? " x1, x8-x9, x18-" : " ra, s0-" )
235
+ << getRegisterName (RISCV::X19 + (Imm - RISCVZC::RLISTENCODE::RA_S0_S3));
234
236
break ;
235
237
case RISCVZC::RLISTENCODE::RA_S0_S11:
236
- O << (ArchRegNames ? " x1, x8-x9, x18-x27" : " ra, s0-s11" );
238
+ OS << (ArchRegNames ? " x1, x8-x9, x18-x27" : " ra, s0-s11" );
237
239
break ;
238
240
default :
239
241
llvm_unreachable (" invalid register list" );
240
242
}
241
- O << " }" ;
243
+ OS << " }" ;
242
244
}
243
245
244
246
void RISCVInstPrinter::printSpimm (const MCInst *MI, unsigned OpNo,
@@ -256,6 +258,7 @@ void RISCVInstPrinter::printSpimm(const MCInst *MI, unsigned OpNo,
256
258
if (Opcode == RISCV::CM_PUSH)
257
259
Spimm = -Spimm;
258
260
261
+ auto OS = markup (O, Markup::Immediate);
259
262
RISCVZC::printSpimm (Spimm, O);
260
263
}
261
264
0 commit comments