Understanding the TableGen language
LLVM comes with its own domain-specific language (DSL) called TableGen. It is used to generate C++ code for a wide range of use cases, thus reducing the amount of code a developer has to produce. The TableGen language is not a full-fledged programming language. It is only used to define records, which is a fancy word for a collection of names and values. To understand why such a restricted language is useful, let’s examine two examples.
Typical data you need to define one machine instruction of a CPU is:
- The mnemonic of the instruction
- The bit pattern
- The number and types of operands
- Possible restrictions or side effects
It is easy to see that this data can be represented as a record. For example, a field named asmstring
could hold the value of the mnemonic; say, "add"
. Also, a field named opcode
could hold the binary representation of the instruction. Together, the record would describe an additional...