@@ -160,7 +160,7 @@ void DecoderTableEmitter::emitULEB128(uint64_t Val) {
160
160
emitByte (Val);
161
161
}
162
162
163
- formatted_raw_ostream &DecoderTableEmitter::emitComment (indent Indent) {
163
+ raw_ostream &DecoderTableEmitter::emitComment (indent Indent) {
164
164
constexpr unsigned CommentColumn = 45 ;
165
165
if (OS.getColumn () > CommentColumn)
166
166
OS << ' \n ' ;
@@ -169,6 +169,23 @@ formatted_raw_ostream &DecoderTableEmitter::emitComment(indent Indent) {
169
169
return OS;
170
170
}
171
171
172
+ namespace {
173
+
174
+ // / Helper class for printing bit ranges.
175
+ struct BitRange {
176
+ unsigned MSB, LSB;
177
+
178
+ friend raw_ostream &operator <<(raw_ostream &OS, BitRange R) {
179
+ if (R.MSB == R.LSB )
180
+ OS << ' [' << R.LSB << ' ]' ;
181
+ else
182
+ OS << ' [' << R.MSB << ' :' << R.LSB << ' ]' ;
183
+ return OS;
184
+ }
185
+ };
186
+
187
+ } // namespace
188
+
172
189
void DecoderTableEmitter::emitCheckAnyNode (const CheckAnyNode *N,
173
190
indent Indent) {
174
191
// TODO: Single-child CheckAny node should be optimized out. For now,
@@ -210,7 +227,7 @@ void DecoderTableEmitter::emitSwitchFieldNode(const SwitchFieldNode *N,
210
227
emitULEB128 (LSB);
211
228
emitUInt8 (Width);
212
229
213
- emitComment (Indent) << " switch Inst[ " << MSB << ' : ' << LSB << " ] {\n " ;
230
+ emitComment (Indent) << " switch Inst" << BitRange{ MSB, LSB} << " {\n " ;
214
231
215
232
for (auto [Val, Child] : drop_end (N->cases ())) {
216
233
emitStartLine ();
@@ -231,7 +248,7 @@ void DecoderTableEmitter::emitSwitchFieldNode(const SwitchFieldNode *N,
231
248
emitNode (Child, Indent + 1 );
232
249
emitComment (Indent) << " }\n " ;
233
250
234
- emitComment (Indent) << " } // switch Inst[ " << MSB << ' : ' << LSB << " ] \n " ;
251
+ emitComment (Indent) << " } // switch Inst" << BitRange{ MSB, LSB} << " \n " ;
235
252
}
236
253
237
254
void DecoderTableEmitter::emitCheckFieldNode (const CheckFieldNode *N,
@@ -246,9 +263,8 @@ void DecoderTableEmitter::emitCheckFieldNode(const CheckFieldNode *N,
246
263
emitUInt8 (Width);
247
264
emitULEB128 (Val);
248
265
249
- emitComment (Indent);
250
- OS << " check Inst[" << MSB << ' :' << LSB << " ] == " << format_hex (Val, 0 )
251
- << ' \n ' ;
266
+ emitComment (Indent) << " check Inst" << BitRange{MSB, LSB}
267
+ << " == " << format_hex (Val, 0 ) << ' \n ' ;
252
268
}
253
269
254
270
void DecoderTableEmitter::emitCheckPredicateNode (const CheckPredicateNode *N,
0 commit comments