2025-10-21 18:25:06 -04:00

55 lines
1.5 KiB
C++

#include "FootInstPrinter.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCRegister.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
#define DEBUG_TYPE "asm-printer"
#define GET_INSTRUCTION_NAME
#define PRINT_ALIAS_INSTR
#include "FootGenAsmWriter.inc"
FootInstPrinter::FootInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
const MCRegisterInfo &MRI)
: MCInstPrinter(MAI, MII, MRI) {}
void FootInstPrinter::printInst(const MCInst *MI, uint64_t Address,
StringRef Annot, const MCSubtargetInfo &STI,
raw_ostream &O) {
if (!PrintAliases || !printAliasInstr(MI, Address, O)) {
printInstruction(MI, Address, O);
}
printAnnotation(O, Annot);
}
void FootInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O) {
const MCOperand &Op = MI->getOperand(OpNo);
if (Op.isReg()) {
unsigned Reg = Op.getReg();
printRegName(O, Reg);
}
else if (Op.isImm()) {
printImm(MI, OpNo, O);
}
else if (Op.isExpr()) {
MAI.printExpr(O, *Op.getExpr());
}
}
void FootInstPrinter::printImm(const MCInst *MI, unsigned OpNo,
raw_ostream &O) {
const MCOperand &Op = MI->getOperand(OpNo);
markup(O, Markup::Immediate) << "#" << formatImm(Op.getImm());
}
void FootInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) {
markup(O, Markup::Register) << getRegisterName(Reg);
}