@@ -84,7 +84,7 @@ static cl::opt<bool> LargeTable(
84
84
" in the table instead of the default 16 bits." ),
85
85
cl::init(false ), cl::cat(DisassemblerEmitterCat));
86
86
87
- static cl::opt<bool > UseFnTableInDecodeToMCInst (
87
+ static cl::opt<bool > UseFnTableInDecodetoMCInst (
88
88
" use-fn-table-in-decode-to-mcinst" ,
89
89
cl::desc (
90
90
" Use a table of function pointers instead of a switch case in the\n "
@@ -251,8 +251,7 @@ class DecoderEmitter {
251
251
//
252
252
// BIT_UNFILTERED is used as the init value for a filter position. It is used
253
253
// only for filter processings.
254
- class BitValue {
255
- public:
254
+ struct BitValue {
256
255
enum bit_value_t : uint8_t {
257
256
BIT_FALSE, // '0'
258
257
BIT_TRUE, // '1'
@@ -261,25 +260,37 @@ class BitValue {
261
260
};
262
261
263
262
BitValue (bit_value_t V) : V(V) {}
264
- BitValue (const Init *Init) {
265
- if (const BitInit *Bit = dyn_cast<BitInit>(Init))
263
+ explicit BitValue (const Init *Init) {
264
+ if (const auto *Bit = dyn_cast<BitInit>(Init))
266
265
V = Bit->getValue () ? BIT_TRUE : BIT_FALSE;
267
266
else
268
267
V = BIT_UNSET;
269
268
}
270
269
BitValue (const BitsInit &Bits, unsigned Idx) : BitValue(Bits.getBit(Idx)) {}
271
270
272
- bool isSet (void ) const { return V == BIT_TRUE || V == BIT_FALSE; }
273
- bool isUnset (void ) const { return V == BIT_UNSET; }
274
- std::optional<uint64_t > getValue (void ) const {
271
+ bool isSet () const { return V == BIT_TRUE || V == BIT_FALSE; }
272
+ bool isUnset () const { return V == BIT_UNSET; }
273
+ std::optional<uint64_t > getValue () const {
275
274
if (isSet ())
276
275
return static_cast <uint64_t >(V);
277
276
return std::nullopt;
278
277
}
279
278
bit_value_t getRawValue () const { return V; }
280
279
281
280
// For printing a bit value.
282
- operator StringRef () const { return StringRef (" 01_." ).slice (V, V + 1 ); }
281
+ operator StringRef () const {
282
+ switch (V) {
283
+ case BIT_FALSE:
284
+ return " 0" ;
285
+ case BIT_TRUE:
286
+ return " 1" ;
287
+ case BIT_UNSET:
288
+ return " _" ;
289
+ case BIT_UNFILTERED:
290
+ return " ." ;
291
+ }
292
+ llvm_unreachable (" Unknow bit value" );
293
+ }
283
294
284
295
bool operator ==(bit_value_t Other) const { return Other == V; }
285
296
bool operator !=(bit_value_t Other) const { return Other != V; }
@@ -318,7 +329,7 @@ static const BitsInit &getBitsField(const Record &Def, StringRef FieldName) {
318
329
else if (const BitInit *BI = dyn_cast<BitInit>(SI.Value ))
319
330
Bits.push_back (BI);
320
331
else
321
- Bits.insert (Bits. end (), SI.BitWidth , UnsetInit::get (Def.getRecords ()));
332
+ Bits.append ( SI.BitWidth , UnsetInit::get (Def.getRecords ()));
322
333
}
323
334
324
335
return *BitsInit::get (Def.getRecords (), Bits);
@@ -1072,7 +1083,7 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
1072
1083
" DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const "
1073
1084
" MCDisassembler *Decoder, bool &DecodeComplete" ;
1074
1085
1075
- if (UseFnTableInDecodeToMCInst ) {
1086
+ if (UseFnTableInDecodetoMCInst ) {
1076
1087
// Emit a function for each case first.
1077
1088
for (const auto &[Index, Decoder] : enumerate(Decoders)) {
1078
1089
OS << Indent << " template <typename InsnType>\n " ;
@@ -1095,7 +1106,7 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
1095
1106
Indent += 2 ;
1096
1107
OS << Indent << " DecodeComplete = true;\n " ;
1097
1108
1098
- if (UseFnTableInDecodeToMCInst ) {
1109
+ if (UseFnTableInDecodetoMCInst ) {
1099
1110
// Build a table of function pointers.
1100
1111
OS << Indent << " using DecodeFnTy = DecodeStatus (*)(" << DecodeParams
1101
1112
<< " );\n " ;
@@ -1282,7 +1293,7 @@ std::pair<unsigned, bool> FilterChooser::getDecoderIndex(DecoderSet &Decoders,
1282
1293
// FIXME: emitDecoder() function can take a buffer directly rather than
1283
1294
// a stream.
1284
1295
raw_svector_ostream S (Decoder);
1285
- indent Indent (UseFnTableInDecodeToMCInst ? 2 : 4 );
1296
+ indent Indent (UseFnTableInDecodetoMCInst ? 2 : 4 );
1286
1297
bool HasCompleteDecoder = emitDecoder (S, Indent, Opc);
1287
1298
1288
1299
// Using the full decoder string as the key value here is a bit
@@ -1430,16 +1441,13 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
1430
1441
if (B != BitValue::BIT_TRUE)
1431
1442
continue ;
1432
1443
1433
- switch (IB.getRawValue ()) {
1434
- case BitValue::BIT_FALSE:
1444
+ if (IB == BitValue::BIT_FALSE) {
1435
1445
// The bit is meant to be false, so emit a check to see if it is true.
1436
1446
PositiveMask.setBit (i);
1437
- break ;
1438
- case BitValue::BIT_TRUE:
1447
+ } else if (IB == BitValue::BIT_TRUE) {
1439
1448
// The bit is meant to be true, so emit a check to see if it is false.
1440
1449
NegativeMask.setBit (i);
1441
- break ;
1442
- default :
1450
+ } else {
1443
1451
// The bit is not set; this must be an error!
1444
1452
errs () << " SoftFail Conflict: bit SoftFail{" << i << " } in "
1445
1453
<< AllInstructions[Opc] << " is set but Inst{" << i
0 commit comments