Printing an instruction
Printing an assembly instruction is an important step in generating target code. Various classes are defined that work as a gateway to the streamers.
First, we initialize the class for instruction, assigning the operands, the assembly string, pattern, the output variable, and so on in the TOYInstrFormats.td
file:
class InstTOY<dag outs, dag ins, string asmstr, list<dag> pattern> : Instruction { field bits<32> Inst; let Namespace = "TOY"; dag OutOperandList = outs; dag InOperandList = ins; let AsmString = asmstr; let Pattern = pattern; let Size = 4; }
Then, we define functions to print operands in TOYInstPrinter.cpp
.
void TOYInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) { const MCOperand &Op = MI->getOperand(OpNo); if (Op.isReg()) { printRegName(O, Op.getReg()); return; } if (Op.isImm()) { O << "#" << Op.getImm(); return; ...