Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Create a new folder called InstPrinter inside the TOY folder:

    $ cd lib/Target/TOY
    $ mkdir InstPrinter
    
  2. In a new file, called TOYInstrFormats.td, define the AsmString 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;
    }
  3. Create a new file called TOYInstPrinter.cpp, and define the printOperand function, as follows...