mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 09:23:52 -05:00
LLVM TableGen is used to generate complex output files in the llvm project. A generic description of classes and definitions produces "records" that can then be walked by a TableGen backend to produce things like C++ code, configuration files, etc. The biggest examples are LLVM's assembler and disassembler where all the targets' instructions are defined in TableGen. https://llvm.org/docs/TableGen/ProgRef.html An example: ``` class Register<int _size, string _alias=""> { int size = _size; string alias = _alias; } def X0: Register<8> {} def X29: Register<8, "frame pointer"> {} ``` ``` ------------- Classes ----------------- class Register<int Register:_size = ?, string Register:_alias = ""> { int size = Register:_size; string alias = Register:_alias; } ------------- Defs ----------------- def X0 { // Register int size = 8; string alias = ""; } def X29 { // Register int size = 8; string alias = "frame pointer"; } ``` It's often a pain point for people new to LLVM so having a quick way to experiment would be a great benefit for the community (we have a Jupyter kernel which is good but not as simple as Compiler Explorer). The compiler for TableGen is `llvm-tblgen`. This comes with most release builds of LLVM in /bin along with clang and the others. Its default is to output a text dump of the records defined so that's what I've used here. This is not executable code so I've disabled the features related to that. A user could pass options to `llvm-tblgen` to produce text in a format other than this, C++ code or JSON for example. However this text dump is the main use case. I've re-used an existing clang install, since that includes `llvm-tblgen` in `bin/`. I just added the 17.01 version for this first change. Syntax highlighting is a mix of the Fortran and Ada configuration, following the language spec I linked above. Though I am very new to that so it is likely incomplete.
8 lines
162 B
TableGen
8 lines
162 B
TableGen
class Register<int _size, string _alias=""> {
|
|
int size = _size;
|
|
string alias = _alias;
|
|
}
|
|
|
|
def X0: Register<8> {}
|
|
|
|
def X29: Register<8, "frame pointer"> {} |