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 // Define the option group class.
90 class OptionGroup<string name> {
91 string EnumName = ?; // Uses the def name if undefined.
94 OptionGroup Group = ?;
97 // Define the option class.
99 class Option<string name, OptionKind kind> {
100 string EnumName = ?; // Uses the def name if undefined.
102 OptionKind Kind = kind;
103 // Used by MultiArg option kind.
106 string MetaVarName = ?;
107 list<OptionFlag> Flags = [];
108 OptionGroup Group = ?;
112 // Helpers for defining options.
114 class Flag<string name> : Option<name, KIND_FLAG>;
115 class Joined<string name> : Option<name, KIND_JOINED>;
116 class Separate<string name> : Option<name, KIND_SEPARATE>;
117 class CommaJoined<string name> : Option<name, KIND_COMMAJOINED>;
118 class MultiArg<string name, int numargs> : Option<name, KIND_MULTIARG> {
119 int NumArgs = numargs;
121 class JoinedOrSeparate<string name> : Option<name, KIND_JOINED_OR_SEPARATE>;
122 class JoinedAndSeparate<string name> : Option<name, KIND_JOINED_AND_SEPARATE>;
124 // Mix-ins for adding optional attributes.
126 class Alias<Option alias> { Option Alias = alias; }
127 class EnumName<string name> { string EnumName = name; }
128 class Flags<list<OptionFlag> flags> { list<OptionFlag> Flags = flags; }
129 class Group<OptionGroup group> { OptionGroup Group = group; }
130 class HelpText<string text> { string HelpText = text; }
131 class MetaVarName<string name> { string MetaVarName = name; }
133 // Predefined options.
135 // FIXME: Have generator validate that these appear in correct position (and
136 // aren't duplicated).
137 def INPUT : Option<"<input>", KIND_INPUT>, Flags<[DriverOption]>;
138 def UNKNOWN : Option<"<unknown>", KIND_UNKNOWN>;