18
18
#include < vector>
19
19
20
20
#if __has_include("swift/Option/Options.inc")
21
- #if __has_include("llvm/ADT/ArrayRef .h")
22
- #if __has_include("llvm/ADT/StringRef .h")
21
+ #if __has_include("llvm/Option/OptTable .h")
22
+ #if __has_include("llvm/Option/Option .h")
23
23
24
- #include " llvm/ADT/ArrayRef .h"
25
- #include " llvm/ADT/StringRef .h"
24
+ #include " llvm/Option/OptTable .h"
25
+ #include " llvm/Option/Option .h"
26
26
27
27
enum class OptionKind {
28
28
Group = 0 ,
@@ -37,12 +37,6 @@ enum class OptionKind {
37
37
MultiArg,
38
38
};
39
39
40
- #define LLVM_MAKE_OPT_ID_WITH_ID_PREFIX (ID_PREFIX, PREFIX, NAME, ID, KIND, \
41
- GROUP, ALIAS, ALIASARGS, FLAGS, \
42
- VISIBILITY, PARAM, HELPTEXT, \
43
- HELPTEXTFORVARIANTS, METAVAR, VALUES) \
44
- ID_PREFIX##ID
45
-
46
40
// . The IDs of each option
47
41
enum class OptionID {
48
42
Opt_INVALID = 0 ,
@@ -106,7 +100,7 @@ static std::string swiftify(const std::string &name) {
106
100
// / Raw option from the TableGen'd output of the Swift options.
107
101
struct RawOption {
108
102
OptionID id;
109
- const llvm::ArrayRef <llvm::StringLiteral > prefixes;
103
+ std::vector <llvm::StringRef > prefixes;
110
104
const char *spelling;
111
105
std::string idName;
112
106
OptionKind kind;
@@ -130,16 +124,65 @@ struct RawOption {
130
124
}
131
125
};
132
126
127
+ #if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 21
128
+
129
+ #define OPTTABLE_PREFIXES_TABLE_CODE
130
+ #include " swift/Option/Options.inc"
131
+ #undef OPTTABLE_PREFIXES_TABLE_CODE
132
+
133
+ #define OPTTABLE_STR_TABLE_CODE
134
+ #include " swift/Option/Options.inc"
135
+ #undef OPTTABLE_STR_TABLE_CODE
136
+
137
+ static std::vector<llvm::StringRef> getPrefixes (unsigned prefixesOffset) {
138
+ unsigned numPrefixes = OptionPrefixesTable[prefixesOffset].value ();
139
+
140
+ std::vector<llvm::StringRef> prefixes;
141
+
142
+ const unsigned firstOffsetIndex = prefixesOffset + 1 ;
143
+ for (unsigned i = firstOffsetIndex, e = i + numPrefixes; i < e; ++i) {
144
+ prefixes.push_back (OptionStrTable[OptionPrefixesTable[i]]);
145
+ }
146
+
147
+ return prefixes;
148
+ }
149
+
150
+ static const char *getPrefixedName (unsigned prefixedNameOffset) {
151
+ return OptionStrTable[prefixedNameOffset].data ();
152
+ }
153
+
154
+ #else // #if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 21
155
+
133
156
#define PREFIX (NAME, VALUE ) static constexpr llvm::StringLiteral NAME[] = VALUE;
134
157
#include " swift/Option/Options.inc"
135
158
#undef PREFIX
136
159
160
+ static std::vector<llvm::StringRef>
161
+ getPrefixes (llvm::ArrayRef<llvm::StringLiteral> prefixes) {
162
+ return std::vector<llvm::StringRef>(prefixes.begin (), prefixes.end ());
163
+ }
164
+
165
+ static const char *getPrefixedName (const char *prefixedName) {
166
+ return prefixedName;
167
+ }
168
+
169
+ #endif // #if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 21
170
+
137
171
static const RawOption rawOptions[] = {
138
- #define OPTION (PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
139
- VISIBILITY, PARAM, HELPTEXT, HELPTEXTFORVARIANTS, METAVAR, \
140
- VALUES) \
141
- { OptionID::Opt_##ID, PREFIX, NAME, swiftify (#ID), OptionKind::KIND, \
142
- OptionID::Opt_##GROUP, OptionID::Opt_##ALIAS, FLAGS, HELPTEXT, METAVAR, PARAM },
172
+ #define OPTION (PREFIXES_OFFSET, PREFIXED_NAME_OFFSET, ID, KIND, GROUP, ALIAS, \
173
+ ALIASARGS, FLAGS, VISIBILITY, PARAM, HELPTEXT, \
174
+ HELPTEXTFORVARIANTS, METAVAR, VALUES) \
175
+ {OptionID::Opt_##ID, \
176
+ getPrefixes (PREFIXES_OFFSET), \
177
+ getPrefixedName (PREFIXED_NAME_OFFSET), \
178
+ swiftify (#ID), \
179
+ OptionKind::KIND, \
180
+ OptionID::Opt_##GROUP, \
181
+ OptionID::Opt_##ALIAS, \
182
+ FLAGS, \
183
+ HELPTEXT, \
184
+ METAVAR, \
185
+ PARAM},
143
186
#include " swift/Option/Options.inc"
144
187
#undef OPTION
145
188
};
@@ -183,9 +226,13 @@ void forEachOption(std::function<void(const RawOption &)> fn) {
183
226
}
184
227
}
185
228
186
- void forEachSpelling (const llvm::ArrayRef<llvm::StringLiteral> prefixes, const std::string &spelling,
187
- std::function<void (const std::string &spelling,
188
- bool isAlternateSpelling)> fn) {
229
+ void forEachSpelling (
230
+ const RawOption &option,
231
+ std::function<void (const std::string &spelling, bool isAlternateSpelling)>
232
+ fn) {
233
+ std::string spelling (option.spelling );
234
+ auto &prefixes = option.prefixes ;
235
+
189
236
fn (spelling, /* isAlternateSpelling=*/ false );
190
237
191
238
if (prefixes.empty ())
@@ -253,9 +300,8 @@ int makeOptions_main() {
253
300
out << " extension Option {\n " ;
254
301
forEachOption ([&](const RawOption &option) {
255
302
// Look through each spelling of the option.
256
- forEachSpelling (option.prefixes , option.spelling ,
257
- [&](const std::string &spelling,
258
- bool isAlternateSpelling) {
303
+ forEachSpelling (option, [&](const std::string &spelling,
304
+ bool isAlternateSpelling) {
259
305
out << " public static let " << option.idName ;
260
306
261
307
// Add a '_' suffix if this is an alternate spelling.
@@ -372,14 +418,13 @@ int makeOptions_main() {
372
418
<< " return [\n " ;
373
419
forEachOption ([&](const RawOption &option) {
374
420
// Look through each spelling of the option.
375
- forEachSpelling (option.prefixes , option.spelling ,
376
- [&](const std::string &spelling,
377
- bool isAlternateSpelling) {
378
- out << " Option." << option.idName ;
379
- if (isAlternateSpelling)
380
- out << " _" ;
381
- out << " ,\n " ;
382
- });
421
+ forEachSpelling (
422
+ option, [&](const std::string &spelling, bool isAlternateSpelling) {
423
+ out << " Option." << option.idName ;
424
+ if (isAlternateSpelling)
425
+ out << " _" ;
426
+ out << " ,\n " ;
427
+ });
383
428
});
384
429
out << " ]\n " ;
385
430
out << " }\n " ;
@@ -424,10 +469,10 @@ int makeOptions_main() {
424
469
return 0 ;
425
470
}
426
471
#else
427
- static_assert (false , " Failed to locate/include StringRef .h" );
472
+ static_assert (false , " Failed to locate/include llvm/Option/Option .h" );
428
473
#endif
429
474
#else
430
- static_assert (false , " Failed to locate/include ArrayRef .h" );
475
+ static_assert (false , " Failed to locate/include llvm/Option/OptTable .h" );
431
476
#endif
432
477
#else
433
478
#warning "Unable to include 'swift/Option/Options.inc', `makeOptions` will not be usable"
0 commit comments