1 //===--- OptParser.td - Common Option Parsing Interfaces ------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the common interfaces used by the option parsing TableGen
13 //===----------------------------------------------------------------------===//
15 // Define the kinds of options.
17 class OptionKind<string name, int predecence = 0, bit sentinel = 0> {
19 // The kind precedence, kinds with lower precedence are matched first.
20 int Precedence = predecence;
21 // Indicate a sentinel option.
22 bit Sentinel = sentinel;
26 def KIND_GROUP : OptionKind<"Group">;
27 // The input option kind.
28 def KIND_INPUT : OptionKind<"Input", 1, 1>;
29 // The unknown option kind.
30 def KIND_UNKNOWN : OptionKind<"Unknown", 2, 1>;
31 // A flag with no values.
32 def KIND_FLAG : OptionKind<"Flag">;
33 // An option which prefixes its (single) value.
34 def KIND_JOINED : OptionKind<"Joined", 1>;
35 // An option which is followed by its value.
36 def KIND_SEPARATE : OptionKind<"Separate">;
37 // An option followed by its values, which are separated by commas.
38 def KIND_COMMAJOINED : OptionKind<"CommaJoined">;
39 // An option which is which takes multiple (separate) arguments.
40 def KIND_MULTIARG : OptionKind<"MultiArg">;
41 // An option which is either joined to its (non-empty) value, or followed by its
43 def KIND_JOINED_OR_SEPARATE : OptionKind<"JoinedOrSeparate">;
44 // An option which is both joined to its (first) value, and followed by its
46 def KIND_JOINED_AND_SEPARATE : OptionKind<"JoinedAndSeparate">;
48 // Define the option flags.
52 // DriverOption - The option is a "driver" option, and should not be forwarded
54 def DriverOption : OptionFlag;
56 // LinkerInput - The option is a linker input.
57 def LinkerInput : OptionFlag;
59 // NoArgumentUnused - Don't report argument unused warnings for this option; this
60 // is useful for options like -static or -dynamic which a user may always end up
61 // passing, even if the platform defaults to (or only supports) that option.
62 def NoArgumentUnused : OptionFlag;
64 // RenderAsInput - The option should not render the name when rendered as an
65 // input (i.e., the option is rendered as values).
66 def RenderAsInput : OptionFlag;
68 // RenderJoined - The option should be rendered joined, even if separate (only
69 // sensible on single value separate options).
70 def RenderJoined : OptionFlag;
72 // RenderSeparate - The option should be rendered separately, even if joined
73 // (only sensible on joined options).
74 def RenderSeparate : OptionFlag;
76 // Unsupported - The option is unsupported, and the driver will reject command
78 def Unsupported : OptionFlag;
80 // HelpHidden - The option should not be displayed in --help, even if it has
81 // help text. Clients *can* use this in conjunction with the OptTable::PrintHelp
82 // arguments to implement hidden help groups.
83 def HelpHidden : OptionFlag;
85 // NoForward - The option should not be implicitly forwarded to other tools.
86 def NoForward : OptionFlag;
88 // CC1Option - This option should be accepted by clang -cc1.
89 def CC1Option : OptionFlag;
91 // NoDriverOption - This option should not be accepted by the driver.
92 def NoDriverOption : OptionFlag;
94 // Define the option group class.
96 class OptionGroup<string name> {
97 string EnumName = ?; // Uses the def name if undefined.
100 OptionGroup Group = ?;
103 // Define the option class.
105 class Option<list<string> prefixes, string name, OptionKind kind> {
106 string EnumName = ?; // Uses the def name if undefined.
107 list<string> Prefixes = prefixes;
109 OptionKind Kind = kind;
110 // Used by MultiArg option kind.
113 string MetaVarName = ?;
114 list<OptionFlag> Flags = [];
115 OptionGroup Group = ?;
119 // Helpers for defining options.
121 class Flag<list<string> prefixes, string name>
122 : Option<prefixes, name, KIND_FLAG>;
123 class Joined<list<string> prefixes, string name>
124 : Option<prefixes, name, KIND_JOINED>;
125 class Separate<list<string> prefixes, string name>
126 : Option<prefixes, name, KIND_SEPARATE>;
127 class CommaJoined<list<string> prefixes, string name>
128 : Option<prefixes, name, KIND_COMMAJOINED>;
129 class MultiArg<list<string> prefixes, string name, int numargs>
130 : Option<prefixes, name, KIND_MULTIARG> {
131 int NumArgs = numargs;
133 class JoinedOrSeparate<list<string> prefixes, string name>
134 : Option<prefixes, name, KIND_JOINED_OR_SEPARATE>;
135 class JoinedAndSeparate<list<string> prefixes, string name>
136 : Option<prefixes, name, KIND_JOINED_AND_SEPARATE>;
138 // Mix-ins for adding optional attributes.
140 class Alias<Option alias> { Option Alias = alias; }
141 class EnumName<string name> { string EnumName = name; }
142 class Flags<list<OptionFlag> flags> { list<OptionFlag> Flags = flags; }
143 class Group<OptionGroup group> { OptionGroup Group = group; }
144 class HelpText<string text> { string HelpText = text; }
145 class MetaVarName<string name> { string MetaVarName = name; }
147 // Predefined options.
149 // FIXME: Have generator validate that these appear in correct position (and
150 // aren't duplicated).
151 def INPUT : Option<[], "<input>", KIND_INPUT>, Flags<[DriverOption,CC1Option]>;
152 def UNKNOWN : Option<[], "<unknown>", KIND_UNKNOWN>;