1 //===- llvm/TextAPI/MachO/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/ADT/ArrayRef.h"
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/TextAPI/MachO/Platform.h"
20 PlatformKind
mapToPlatformKind(PlatformKind Platform
, bool WantSim
) {
24 case PlatformKind::iOS
:
25 return WantSim
? PlatformKind::iOSSimulator
: PlatformKind::iOS
;
26 case PlatformKind::tvOS
:
27 return WantSim
? PlatformKind::tvOSSimulator
: PlatformKind::tvOS
;
28 case PlatformKind::watchOS
:
29 return WantSim
? PlatformKind::watchOSSimulator
: PlatformKind::watchOS
;
31 llvm_unreachable("Unknown llvm.MachO.PlatformKind enum");
34 PlatformKind
mapToPlatformKind(const Triple
&Target
) {
35 switch (Target
.getOS()) {
37 return PlatformKind::unknown
;
39 return PlatformKind::macOS
;
41 if (Target
.isSimulatorEnvironment())
42 return PlatformKind::iOSSimulator
;
43 if (Target
.getEnvironment() == Triple::MacABI
)
44 return PlatformKind::macCatalyst
;
45 return PlatformKind::iOS
;
47 return Target
.isSimulatorEnvironment() ? PlatformKind::tvOSSimulator
50 return Target
.isSimulatorEnvironment() ? PlatformKind::watchOSSimulator
51 : PlatformKind::watchOS
;
52 // TODO: add bridgeOS once in llvm::Triple
54 llvm_unreachable("Unknown Target Triple");
57 PlatformSet
mapToPlatformSet(ArrayRef
<Triple
> Targets
) {
59 for (const auto &Target
: Targets
)
60 Result
.insert(mapToPlatformKind(Target
));
64 StringRef
getPlatformName(PlatformKind Platform
) {
66 case PlatformKind::unknown
:
68 case PlatformKind::macOS
:
70 case PlatformKind::iOS
:
72 case PlatformKind::tvOS
:
74 case PlatformKind::watchOS
:
76 case PlatformKind::bridgeOS
:
78 case PlatformKind::macCatalyst
:
80 case PlatformKind::iOSSimulator
:
81 return "iOS Simulator";
82 case PlatformKind::tvOSSimulator
:
83 return "tvOS Simulator";
84 case PlatformKind::watchOSSimulator
:
85 return "watchOS Simulator";
87 llvm_unreachable("Unknown llvm.MachO.PlatformKind enum");
90 } // end namespace MachO.
91 } // end namespace llvm.