This changes the default mode to cache the code blocks we're asked to compile until we see the new `%reset` magic to clear that cache. This means that if you run several cells in sequence, at the end you're compiling the code from all the cells at once. This emulates what the ipython kernel does where it uses a persistent interpreter state by default. `%reset` will only be acted on when it's in the cell we're asked to run (the newest code). `%args` we will use the most recent value we have cached. The example notebook has been updated to explain that. Depends on D132378 Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D132646
2.8 KiB
2.8 KiB
LLVM TableGen Kernel
This notebook is running llvm-tblgen.
%reset
// This is some tablegen
class Foo {}
------------- Classes -----------------
class Foo {
}
------------- Defs -----------------
Errors printed to stderr are shown.
%reset
This is not tablegen.
<stdin>:1:1: error: Unexpected token at top level
This is not tablegen.
^
Add some classes to get some output.
%reset
class Stuff {}
def thing : Stuff {}
------------- Classes -----------------
class Stuff {
}
------------- Defs -----------------
def thing { // Stuff
}
By default cells are connected. Meaning that we cache the code and magic directives from the previously run cells.
This means that the next cell still sees the Stuff class.
def other_thing : Stuff {}
------------- Classes -----------------
class Stuff {
}
------------- Defs -----------------
def other_thing { // Stuff
}
def thing { // Stuff
}
You can use the magic %reset to clear this cache and start fresh.
%reset
def other_thing : Stuff {}
<stdin>:1:19: error: Couldn't find class 'Stuff'
def other_thing : Stuff {}
^
There is a "magic" directive %args that you can use to send command line arguments to llvm-tblgen.
For example, here we have some code that shows a warning.
%reset
class Thing <int A, int B> {
int num = A;
}
<stdin>:1:25: warning: unused template argument: Thing:B
class Thing <int A, int B> {
^
We can pass an argument to ignore that warning.
%args --no-warn-on-unused-template-args
------------- Classes -----------------
class Thing<int Thing:A = ?, int Thing:B = ?> {
int num = Thing:A;
}
------------- Defs -----------------
If you have a run of cells without a %reset, the most recent %args is used.
// This passes --no-warn-on-unused-template-args
------------- Classes -----------------
class Thing<int Thing:A = ?, int Thing:B = ?> {
int num = Thing:A;
}
------------- Defs -----------------
%args
// Now we're not passing the argument so the warning comes back.
<stdin>:1:25: warning: unused template argument: Thing:B
class Thing <int A, int B> {
^
If there are many %args in a cell, the last one is used.
%reset
%args --no-warn-on-unused-template-args
%args
class Thing <int A, int B> {}
<stdin>:1:18: warning: unused template argument: Thing:A
class Thing <int A, int B> {}
^
<stdin>:1:25: warning: unused template argument: Thing:B
class Thing <int A, int B> {}
^