Skip to content

Commit 376a516

Browse files
committed
Adjust 'makeOptions' to new TableGen format of Swift's 'Options.inc'
1 parent ae287d9 commit 376a516

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

Package.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ let package = Package(
129129
/// The `makeOptions` utility (for importing option definitions).
130130
.executableTarget(
131131
name: "makeOptions",
132-
dependencies: []),
132+
dependencies: [],
133+
// Do not enforce checks for LLVM's ABI-breaking build settings.
134+
// makeOptions runtime uses some header-only code from LLVM's ADT classes,
135+
// but we do not want to link libSupport into the executable.
136+
cxxSettings: [.unsafeFlags(["-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1"])]),
133137
],
134-
cxxLanguageStandard: .cxx14
138+
cxxLanguageStandard: .cxx17
135139
)
136140

137141
if ProcessInfo.processInfo.environment["SWIFT_DRIVER_LLBUILD_FWK"] == nil {

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ $ apt-get install libncurses-dev
156156
be found, e.g.:
157157

158158
```
159-
$ swift build -Xcc -I/path/to/build/Ninja-ReleaseAssert/swift-.../include --product makeOptions
159+
$ swift build -Xcc -Xcc -I/path/to/build/Ninja-Release/swift-.../include -Xcc -I/path/to/build/Ninja-Release/llvm-.../include -Xcc -I/path/to/source/llvm-project/llvm/include --product makeOptions
160160
```
161161

162162
Then, run `makeOptions` and redirect the output to overwrite `Options.swift`:

Sources/SwiftOptions/Options.swift

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ extension Option {
6565
public static let cacheDisableReplay: Option = Option("-cache-disable-replay", .flag, attributes: [.frontend, .cacheInvariant], helpText: "Skip loading the compilation result from cache")
6666
public static let cacheReplayPrefixMap: Option = Option("-cache-replay-prefix-map", .separate, attributes: [.frontend, .noDriver, .cacheInvariant], metaVar: "<prefix=replacement>", helpText: "Remap paths when replaying outputs from cache")
6767
public static let candidateModuleFile: Option = Option("-candidate-module-file", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<path>", helpText: "Specify Swift module may be ready to use for an interface")
68+
public static let casBackendMode: Option = Option("-cas-backend-mode=", .joined, attributes: [.frontend, .noDriver], metaVar: "native|casid|verify", helpText: "CASBackendMode for output kind")
69+
public static let casBackend: Option = Option("-cas-backend", .flag, attributes: [.frontend, .noDriver], helpText: "Enable using CASBackend for object file output")
70+
public static let casEmitCasidFile: Option = Option("-cas-emit-casid-file", .flag, attributes: [.frontend, .noDriver], helpText: "Emit .casid file next to object file when CAS Backend is enabled")
6871
public static let casFs: Option = Option("-cas-fs", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<cas-id>", helpText: "Root CASID for CAS FileSystem")
6972
public static let casPath: Option = Option("-cas-path", .separate, attributes: [.frontend, .cacheInvariant], metaVar: "<path>", helpText: "Path to CAS")
7073
public static let casPluginOption: Option = Option("-cas-plugin-option", .separate, attributes: [.frontend], metaVar: "<name>=<option>", helpText: "Option pass to CAS Plugin")
@@ -883,6 +886,9 @@ extension Option {
883886
Option.cacheDisableReplay,
884887
Option.cacheReplayPrefixMap,
885888
Option.candidateModuleFile,
889+
Option.casBackendMode,
890+
Option.casBackend,
891+
Option.casEmitCasidFile,
886892
Option.casFs,
887893
Option.casPath,
888894
Option.casPluginOption,

Sources/makeOptions/makeOptions.cpp

+30-22
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
#include <string>
1818
#include <vector>
1919

20+
#if __has_include("swift/Option/Options.inc")
21+
#if __has_include("llvm/ADT/ArrayRef.h")
22+
#if __has_include("llvm/ADT/StringRef.h")
23+
24+
#include "llvm/ADT/ArrayRef.h"
25+
#include "llvm/ADT/StringRef.h"
26+
2027
enum class OptionKind {
2128
Group = 0,
2229
Input,
@@ -38,12 +45,7 @@ enum class OptionKind {
3845
enum class OptionID {
3946
Opt_INVALID = 0,
4047
#define OPTION(...) LLVM_MAKE_OPT_ID_WITH_ID_PREFIX(Opt_, __VA_ARGS__),
41-
#if __has_include("swift/Option/Options.inc")
4248
#include "swift/Option/Options.inc"
43-
#else
44-
#warning "Unable to include 'swift/Option/Options.inc', `makeOptions` will not be usable"
45-
#endif
46-
4749
#undef OPTION
4850
};
4951

@@ -102,7 +104,7 @@ static std::string swiftify(const std::string &name) {
102104
/// Raw option from the TableGen'd output of the Swift options.
103105
struct RawOption {
104106
OptionID id;
105-
const char * const *prefixes;
107+
const llvm::ArrayRef<llvm::StringLiteral> prefixes;
106108
const char *spelling;
107109
std::string idName;
108110
OptionKind kind;
@@ -125,20 +127,16 @@ struct RawOption {
125127
}
126128
};
127129

128-
#define PREFIX(NAME, VALUE) static const char *const NAME[] = VALUE;
129-
#if __has_include("swift/Option/Options.inc")
130+
#define PREFIX(NAME, VALUE) static constexpr llvm::StringLiteral NAME[] = VALUE;
130131
#include "swift/Option/Options.inc"
131-
#endif
132132
#undef PREFIX
133133

134134
static const RawOption rawOptions[] = {
135135
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
136136
HELPTEXT, METAVAR, VALUES) \
137-
{ OptionID::Opt_##ID, PREFIX, NAME, swiftify(#ID), OptionKind::KIND, \
138-
OptionID::Opt_##GROUP, OptionID::Opt_##ALIAS, FLAGS, HELPTEXT, METAVAR },
139-
#if __has_include("swift/Option/Options.inc")
137+
{ OptionID::Opt_##ID, PREFIX, NAME, swiftify(#ID), OptionKind::KIND, \
138+
OptionID::Opt_##GROUP, OptionID::Opt_##ALIAS, FLAGS, HELPTEXT, METAVAR },
140139
#include "swift/Option/Options.inc"
141-
#endif
142140
#undef OPTION
143141
};
144142

@@ -181,20 +179,20 @@ void forEachOption(std::function<void(const RawOption &)> fn) {
181179
}
182180
}
183181

184-
void forEachSpelling(const char * const *prefixes, const std::string &spelling,
182+
void forEachSpelling(const llvm::ArrayRef<llvm::StringLiteral> prefixes, const std::string &spelling,
185183
std::function<void(const std::string &spelling,
186184
bool isAlternateSpelling)> fn) {
187-
if (!prefixes || !*prefixes) {
188-
fn(spelling, /*isAlternateSpelling=*/false);
189-
return;
190-
}
191-
192185
fn(spelling, /*isAlternateSpelling=*/false);
193186

194-
std::string defaultPrefix = std::string(*prefixes++);
195-
while (*prefixes) {
187+
if (prefixes.empty())
188+
return;
189+
190+
std::string defaultPrefix = std::string(*prefixes.begin());
191+
for (auto it = prefixes.begin() + 1, end = prefixes.end(); it != end; it++) {
192+
if (it->empty())
193+
continue;
196194
std::string altSpelling =
197-
std::string(*prefixes++) + spelling.substr(defaultPrefix.size());
195+
std::string(*it) + spelling.substr(defaultPrefix.size());
198196
fn(altSpelling, /*isAlternateSpelling=*/true);
199197
}
200198
}
@@ -414,3 +412,13 @@ int makeOptions_main() {
414412

415413
return 0;
416414
}
415+
#else
416+
static_assert(false, "Failed to locate/include StringRef.h");
417+
#endif
418+
#else
419+
static_assert(false, "Failed to locate/include ArrayRef.h");
420+
#endif
421+
#else
422+
#warning "Unable to include 'swift/Option/Options.inc', `makeOptions` will not be usable"
423+
int makeOptions_main() {return 0;}
424+
#endif

0 commit comments

Comments
 (0)