@@ -2261,14 +2261,23 @@ static void insertBits(InsnType &field, InsnType bits, unsigned startBit,
2261
2261
// emitDecodeInstruction - Emit the templated helper function
2262
2262
// decodeInstruction().
2263
2263
static void emitDecodeInstruction (formatted_raw_ostream &OS, bool IsVarLenInst,
2264
- unsigned OpcodeMask) {
2264
+ unsigned OpcodeMask,
2265
+ StringRef SpecializedInsnType) {
2265
2266
const bool HasTryDecode = OpcodeMask & ((1 << MCD::OPC_TryDecode) |
2266
2267
(1 << MCD::OPC_TryDecodeOrFail));
2267
2268
const bool HasCheckPredicate =
2268
2269
OpcodeMask &
2269
2270
((1 << MCD::OPC_CheckPredicate) | (1 << MCD::OPC_CheckPredicateOrFail));
2270
2271
const bool HasSoftFail = OpcodeMask & (1 << MCD::OPC_SoftFail);
2271
2272
2273
+ auto emitTemplate = [&OS, SpecializedInsnType] {
2274
+ if (SpecializedInsnType.empty ())
2275
+ OS << " template <typename InsnType>\n " ;
2276
+ };
2277
+
2278
+ StringRef InsnType =
2279
+ SpecializedInsnType.empty () ? " InsnType" : SpecializedInsnType;
2280
+
2272
2281
OS << R"(
2273
2282
static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
2274
2283
unsigned NumToSkip = *Ptr++;
@@ -2277,11 +2286,13 @@ static unsigned decodeNumToSkip(const uint8_t *&Ptr) {
2277
2286
if (getNumToSkipInBytes () == 3 )
2278
2287
OS << " NumToSkip |= (*Ptr++) << 16;\n " ;
2279
2288
OS << R"( return NumToSkip;
2280
- }
2289
+ })" ;
2281
2290
2282
- template <typename InsnType>
2283
- static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
2284
- InsnType insn, uint64_t Address,
2291
+ emitTemplate ();
2292
+ OS << R"(
2293
+ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI, )" ;
2294
+ OS << InsnType << " insn,\n " ;
2295
+ OS << R"( uint64_t Address,
2285
2296
const MCDisassembler *DisAsm,
2286
2297
const MCSubtargetInfo &STI)" ;
2287
2298
if (IsVarLenInst) {
@@ -2802,7 +2813,11 @@ namespace {
2802
2813
emitPredicateFunction (OS, TableInfo.Predicates , indent (0 ));
2803
2814
2804
2815
// Emit the main entry point for the decoder, decodeInstruction().
2805
- emitDecodeInstruction (OS, IsVarLenInst, OpcodeMask);
2816
+ // Generate non-templated code if exactly one InsnCPPType was specified.
2817
+ StringRef SpecializedInsnType =
2818
+ NonTemplatedInsnTypes.size () == 1 ? NonTemplatedInsnTypes[0 ].CPPType : " " ;
2819
+
2820
+ emitDecodeInstruction (OS, IsVarLenInst, OpcodeMask, SpecializedInsnType);
2806
2821
2807
2822
OS << " \n } // namespace\n " ;
2808
2823
}
0 commit comments