@@ -100,24 +100,23 @@ getAllMovedPlatformVersions(Decl *D) {
100
100
return Results;
101
101
}
102
102
103
- static StringRef getLinkerPlatformName (uint8_t Id) {
103
+ static StringRef getLinkerPlatformName (LinkerPlatformId Id) {
104
104
switch (Id) {
105
- #define LD_PLATFORM (Name, Id ) case Id : return #Name;
105
+ #define LD_PLATFORM (Name, Id ) case LinkerPlatformId::Name : return #Name;
106
106
#include " ldPlatformKinds.def"
107
- default :
108
- llvm_unreachable (" unrecognized platform id" );
109
107
}
108
+ llvm_unreachable (" unrecognized platform id" );
110
109
}
111
110
112
- static std::optional<uint8_t > getLinkerPlatformId (StringRef Platform) {
113
- return llvm::StringSwitch<std::optional<uint8_t >>(Platform)
114
- #define LD_PLATFORM (Name, Id ) .Case(#Name, Id )
111
+ static std::optional<LinkerPlatformId > getLinkerPlatformId (StringRef Platform) {
112
+ return llvm::StringSwitch<std::optional<LinkerPlatformId >>(Platform)
113
+ #define LD_PLATFORM (Name, Id ) .Case(#Name, LinkerPlatformId::Name )
115
114
#include " ldPlatformKinds.def"
116
115
.Default (std::nullopt);
117
116
}
118
117
119
118
StringRef InstallNameStore::getInstallName (LinkerPlatformId Id) const {
120
- auto It = PlatformInstallName.find (( uint8_t ) Id);
119
+ auto It = PlatformInstallName.find (Id);
121
120
if (It == PlatformInstallName.end ())
122
121
return InstallName;
123
122
else
@@ -129,8 +128,9 @@ static std::string getScalaNodeText(Node *N) {
129
128
return cast<ScalarNode>(N)->getValue (Buffer).str ();
130
129
}
131
130
132
- static std::set<int8_t > getSequenceNodePlatformList (ASTContext &Ctx, Node *N) {
133
- std::set<int8_t > Results;
131
+ static std::set<LinkerPlatformId> getSequenceNodePlatformList (ASTContext &Ctx,
132
+ Node *N) {
133
+ std::set<LinkerPlatformId> Results;
134
134
for (auto &E: *cast<SequenceNode>(N)) {
135
135
auto Platform = getScalaNodeText (&E);
136
136
auto Id = getLinkerPlatformId (Platform);
@@ -158,7 +158,7 @@ parseEntry(ASTContext &Ctx,
158
158
auto *MN = cast<MappingNode>(&*It);
159
159
std::string ModuleName;
160
160
std::string InstallName;
161
- std::optional<std::set<int8_t >> Platforms;
161
+ std::optional<std::set<LinkerPlatformId >> Platforms;
162
162
for (auto &Pair: *MN) {
163
163
auto Key = getScalaNodeText (Pair.getKey ());
164
164
auto * Value = Pair.getValue ();
@@ -233,7 +233,12 @@ TBDGenVisitor::parsePreviousModuleInstallNameMap() {
233
233
}
234
234
235
235
static LinkerPlatformId
236
- getLinkerPlatformId (OriginallyDefinedInAttr::ActiveVersion Ver) {
236
+ getLinkerPlatformId (OriginallyDefinedInAttr::ActiveVersion Ver,
237
+ ASTContext &Ctx) {
238
+ auto target =
239
+ Ver.ForTargetVariant ? Ctx.LangOpts .TargetVariant : Ctx.LangOpts .Target ;
240
+ bool isSimulator = target ? target->isSimulatorEnvironment () : false ;
241
+
237
242
switch (Ver.Platform ) {
238
243
case swift::PlatformKind::none:
239
244
llvm_unreachable (" cannot find platform kind" );
@@ -243,16 +248,16 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) {
243
248
llvm_unreachable (" not used for this platform" );
244
249
case swift::PlatformKind::iOS:
245
250
case swift::PlatformKind::iOSApplicationExtension:
246
- return Ver.IsSimulator ? LinkerPlatformId::iOS_sim:
247
- LinkerPlatformId::iOS;
251
+ if (target && target->isMacCatalystEnvironment ())
252
+ return LinkerPlatformId::macCatalyst;
253
+ return isSimulator ? LinkerPlatformId::iOS_sim : LinkerPlatformId::iOS;
248
254
case swift::PlatformKind::tvOS:
249
255
case swift::PlatformKind::tvOSApplicationExtension:
250
- return Ver.IsSimulator ? LinkerPlatformId::tvOS_sim:
251
- LinkerPlatformId::tvOS;
256
+ return isSimulator ? LinkerPlatformId::tvOS_sim : LinkerPlatformId::tvOS;
252
257
case swift::PlatformKind::watchOS:
253
258
case swift::PlatformKind::watchOSApplicationExtension:
254
- return Ver. IsSimulator ? LinkerPlatformId::watchOS_sim:
255
- LinkerPlatformId::watchOS;
259
+ return isSimulator ? LinkerPlatformId::watchOS_sim
260
+ : LinkerPlatformId::watchOS;
256
261
case swift::PlatformKind::macOS:
257
262
case swift::PlatformKind::macOSApplicationExtension:
258
263
return LinkerPlatformId::macOS;
@@ -264,8 +269,9 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver) {
264
269
}
265
270
266
271
static StringRef
267
- getLinkerPlatformName (OriginallyDefinedInAttr::ActiveVersion Ver) {
268
- return getLinkerPlatformName ((uint8_t )getLinkerPlatformId (Ver));
272
+ getLinkerPlatformName (OriginallyDefinedInAttr::ActiveVersion Ver,
273
+ ASTContext &Ctx) {
274
+ return getLinkerPlatformName (getLinkerPlatformId (Ver, Ctx));
269
275
}
270
276
271
277
// / Find the most relevant introducing version of the decl stack we have visited
@@ -313,17 +319,17 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(
313
319
// so we don't need the linker directives.
314
320
if (*IntroVer >= Ver.Version )
315
321
continue ;
316
- auto PlatformNumber = getLinkerPlatformId (Ver);
322
+ auto PlatformNumber = getLinkerPlatformId (Ver, Ctx );
317
323
auto It = previousInstallNameMap->find (Ver.ModuleName .str ());
318
324
if (It == previousInstallNameMap->end ()) {
319
325
Ctx.Diags .diagnose (SourceLoc (), diag::cannot_find_install_name,
320
- Ver.ModuleName , getLinkerPlatformName (Ver));
326
+ Ver.ModuleName , getLinkerPlatformName (Ver, Ctx ));
321
327
continue ;
322
328
}
323
329
auto InstallName = It->second .getInstallName (PlatformNumber);
324
330
if (InstallName.empty ()) {
325
331
Ctx.Diags .diagnose (SourceLoc (), diag::cannot_find_install_name,
326
- Ver.ModuleName , getLinkerPlatformName (Ver));
332
+ Ver.ModuleName , getLinkerPlatformName (Ver, Ctx ));
327
333
continue ;
328
334
}
329
335
llvm::SmallString<64 > Buffer;
@@ -333,7 +339,7 @@ void TBDGenVisitor::addLinkerDirectiveSymbolsLdPrevious(
333
339
OS << " $ld$previous$" ;
334
340
OS << InstallName << " $" ;
335
341
OS << ComptibleVersion << " $" ;
336
- OS << std::to_string (( uint8_t ) PlatformNumber) << " $" ;
342
+ OS << std::to_string (static_cast < uint8_t >( PlatformNumber) ) << " $" ;
337
343
static auto getMinor = [](std::optional<unsigned > Minor) {
338
344
return Minor.has_value () ? *Minor : 0 ;
339
345
};
0 commit comments