To support variable length instructions, I think of them as fixed length instructions with the "maximum length". For example, if there're three instructions with 2, 6 and 9 bytes, we can fit them into the algorithm by treating them all as 9 bytes.
Also, since we can't know the length of the instruction in advance, there is a function object with type void(APInt &, uint64_t) added in the parameter list of decodeInstruction and fieldFromInstruction. We can use this to supply the additional bits the decoder needs after we know the opcode of the instruction.
Finally, InstrLenTable is added to let the decoder know the length of the instructions.
See D120960 for its usage.
I still prefer the decoder's tests either go under the FixedLenDecoderEmitter's folder or at least putting into a separate file.