• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 predecence = 0, bit sentinel = 0> {
18  string Name = name;
19  // The kind precedence, kinds with lower precedence are matched first.
20  int Precedence = predecence;
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
48// Define the option flags.
49
50class OptionFlag {}
51
52// DriverOption - The option is a "driver" option, and should not be forwarded
53// to gcc.
54def DriverOption : OptionFlag;
55
56// LinkerInput - The option is a linker input.
57def LinkerInput : OptionFlag;
58
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.
62def NoArgumentUnused : OptionFlag;
63
64// RenderAsInput - The option should not render the name when rendered as an
65// input (i.e., the option is rendered as values).
66def RenderAsInput : OptionFlag;
67
68// RenderJoined - The option should be rendered joined, even if separate (only
69// sensible on single value separate options).
70def RenderJoined : OptionFlag;
71
72// RenderSeparate - The option should be rendered separately, even if joined
73// (only sensible on joined options).
74def RenderSeparate : OptionFlag;
75
76// Unsupported - The option is unsupported, and the driver will reject command
77// lines that use it.
78def Unsupported : OptionFlag;
79
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.
83def HelpHidden : OptionFlag;
84
85// NoForward - The option should not be implicitly forwarded to other tools.
86def NoForward : OptionFlag;
87
88// CC1Option - This option should be accepted by clang -cc1.
89def CC1Option : OptionFlag;
90
91// Define the option group class.
92
93class OptionGroup<string name> {
94  string EnumName = ?; // Uses the def name if undefined.
95  string Name = name;
96  string HelpText = ?;
97  OptionGroup Group = ?;
98}
99
100// Define the option class.
101
102class Option<string name, OptionKind kind> {
103  string EnumName = ?; // Uses the def name if undefined.
104  string Name = name;
105  OptionKind Kind = kind;
106  // Used by MultiArg option kind.
107  int NumArgs = 0;
108  string HelpText = ?;
109  string MetaVarName = ?;
110  list<OptionFlag> Flags = [];
111  OptionGroup Group = ?;
112  Option Alias = ?;
113}
114
115// Helpers for defining options.
116
117class Flag<string name> : Option<name, KIND_FLAG>;
118class Joined<string name> : Option<name, KIND_JOINED>;
119class Separate<string name> : Option<name, KIND_SEPARATE>;
120class CommaJoined<string name> : Option<name, KIND_COMMAJOINED>;
121class MultiArg<string name, int numargs> : Option<name, KIND_MULTIARG> {
122  int NumArgs = numargs;
123}
124class JoinedOrSeparate<string name> : Option<name, KIND_JOINED_OR_SEPARATE>;
125class JoinedAndSeparate<string name> : Option<name, KIND_JOINED_AND_SEPARATE>;
126
127// Mix-ins for adding optional attributes.
128
129class Alias<Option alias> { Option Alias = alias; }
130class EnumName<string name> { string EnumName = name; }
131class Flags<list<OptionFlag> flags> { list<OptionFlag> Flags = flags; }
132class Group<OptionGroup group> { OptionGroup Group = group; }
133class HelpText<string text> { string HelpText = text; }
134class MetaVarName<string name> { string MetaVarName = name; }
135
136// Predefined options.
137
138// FIXME: Have generator validate that these appear in correct position (and
139// aren't duplicated).
140def INPUT : Option<"<input>", KIND_INPUT>, Flags<[DriverOption,CC1Option]>;
141def UNKNOWN : Option<"<unknown>", KIND_UNKNOWN>;
142