Files
clang-p2996/llvm/utils/TableGen
David Spickett b81bfea99b [llvm][TableGen] Add a README to the main TableGen folder (#69943)
Though I doubt that many people will land here directly, I thought it
odd that we didn't have one we can at least reference in response to questions.

The intro I've copied from the programmer's reference and added a simple
example. Then some links to resources and tools, which is the main
reason to have this page.
2023-10-25 09:45:31 +01:00
..

LLVM TableGen

The purpose of TableGen is to generate complex output files based on information from source files that are significantly easier to code than the output files would be, and also easier to maintain and modify over time.

The information is coded in a declarative style involving classes and records, which are then processed by TableGen.

class Hello <string _msg> {
  string msg = !strconcat("Hello ", _msg);
}

def HelloWorld: Hello<"world!"> {}
------------- Classes -----------------
class Hello<string Hello:_msg = ?> {
  string msg = !strconcat("Hello ", Hello:_msg);
}
------------- Defs -----------------
def HelloWorld {        // Hello
  string msg = "Hello world!";
}

The internalized records are passed on to various backends, which extract information from a subset of the records and generate one or more output files.

These output files are typically .inc files for C++, but may be any type of file that the backend developer needs.

Resources for learning the language:

Writing TableGen backends:

TableGen in MLIR:

Useful tools: