README.md
1# Jupyter Tools for TableGen
2
3This folder contains notebooks relating to TableGen and a Jupyter kernel for
4TableGen.
5
6## Notebooks
7
8[LLVM_TableGen.ipynb](LLVM_TableGen.ipynb) - A demo of the kernel's capabilities.
9
10[tablegen_tutorial_part_1.ipynb](tablegen_tutorial_part_1.ipynb) - A tutorial on the TableGen language.
11
12[sql_query_backend.ipynb](sql_query_backend.ipynb) - How to write a backend using
13JSON output and Python.
14
15Notebooks can be viewed in browser on Github or downloaded and run locally. If
16that is not possible, there are Markdown versions next to the notebook files.
17
18## TableGen Kernel
19
20To use the kernel, first install it into jupyter.
21
22If you have installed Jupyter into a virtual environment, adjust `python3` to
23be the interpreter for that environment. This will ensure that tools run the
24kernel in the correct context.
25
26```shell
27 python3 -m tablegen_kernel.install
28```
29
30If you are going to open the notebook in an IDE like Visual Studio Code,
31you should restart it now so that it will find the newly installed kernel.
32
33Then run one of:
34
35```shell
36 jupyter notebook
37 # Then in the notebook interface, select 'LLVM TableGen' from the 'New' menu.
38
39 # To run the example notebook in this folder.
40 jupyter notebook LLVM_TableGen.ipynb
41
42 # To use the kernel from the command line.
43 jupyter console --kernel tablegen
44```
45
46Or open the notebook in a tool with built in Jupyter support.
47
48`llvm-tblgen` is expected to be either in the `PATH` or you can set
49the environment variable `LLVM_TBLGEN_EXECUTABLE` to point to it directly.
50
51If you see an error like this:
52```shell
53 Cell In[8], line 2
54 // This is some tablegen
55 ^
56SyntaxError: invalid syntax
57```
58
59You are probably running the notebook using the iPython kernel. Make sure you
60 have selected the tablegen kernel.
61
62To run the kernel's doctests do:
63
64```shell
65 python3 tablegen_kernel/kernel.py
66```
67