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. The instruction string is provided by the .td
file defined earlier.
Getting ready
The first and foremost step for printing instructions is to define the instruction string in the .td
file, which was done in the Defining the instruction set recipe.
How to do it…
Perform the following steps:
Create a new folder called
InstPrinter
inside theTOY
folder:$ cd lib/Target/TOY $ mkdir InstPrinter
In a new file, called
TOYInstrFormats.td
, define theAsmString
variable: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; }
Create a new file called
TOYInstPrinter.cpp
, and define theprintOperand
function, as follows...