[llvm] [Option] Declare library command line options in TableGen (PR #226087)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 00:48:17 PDT 2026
================
@@ -1564,3 +1564,39 @@ TODO: complete this section
:::{todo}
TODO: fill in this section
:::
+
+## Declaring a Library's Options in TableGen
+
+A library can declare its options in a `.td` file instead of as `cl::opt` globals.
+`llvm-tblgen -gen-opt-parser-defs` generates a struct with a member per option,
+the table that parses them, and the hooks through which
+`cl::ParseCommandLineOptions` parses them and `-help-hidden` lists them.
+
+```text
+include "llvm/Option/OptParser.td"
+
+def FooOptions : OptionsStruct;
+
+defm : BoolField<"foo-enable", "1", "Enable foo">;
+defm : ValueField<"foo-threshold", "unsigned", "8", "The threshold">;
+let Hidden = 0 in
+defm : ValueField<"foo-path", "StringRef", "", "The input path">;
----------------
aengelke wrote:
Should add an example with a non-empty default string to show that the default value really is the default initializer code.
https://github.com/llvm/llvm-project/pull/226087
More information about the llvm-commits
mailing list