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/ADT/Triple.h"
21 PlatformKind
mapToPlatformKind(PlatformKind Platform
, bool WantSim
) {
25 case PlatformKind::iOS
:
26 return WantSim
? PlatformKind::iOSSimulator
: PlatformKind::iOS
;
27 case PlatformKind::tvOS
:
28 return WantSim
? PlatformKind::tvOSSimulator
: PlatformKind::tvOS
;
29 case PlatformKind::watchOS
:
30 return WantSim
? PlatformKind::watchOSSimulator
: PlatformKind::watchOS
;
32 llvm_unreachable("Unknown llvm::MachO::PlatformKind enum");
35 PlatformKind
mapToPlatformKind(const Triple
&Target
) {
36 switch (Target
.getOS()) {
38 return PlatformKind::unknown
;
40 return PlatformKind::macOS
;
42 if (Target
.isSimulatorEnvironment())
43 return PlatformKind::iOSSimulator
;
44 if (Target
.getEnvironment() == Triple::MacABI
)
45 return PlatformKind::macCatalyst
;
46 return PlatformKind::iOS
;
48 return Target
.isSimulatorEnvironment() ? PlatformKind::tvOSSimulator
51 return Target
.isSimulatorEnvironment() ? PlatformKind::watchOSSimulator
52 : PlatformKind::watchOS
;
53 // TODO: add bridgeOS & driverKit once in llvm::Triple
55 llvm_unreachable("Unknown Target Triple");
58 PlatformSet
mapToPlatformSet(ArrayRef
<Triple
> Targets
) {
60 for (const auto &Target
: Targets
)
61 Result
.insert(mapToPlatformKind(Target
));
65 StringRef
getPlatformName(PlatformKind Platform
) {
67 case PlatformKind::unknown
:
69 case PlatformKind::macOS
:
71 case PlatformKind::iOS
:
73 case PlatformKind::tvOS
:
75 case PlatformKind::watchOS
:
77 case PlatformKind::bridgeOS
:
79 case PlatformKind::macCatalyst
:
81 case PlatformKind::iOSSimulator
:
82 return "iOS Simulator";
83 case PlatformKind::tvOSSimulator
:
84 return "tvOS Simulator";
85 case PlatformKind::watchOSSimulator
:
86 return "watchOS Simulator";
87 case PlatformKind::driverKit
:
90 llvm_unreachable("Unknown llvm::MachO::PlatformKind enum");
93 PlatformKind
getPlatformFromName(StringRef Name
) {
94 return StringSwitch
<PlatformKind
>(Name
)
95 .Case("macos", PlatformKind::macOS
)
96 .Case("ios", PlatformKind::iOS
)
97 .Case("tvos", PlatformKind::tvOS
)
98 .Case("watchos", PlatformKind::watchOS
)
99 .Case("bridgeos", PlatformKind::macOS
)
100 .Case("ios-macabi", PlatformKind::macCatalyst
)
101 .Case("ios-simulator", PlatformKind::iOSSimulator
)
102 .Case("tvos-simulator", PlatformKind::tvOSSimulator
)
103 .Case("watchos-simulator", PlatformKind::watchOSSimulator
)
104 .Case("driverkit", PlatformKind::driverKit
)
105 .Default(PlatformKind::unknown
);
108 std::string
getOSAndEnvironmentName(PlatformKind Platform
,
109 std::string Version
) {
111 case PlatformKind::unknown
:
112 return "darwin" + Version
;
113 case PlatformKind::macOS
:
114 return "macos" + Version
;
115 case PlatformKind::iOS
:
116 return "ios" + Version
;
117 case PlatformKind::tvOS
:
118 return "tvos" + Version
;
119 case PlatformKind::watchOS
:
120 return "watchos" + Version
;
121 case PlatformKind::bridgeOS
:
122 return "bridgeos" + Version
;
123 case PlatformKind::macCatalyst
:
124 return "ios" + Version
+ "-macabi";
125 case PlatformKind::iOSSimulator
:
126 return "ios" + Version
+ "-simulator";
127 case PlatformKind::tvOSSimulator
:
128 return "tvos" + Version
+ "-simulator";
129 case PlatformKind::watchOSSimulator
:
130 return "watchos" + Version
+ "-simulator";
131 case PlatformKind::driverKit
:
132 return "driverkit" + Version
;
134 llvm_unreachable("Unknown llvm::MachO::PlatformKind enum");
137 } // end namespace MachO.
138 } // end namespace llvm.