[llvm] 1e31cdf - [llvm] Add include guards to LLVMOption TableGen

Brian Gesiak via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 17:21:38 PDT 2023


Author: Brian Gesiak
Date: 2023-06-27T20:21:31-04:00
New Revision: 1e31cdfbb152f00c30b5eacc8a50104c00753f2d

URL: https://github.com/llvm/llvm-project/commit/1e31cdfbb152f00c30b5eacc8a50104c00753f2d
DIFF: https://github.com/llvm/llvm-project/commit/1e31cdfbb152f00c30b5eacc8a50104c00753f2d.diff

LOG: [llvm] Add include guards to LLVMOption TableGen

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`).

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D153915

Added: 
    

Modified: 
    llvm/include/llvm/Option/OptParser.td

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td
index 9c73f478db5e0..94b945defac11 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/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 @@ class ValueExtractor<code extractor> { code ValueExtractor = extractor; }
 // aren't duplicated).
 def INPUT : Option<[], "<input>", KIND_INPUT>;
 def UNKNOWN : Option<[], "<unknown>", KIND_UNKNOWN>;
+
+#endif // LLVM_OPTION_OPTPARSER_TD


        


More information about the llvm-commits mailing list