Experimenting with the TableGen language
Very often, beginners feel overwhelmed by the TableGen language. But as soon as you start experimenting with the language, it becomes much easier.
Defining records and classes
Let’s define a simple record for an instruction:
def ADD { string Mnemonic = "add"; int Opcode = 0xA0; }
The def
keyword signals that you define a record. It is followed by the name of the record. The record body is surrounded by curly braces, and the body consists of field definitions, similar to a structure in C++.
You can use the llvm-tblgen
tool to see the generated records. Save the preceding source code in an inst.td
file and run the following:
$ llvm-tblgen --print-records inst.td ------------- Classes ----------------- ------------- Defs ----------------- def ADD { string Mnemonic = "add"; int Opcode = 160; }
This is not yet exciting; it only shows the defined record was...