1 //===- llvm/TextAPI/Platform.cpp - Platform ---------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Implementations of Platform Helper functions.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/TextAPI/Platform.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/TargetParser/Triple.h"
21 PlatformType
mapToPlatformType(PlatformType Platform
, bool WantSim
) {
26 return WantSim
? PLATFORM_IOSSIMULATOR
: PLATFORM_IOS
;
28 return WantSim
? PLATFORM_TVOSSIMULATOR
: PLATFORM_TVOS
;
29 case PLATFORM_WATCHOS
:
30 return WantSim
? PLATFORM_WATCHOSSIMULATOR
: PLATFORM_WATCHOS
;
34 PlatformType
mapToPlatformType(const Triple
&Target
) {
35 switch (Target
.getOS()) {
37 return PLATFORM_UNKNOWN
;
39 return PLATFORM_MACOS
;
41 if (Target
.isSimulatorEnvironment())
42 return PLATFORM_IOSSIMULATOR
;
43 if (Target
.getEnvironment() == Triple::MacABI
)
44 return PLATFORM_MACCATALYST
;
47 return Target
.isSimulatorEnvironment() ? PLATFORM_TVOSSIMULATOR
50 return Target
.isSimulatorEnvironment() ? PLATFORM_WATCHOSSIMULATOR
52 // TODO: add bridgeOS & driverKit once in llvm::Triple
56 PlatformSet
mapToPlatformSet(ArrayRef
<Triple
> Targets
) {
58 for (const auto &Target
: Targets
)
59 Result
.insert(mapToPlatformType(Target
));
63 StringRef
getPlatformName(PlatformType Platform
) {
65 case PLATFORM_UNKNOWN
:
73 case PLATFORM_WATCHOS
:
75 case PLATFORM_BRIDGEOS
:
77 case PLATFORM_MACCATALYST
:
79 case PLATFORM_IOSSIMULATOR
:
80 return "iOS Simulator";
81 case PLATFORM_TVOSSIMULATOR
:
82 return "tvOS Simulator";
83 case PLATFORM_WATCHOSSIMULATOR
:
84 return "watchOS Simulator";
85 case PLATFORM_DRIVERKIT
:
88 llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
91 PlatformType
getPlatformFromName(StringRef Name
) {
92 return StringSwitch
<PlatformType
>(Name
)
93 .Case("macos", PLATFORM_MACOS
)
94 .Case("ios", PLATFORM_IOS
)
95 .Case("tvos", PLATFORM_TVOS
)
96 .Case("watchos", PLATFORM_WATCHOS
)
97 .Case("bridgeos", PLATFORM_BRIDGEOS
)
98 .Case("ios-macabi", PLATFORM_MACCATALYST
)
99 .Case("ios-simulator", PLATFORM_IOSSIMULATOR
)
100 .Case("tvos-simulator", PLATFORM_TVOSSIMULATOR
)
101 .Case("watchos-simulator", PLATFORM_WATCHOSSIMULATOR
)
102 .Case("driverkit", PLATFORM_DRIVERKIT
)
103 .Default(PLATFORM_UNKNOWN
);
106 std::string
getOSAndEnvironmentName(PlatformType Platform
,
107 std::string Version
) {
109 case PLATFORM_UNKNOWN
:
110 return "darwin" + Version
;
112 return "macos" + Version
;
114 return "ios" + Version
;
116 return "tvos" + Version
;
117 case PLATFORM_WATCHOS
:
118 return "watchos" + Version
;
119 case PLATFORM_BRIDGEOS
:
120 return "bridgeos" + Version
;
121 case PLATFORM_MACCATALYST
:
122 return "ios" + Version
+ "-macabi";
123 case PLATFORM_IOSSIMULATOR
:
124 return "ios" + Version
+ "-simulator";
125 case PLATFORM_TVOSSIMULATOR
:
126 return "tvos" + Version
+ "-simulator";
127 case PLATFORM_WATCHOSSIMULATOR
:
128 return "watchos" + Version
+ "-simulator";
129 case PLATFORM_DRIVERKIT
:
130 return "driverkit" + Version
;
132 llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
135 VersionTuple
mapToSupportedOSVersion(const Triple
&Triple
) {
136 const VersionTuple MinSupportedOS
= Triple
.getMinimumSupportedOSVersion();
137 if (MinSupportedOS
> Triple
.getOSVersion())
138 return MinSupportedOS
;
139 return Triple
.getOSVersion();
142 } // end namespace MachO.
143 } // end namespace llvm.