[PATCH] D153915: [llvm] Add include guards to LLVMOption TableGen
Brian Gesiak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 13:39:37 PDT 2023
modocache created this revision.
modocache added reviewers: thakis, jansvoboda11, rriddle.
Herald added a project: All.
modocache requested review of this revision.
Herald added a project: LLVM.
Add include guards that allow multiple includes of `OptParser.td`. This
is helpful when defining multiple sets of options in multiple files.
For example, a user could define a `HelpOptions.td` file that defines
only `-h` and `--help`:
// HelpOptions.td
include "llvm/Option/OptParser.td"
def HelpOptionGroup : OptionGroup<"Help Options">;
def help : Flag<["--", "-"], "help">, Group<HelpOptionGroup>,
Flags<[]>;
def : Flag<["-"], "h">, Group<HelpOptionGroup>, Flags<[]>, Alias<help>;
This file could then be included into any TableGen file that wishes to
define these options:
// MyOptions.td
include "llvm/Option/OptParser.td"
def MyOptionGroup : OptionGroup<"My Options">;
// ...define my options.
// And also define `-h` and `--help`:
include "HelpOptions.td"
This currently isn't possible, because this would result in
`OptParser.td` being included twice. Alternatively, the include of
`OptParser.td` in the `HelpOptions.td` example above could be removed,
but then `llvm-tblgen --gen-opt-parser-defs HelpOptions.td` would fail
(because the `OptionGroup` and `Option` records are defined in
`OptParser.td`).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153915
Files:
llvm/include/llvm/Option/OptParser.td
Index: llvm/include/llvm/Option/OptParser.td
===================================================================
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -11,6 +11,9 @@
//
//===----------------------------------------------------------------------===//
+#ifndef LLVM_OPTION_OPTPARSER_TD
+#define LLVM_OPTION_OPTPARSER_TD
+
// Define the kinds of options.
class OptionKind<string name, int precedence = 0, bit sentinel = false> {
@@ -246,3 +249,5 @@
// aren't duplicated).
def INPUT : Option<[], "<input>", KIND_INPUT>;
def UNKNOWN : Option<[], "<unknown>", KIND_UNKNOWN>;
+
+#endif // LLVM_OPTION_OPTPARSER_TD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153915.535122.patch
Type: text/x-patch
Size: 667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230627/093e306f/attachment.bin>
More information about the llvm-commits
mailing list