#include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDisassembler.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/SubtargetFeature.h" ... MCInst Instruction; // Set up the instruction's operands and opcode... // ... const MCDisassembler *Disassembler = Target->createMCDisassembler(*STI); const MCInstPrinter *Printer = Target->createMCInstPrinter( Triple(TT), AsmInfo->getAssemblerDialect(), *AsmInfo, *InstrInfo, *RegInfo); // Print the assembly code for the instruction Printer->printInst(&Instruction, OS, "", *STI);
#include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstPrinter.h" ... MCInst Instruction; // Set up the instruction's operands and opcode... // ... const MCInstrInfo *InstrInfo = STI->getInstrInfo(); const MCInstPrinter *Printer = Target->createMCInstPrinter( Triple(TT), AsmInfo->getAssemblerDialect(), *AsmInfo, *InstrInfo, *RegInfo); // Convert the instruction to a human-readable string std::string Str; raw_string_ostream OS(Str); Printer->printInst(&Instruction, OS, "", *STI); // Use the string as needed...This example shows how to convert a machine instruction to a human-readable string using MCInst and an MCInstPrinter object. These examples are part of the LLVM project and can be found in the 'llvm/lib/MC/MCInst.cpp' file.