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 #define PLATFORM(platform, id, name, build_name, target, tapi_target, \
67 case PLATFORM_##platform: \
69 #include "llvm/BinaryFormat/MachO.def"
71 llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
74 PlatformType
getPlatformFromName(StringRef Name
) {
75 return StringSwitch
<PlatformType
>(Name
)
76 .Case("osx", PLATFORM_MACOS
)
77 #define PLATFORM(platform, id, name, build_name, target, tapi_target, \
79 .Case(#target, PLATFORM_##platform)
80 #include "llvm/BinaryFormat/MachO.def"
81 .Default(PLATFORM_UNKNOWN
);
84 std::string
getOSAndEnvironmentName(PlatformType Platform
,
85 std::string Version
) {
87 case PLATFORM_UNKNOWN
:
88 return "darwin" + Version
;
90 return "macos" + Version
;
92 return "ios" + Version
;
94 return "tvos" + Version
;
95 case PLATFORM_WATCHOS
:
96 return "watchos" + Version
;
97 case PLATFORM_BRIDGEOS
:
98 return "bridgeos" + Version
;
99 case PLATFORM_MACCATALYST
:
100 return "ios" + Version
+ "-macabi";
101 case PLATFORM_IOSSIMULATOR
:
102 return "ios" + Version
+ "-simulator";
103 case PLATFORM_TVOSSIMULATOR
:
104 return "tvos" + Version
+ "-simulator";
105 case PLATFORM_WATCHOSSIMULATOR
:
106 return "watchos" + Version
+ "-simulator";
107 case PLATFORM_DRIVERKIT
:
108 return "driverkit" + Version
;
110 return "xros" + Version
;
111 case PLATFORM_XROS_SIMULATOR
:
112 return "xros" + Version
+ "-simulator";
114 llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
117 VersionTuple
mapToSupportedOSVersion(const Triple
&Triple
) {
118 const VersionTuple MinSupportedOS
= Triple
.getMinimumSupportedOSVersion();
119 if (MinSupportedOS
> Triple
.getOSVersion())
120 return MinSupportedOS
;
121 return Triple
.getOSVersion();
124 } // end namespace MachO.
125 } // end namespace llvm.