Is there an easy to way to get the printing of an MCInstr such that I can split out the MCOperands and the mnemonic ?
So far I have come up with the following code snippet:
const llvm::MCContext &Ctx = getContext();
const llvm::MCAsmInfo *MAI = Ctx.getAsmInfo();
const llvm::MCRegisterInfo *MRI = Ctx.getRegisterInfo();
const llvm::Triple &TheTriple = Ctx.getTargetTriple();
std::string Error;
const Target *Target = TargetRegistry::lookupTarget(TheTriple.str(), Error);
unsigned AsmVariant = 0; // typically 0 for the default assembly variant
std::unique_ptr<const MCInstrInfo> MII(Target->createMCInstrInfo());
std::unique_ptr<llvm::MCInstPrinter> Printer(Target->createMCInstPrinter(TheTriple, AsmVariant, *MAI, *MII, *MRI));
Printer->printInst(&Inst, 0, "", STI, dbgs());
This prints out the assembly nicely as single whole lines but I’d love to be able to capture them individually as I am storing them in a structure.
Bonus points: I’m trying to find a way also for MCFixup to have a reference to the operand it needs to fixup rather than merely the offset.