From 28e607057cb87c6dadde0f4f32abf3adf32361e3 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Mon, 6 Nov 2023 23:32:24 +0000 Subject: [PATCH] LLVM TableGen: Improve docstring for Actions Override and add example (#5711) A majority of the actions/backends expect to find certain classes and definitions in the source code. There's no canonical reference for this so it's a combination of incomplete docs and the actual uses in llvm-project. (most of the time I expect people will come from llvm-project to experiment, rather than the other way around) I've added an example that uses the Searchable Tables backend. --- examples/tablegen/searchable_tables.td | 20 ++++++++++++++++++++ lib/compilers/tablegen.ts | 8 +++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 examples/tablegen/searchable_tables.td diff --git a/examples/tablegen/searchable_tables.td b/examples/tablegen/searchable_tables.td new file mode 100644 index 000000000..605464bb8 --- /dev/null +++ b/examples/tablegen/searchable_tables.td @@ -0,0 +1,20 @@ +// This example uses the Searchable Tables backend, aka --gen-searchable-tables. +// To choose the backend, select it as the "Action" in the "Overrides" menu, +// or add "--gen-searchable-tables" to the compiler options. +// For more details: +// https://llvm.org/docs/TableGen/BackEnds.html#searchabletables-reference + +include "llvm/TableGen/SearchableTable.td" + +class Pair : SearchableTable { + let SearchableFields = ["Name", "Value"]; + let EnumValueField = "Value"; + + string Name = name; + bits<2> Value = value; +} + +def : Pair<"Example 0", 0b00>; +def : Pair<"Example 1", 0b01>; +def : Pair<"Example 2", 0b10>; +def : Pair<"Example 3", 0b11>; \ No newline at end of file diff --git a/lib/compilers/tablegen.ts b/lib/compilers/tablegen.ts index 1ce51f2cc..04acf3ce0 100644 --- a/lib/compilers/tablegen.ts +++ b/lib/compilers/tablegen.ts @@ -32,7 +32,13 @@ export class TableGenCompiler extends BaseCompiler { display_title: 'Action', description: 'The action to perform, which is the backend you wish to ' + - 'run. By default, the records are just printed as text.', + 'run. By default, the records are just printed as text. ' + + 'Many backends expect to find certain classes and defnitions ' + + 'in your source code. You may find details of those in the ' + + 'documentation, ' + + 'but if not, refer to use of the backend in the ' + + 'LLVM Project ' + + 'by searching for the command line name e.g. "gen-attrs".', flags: [''], values: possibleActions, default: '--print-records',