Skip to content

Commit 6b50839

Browse files
committed
makeOptions: Use swift::options::ID and swift::options::SwiftFlags
1 parent 2f8ee69 commit 6b50839

File tree

1 file changed

+40
-63
lines changed

1 file changed

+40
-63
lines changed

Sources/makeOptions/makeOptions.cpp

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,14 @@
1818
#include <vector>
1919

2020
#if __has_include("swift/Option/Options.inc")
21+
#if __has_include("swift/Option/Options.h")
2122
#if __has_include("llvm/Option/OptTable.h")
2223
#if __has_include("llvm/Option/Option.h")
2324

25+
#include "swift/Option/Options.h"
2426
#include "llvm/Option/OptTable.h"
2527
#include "llvm/Option/Option.h"
2628

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-
5929
static std::set<std::string> swiftKeywords = { "internal", "static" };
6030

6131
/// Turns a snake_case_option_name into a camelCaseOptionName, and escapes
@@ -86,27 +56,23 @@ static std::string swiftify(const std::string &name) {
8656

8757
/// Raw option from the TableGen'd output of the Swift options.
8858
struct RawOption {
89-
OptionID id;
59+
swift::options::ID id;
9060
std::vector<llvm::StringRef> prefixes;
9161
const char *spelling;
9262
std::string idName;
9363
llvm::opt::Option::OptionClass kind;
94-
OptionID group;
95-
OptionID alias;
64+
swift::options::ID group;
65+
swift::options::ID alias;
9666
unsigned flags;
9767
const char *helpText;
9868
const char *metaVar;
9969
unsigned numArgs;
10070

10171
bool isGroup() const { return kind == llvm::opt::Option::GroupClass; }
10272

103-
bool isAlias() const {
104-
return alias != OptionID::Opt_INVALID;
105-
}
73+
bool isAlias() const { return alias != swift::options::OPT_INVALID; }
10674

107-
bool isHidden() const {
108-
return flags & HelpHidden;
109-
}
75+
bool isHidden() const { return flags & llvm::opt::HelpHidden; }
11076
};
11177

11278
#if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 21
@@ -153,24 +119,28 @@ static const char *getPrefixedName(const char *prefixedName) {
153119

154120
#endif // #if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 21
155121

122+
namespace {
123+
using namespace swift::options;
124+
using namespace llvm::opt;
156125
static const RawOption rawOptions[] = {
157126
#define OPTION(PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
158127
ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
159128
HELPTEXTFORVARIANTS, METAVAR, VALUES) \
160-
{OptionID::Opt_##ID, \
129+
{OPT_##ID, \
161130
getPrefixes(PREFIXES_OFFSET), \
162131
getPrefixedName(PREFIXED_NAME_OFFSET), \
163132
swiftify(#ID), \
164133
llvm::opt::Option::KIND##Class, \
165-
OptionID::Opt_##GROUP, \
166-
OptionID::Opt_##ALIAS, \
134+
OPT_##GROUP, \
135+
OPT_##ALIAS, \
167136
FLAGS, \
168137
HELPTEXT, \
169138
METAVAR, \
170139
PARAM},
171140
#include "swift/Option/Options.inc"
172141
#undef OPTION
173142
};
143+
} // end anonymous namespace
174144

175145
struct Group {
176146
std::string id;
@@ -179,8 +149,8 @@ struct Group {
179149
};
180150

181151
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;
184154

185155
static std::string stringOrNil(const char *text) {
186156
if (!text)
@@ -359,29 +329,33 @@ int makeOptions_main() {
359329
out << name;
360330
};
361331

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+
}
364336
emitFlag(name);
365337
};
366338

367339
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");
377351
if (option.kind == llvm::opt::Option::InputClass)
378352
emitFlag(".argumentIsPath");
379353
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");
385359
out << "]";
386360
}
387361

@@ -391,7 +365,7 @@ int makeOptions_main() {
391365
if (option.helpText) {
392366
out << ", helpText: " << stringOrNilLeftTrimmed(option.helpText);
393367
}
394-
if (option.group != OptionID::Opt_INVALID) {
368+
if (option.group != swift::options::OPT_INVALID) {
395369
out << ", group: ." << groups[groupIndexByID[option.group]].id;
396370
}
397371
if (option.kind == llvm::opt::Option::MultiArgClass) {
@@ -465,6 +439,9 @@ static_assert(false, "Failed to locate/include llvm/Option/Option.h");
465439
static_assert(false, "Failed to locate/include llvm/Option/OptTable.h");
466440
#endif
467441
#else
442+
static_assert(false, "Failed to locate/include swift/Option/Options.h");
443+
#endif
444+
#else
468445
#warning "Unable to include 'swift/Option/Options.inc', `makeOptions` will not be usable"
469446
int makeOptions_main() {return 0;}
470447
#endif

0 commit comments

Comments
 (0)