1//===--- OptParser.td - Common Option Parsing Interfaces ------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the common interfaces used by the option parsing TableGen
11//  backend.
12//
13//===----------------------------------------------------------------------===//
14
15// Define the kinds of options.
16
17class OptionKind<string name, int precedence = 0, bit sentinel = 0> {
18  string Name = name;
19  // The kind precedence, kinds with lower precedence are matched first.
20  int Precedence = precedence;
21  // Indicate a sentinel option.
22  bit Sentinel = sentinel;
23}
24
25// An option group.
26def KIND_GROUP : OptionKind<"Group">;
27// The input option kind.
28def KIND_INPUT : OptionKind<"Input", 1, 1>;
29// The unknown option kind.
30def KIND_UNKNOWN : OptionKind<"Unknown", 2, 1>;
31// A flag with no values.
32def KIND_FLAG : OptionKind<"Flag">;
33// An option which prefixes its (single) value.
34def KIND_JOINED : OptionKind<"Joined", 1>;
35// An option which is followed by its value.
36def KIND_SEPARATE : OptionKind<"Separate">;
37// An option followed by its values, which are separated by commas.
38def KIND_COMMAJOINED : OptionKind<"CommaJoined">;
39// An option which is which takes multiple (separate) arguments.
40def KIND_MULTIARG : OptionKind<"MultiArg">;
41// An option which is either joined to its (non-empty) value, or followed by its
42// value.
43def KIND_JOINED_OR_SEPARATE : OptionKind<"JoinedOrSeparate">;
44// An option which is both joined to its (first) value, and followed by its
45// (second) value.
46def KIND_JOINED_AND_SEPARATE : OptionKind<"JoinedAndSeparate">;
47// An option which consumes all remaining arguments if there are any.
48def KIND_REMAINING_ARGS : OptionKind<"RemainingArgs">;
49
50// Define the option flags.
51
52class OptionFlag {}
53
54// HelpHidden - The option should not be displayed in --help, even if it has
55// help text. Clients *can* use this in conjunction with the OptTable::PrintHelp
56// arguments to implement hidden help groups.
57def HelpHidden : OptionFlag;
58
59// RenderAsInput - The option should not render the name when rendered as an
60// input (i.e., the option is rendered as values).
61def RenderAsInput : OptionFlag;
62
63// RenderJoined - The option should be rendered joined, even if separate (only
64// sensible on single value separate options).
65def RenderJoined : OptionFlag;
66
67// RenderSeparate - The option should be rendered separately, even if joined
68// (only sensible on joined options).
69def RenderSeparate : OptionFlag;
70
71// Define the option group class.
72
73class OptionGroup<string name> {
74  string EnumName = ?; // Uses the def name if undefined.
75  string Name = name;
76  string HelpText = ?;
77  OptionGroup Group = ?;
78  list<OptionFlag> Flags = [];
79}
80
81// Define the option class.
82
83class Option<list<string> prefixes, string name, OptionKind kind> {
84  string EnumName = ?; // Uses the def name if undefined.
85  list<string> Prefixes = prefixes;
86  string Name = name;
87  OptionKind Kind = kind;
88  // Used by MultiArg option kind.
89  int NumArgs = 0;
90  string HelpText = ?;
91  string MetaVarName = ?;
92  list<OptionFlag> Flags = [];
93  OptionGroup Group = ?;
94  Option Alias = ?;
95  list<string> AliasArgs = [];
96}
97
98// Helpers for defining options.
99
100class Flag<list<string> prefixes, string name>
101  : Option<prefixes, name, KIND_FLAG>;
102class Joined<list<string> prefixes, string name>
103  : Option<prefixes, name, KIND_JOINED>;
104class Separate<list<string> prefixes, string name>
105  : Option<prefixes, name, KIND_SEPARATE>;
106class CommaJoined<list<string> prefixes, string name>
107  : Option<prefixes, name, KIND_COMMAJOINED>;
108class MultiArg<list<string> prefixes, string name, int numargs>
109  : Option<prefixes, name, KIND_MULTIARG> {
110  int NumArgs = numargs;
111}
112class JoinedOrSeparate<list<string> prefixes, string name>
113  : Option<prefixes, name, KIND_JOINED_OR_SEPARATE>;
114class JoinedAndSeparate<list<string> prefixes, string name>
115  : Option<prefixes, name, KIND_JOINED_AND_SEPARATE>;
116
117// Mix-ins for adding optional attributes.
118
119class Alias<Option alias> { Option Alias = alias; }
120class AliasArgs<list<string> aliasargs> { list<string> AliasArgs = aliasargs; }
121class EnumName<string name> { string EnumName = name; }
122class Flags<list<OptionFlag> flags> { list<OptionFlag> Flags = flags; }
123class Group<OptionGroup group> { OptionGroup Group = group; }
124class HelpText<string text> { string HelpText = text; }
125class MetaVarName<string name> { string MetaVarName = name; }
126
127// Predefined options.
128
129// FIXME: Have generator validate that these appear in correct position (and
130// aren't duplicated).
131def INPUT : Option<[], "<input>", KIND_INPUT>;
132def UNKNOWN : Option<[], "<unknown>", KIND_UNKNOWN>;
133