Skip to content

Generate SQL from TableGen code - This is part of the tutorial "How to write a TableGen backend" in 2021 LLVM Developers' Meeting.

License

Notifications You must be signed in to change notification settings

mshockwave/SQLGen

Repository files navigation

SQLGen

Generate SQL from TableGen code

This is part of the tutorial "How to write a TableGen backend" in 2021 LLVM Developers' Meeting.

Prerequisites

This tool is build against LLVM of this particular Git SHA: 475de8da011c8ae79c453fa43593ec5b35f52962. (Though I think using LLVM 13.0 release also works)

Build

Configuring CMake:

mkdir .build && cd .build
cmake -G Ninja -DLLVM_DIR=/path/to/llvm/install/lib/cmake/llvm ../

Then build:

ninja sqlgen

Example usage

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;
$

Testing

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:

  1. Using the FileCheck command line tool from a LLVM build and put in your PATH. Note that unfortunately, LLVM doesn't ship FileCheck in their release tarball.
  2. The recommended way: install the filecheck python package / command line tool via pip3 install filecheck.

After the lit is installed and FileCheck is setup, launch this command to run the tests:

cd .build
ninja check

About

Generate SQL from TableGen code - This is part of the tutorial "How to write a TableGen backend" in 2021 LLVM Developers' Meeting.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published