18
18
#include < vector>
19
19
20
20
#if __has_include("swift/Option/Options.inc")
21
+ #if __has_include("swift/Option/Options.h")
21
22
#if __has_include("llvm/Option/OptTable.h")
22
23
#if __has_include("llvm/Option/Option.h")
23
24
25
+ #include " swift/Option/Options.h"
24
26
#include " llvm/Option/OptTable.h"
25
27
#include " llvm/Option/Option.h"
26
28
27
- // . The IDs of each option
28
- enum class OptionID {
29
- Opt_INVALID = 0 ,
30
- #define OPTION (...) LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(Opt_, __VA_ARGS__),
31
- #include " swift/Option/Options.inc"
32
- #undef OPTION
33
- };
34
-
35
- enum SwiftFlags {
36
- HelpHidden = (1 << 0 ),
37
-
38
- FrontendOption = (1 << 4 ),
39
- NoDriverOption = (1 << 5 ),
40
- NoInteractiveOption = (1 << 6 ),
41
- NoBatchOption = (1 << 7 ),
42
- DoesNotAffectIncrementalBuild = (1 << 8 ),
43
- AutolinkExtractOption = (1 << 9 ),
44
- ModuleWrapOption = (1 << 10 ),
45
- SwiftSynthesizeInterfaceOption = (1 << 11 ),
46
- ArgumentIsPath = (1 << 12 ),
47
- ModuleInterfaceOption = (1 << 13 ),
48
- SupplementaryOutput = (1 << 14 ),
49
- SwiftAPIExtractOption = (1 << 15 ),
50
- SwiftSymbolGraphExtractOption = (1 << 16 ),
51
- SwiftAPIDigesterOption = (1 << 17 ),
52
- NewDriverOnlyOption = (1 << 18 ),
53
- ModuleInterfaceOptionIgnorable = (1 << 19 ),
54
- ModuleInterfaceOptionIgnorablePrivate = (1 << 20 ),
55
- ArgumentIsFileList = (1 << 21 ),
56
- CacheInvariant = (1 << 22 ),
57
- };
58
-
59
29
static std::set<std::string> swiftKeywords = { " internal" , " static" };
60
30
61
31
// / Turns a snake_case_option_name into a camelCaseOptionName, and escapes
@@ -86,27 +56,23 @@ static std::string swiftify(const std::string &name) {
86
56
87
57
// / Raw option from the TableGen'd output of the Swift options.
88
58
struct RawOption {
89
- OptionID id;
59
+ swift::options::ID id;
90
60
std::vector<llvm::StringRef> prefixes;
91
61
const char *spelling;
92
62
std::string idName;
93
63
llvm::opt::Option::OptionClass kind;
94
- OptionID group;
95
- OptionID alias;
64
+ swift::options::ID group;
65
+ swift::options::ID alias;
96
66
unsigned flags;
97
67
const char *helpText;
98
68
const char *metaVar;
99
69
unsigned numArgs;
100
70
101
71
bool isGroup () const { return kind == llvm::opt::Option::GroupClass; }
102
72
103
- bool isAlias () const {
104
- return alias != OptionID::Opt_INVALID;
105
- }
73
+ bool isAlias () const { return alias != swift::options::OPT_INVALID; }
106
74
107
- bool isHidden () const {
108
- return flags & HelpHidden;
109
- }
75
+ bool isHidden () const { return flags & llvm::opt::HelpHidden; }
110
76
};
111
77
112
78
#if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 21
@@ -153,24 +119,28 @@ static const char *getPrefixedName(const char *prefixedName) {
153
119
154
120
#endif // #if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 21
155
121
122
+ namespace {
123
+ using namespace swift ::options;
124
+ using namespace llvm ::opt;
156
125
static const RawOption rawOptions[] = {
157
126
#define OPTION (PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
158
127
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
159
128
HELPTEXTFORVARIANTS, METAVAR, VALUES) \
160
- {OptionID::Opt_ ##ID, \
129
+ {OPT_ ##ID, \
161
130
getPrefixes (PREFIXES_OFFSET), \
162
131
getPrefixedName (PREFIXED_NAME_OFFSET), \
163
132
swiftify (#ID), \
164
133
llvm::opt::Option::KIND##Class, \
165
- OptionID::Opt_ ##GROUP, \
166
- OptionID::Opt_ ##ALIAS, \
134
+ OPT_ ##GROUP, \
135
+ OPT_ ##ALIAS, \
167
136
FLAGS, \
168
137
HELPTEXT, \
169
138
METAVAR, \
170
139
PARAM},
171
140
#include " swift/Option/Options.inc"
172
141
#undef OPTION
173
142
};
143
+ } // end anonymous namespace
174
144
175
145
struct Group {
176
146
std::string id;
@@ -179,8 +149,8 @@ struct Group {
179
149
};
180
150
181
151
static std::vector<Group> groups;
182
- static std::map<OptionID , unsigned > groupIndexByID;
183
- static std::map<OptionID , unsigned > optionIndexByID;
152
+ static std::map<swift::options::ID , unsigned > groupIndexByID;
153
+ static std::map<swift::options::ID , unsigned > optionIndexByID;
184
154
185
155
static std::string stringOrNil (const char *text) {
186
156
if (!text)
@@ -359,29 +329,33 @@ int makeOptions_main() {
359
329
out << name;
360
330
};
361
331
362
- auto emitFlagIf = [&](SwiftFlags flag, const char *name) {
363
- if ((option.flags & flag) == 0 ) { return ; }
332
+ auto emitFlagIf = [&](unsigned flag, const char *name) {
333
+ if ((option.flags & flag) == 0 ) {
334
+ return ;
335
+ }
364
336
emitFlag (name);
365
337
};
366
338
367
339
out << " , attributes: [" ;
368
- emitFlagIf (HelpHidden, " .helpHidden" );
369
- emitFlagIf (FrontendOption, " .frontend" );
370
- emitFlagIf (NoDriverOption, " .noDriver" );
371
- emitFlagIf (NoInteractiveOption, " .noInteractive" );
372
- emitFlagIf (NoBatchOption, " .noBatch" );
373
- emitFlagIf (DoesNotAffectIncrementalBuild, " .doesNotAffectIncrementalBuild" );
374
- emitFlagIf (AutolinkExtractOption, " .autolinkExtract" );
375
- emitFlagIf (ModuleWrapOption, " .moduleWrap" );
376
- emitFlagIf (SwiftSynthesizeInterfaceOption, " .synthesizeInterface" );
340
+ emitFlagIf (llvm::opt::HelpHidden, " .helpHidden" );
341
+ emitFlagIf (swift::options::FrontendOption, " .frontend" );
342
+ emitFlagIf (swift::options::NoDriverOption, " .noDriver" );
343
+ emitFlagIf (swift::options::NoInteractiveOption, " .noInteractive" );
344
+ emitFlagIf (swift::options::NoBatchOption, " .noBatch" );
345
+ emitFlagIf (swift::options::DoesNotAffectIncrementalBuild,
346
+ " .doesNotAffectIncrementalBuild" );
347
+ emitFlagIf (swift::options::AutolinkExtractOption, " .autolinkExtract" );
348
+ emitFlagIf (swift::options::ModuleWrapOption, " .moduleWrap" );
349
+ emitFlagIf (swift::options::SwiftSynthesizeInterfaceOption,
350
+ " .synthesizeInterface" );
377
351
if (option.kind == llvm::opt::Option::InputClass)
378
352
emitFlag (" .argumentIsPath" );
379
353
else
380
- emitFlagIf (ArgumentIsPath, " .argumentIsPath" );
381
- emitFlagIf (ModuleInterfaceOption, " .moduleInterface" );
382
- emitFlagIf (SupplementaryOutput, " .supplementaryOutput" );
383
- emitFlagIf (ArgumentIsFileList, " .argumentIsFileList" );
384
- emitFlagIf (CacheInvariant, " .cacheInvariant" );
354
+ emitFlagIf (swift::options:: ArgumentIsPath, " .argumentIsPath" );
355
+ emitFlagIf (swift::options:: ModuleInterfaceOption, " .moduleInterface" );
356
+ emitFlagIf (swift::options:: SupplementaryOutput, " .supplementaryOutput" );
357
+ emitFlagIf (swift::options:: ArgumentIsFileList, " .argumentIsFileList" );
358
+ emitFlagIf (swift::options:: CacheInvariant, " .cacheInvariant" );
385
359
out << " ]" ;
386
360
}
387
361
@@ -391,7 +365,7 @@ int makeOptions_main() {
391
365
if (option.helpText ) {
392
366
out << " , helpText: " << stringOrNilLeftTrimmed (option.helpText );
393
367
}
394
- if (option.group != OptionID::Opt_INVALID ) {
368
+ if (option.group != swift::options::OPT_INVALID ) {
395
369
out << " , group: ." << groups[groupIndexByID[option.group ]].id ;
396
370
}
397
371
if (option.kind == llvm::opt::Option::MultiArgClass) {
@@ -465,6 +439,9 @@ static_assert(false, "Failed to locate/include llvm/Option/Option.h");
465
439
static_assert (false , " Failed to locate/include llvm/Option/OptTable.h" );
466
440
#endif
467
441
#else
442
+ static_assert (false , " Failed to locate/include swift/Option/Options.h" );
443
+ #endif
444
+ #else
468
445
#warning "Unable to include 'swift/Option/Options.inc', `makeOptions` will not be usable"
469
446
int makeOptions_main () {return 0 ;}
470
447
#endif
0 commit comments