This is part of the tutorial "How to write a TableGen backend" in 2021 LLVM Developers' Meeting.
This tool is build against LLVM of this particular Git SHA: 475de8da011c8ae79c453fa43593ec5b35f52962
.
(Though I think using LLVM 13.0 release also works)
Configuring CMake:
mkdir .build && cd .build
cmake -G Ninja -DLLVM_DIR=/path/to/llvm/install/lib/cmake/llvm ../
Then build:
ninja sqlgen
Given the following TableGen file SampleQuery.td
:
class Query <string table, dag query_fields = (all), dag condition = (none)> {
string TableName = table;
dag Fields = query_fields;
dag WhereClause = condition;
list<string> OrderedBy = [];
}
def : Query<"Orders", (fields "Person", "Amount")>;
We can use the following command to generate the corresponding SQL query:
$ .build/sqlgen SampleQuery.td -o SampleQuery.sql
$ cat SampleQuery.sql
SELECT Person, Amount FROM Orders;
$
SQLGen is using LLVM LIT as the testing harness. Please install it first:
pip3 install lit
SQLGen is also using the functionality of FileCheck. However, we support two variants of FileCheck:
- Using the
FileCheck
command line tool from a LLVM build and put in your PATH. Note that unfortunately, LLVM doesn't shipFileCheck
in their release tarball. - The recommended way: install the
filecheck
python package / command line tool viapip3 install filecheck
.
After the lit
is installed and FileCheck is setup, launch this command to run the tests:
cd .build
ninja check