LLVM 18.0.0git
Platform.cpp
Go to the documentation of this file.
1//===- llvm/TextAPI/Platform.cpp - Platform ---------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// Implementations of Platform Helper functions.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/ArrayRef.h"
17
18namespace llvm {
19namespace MachO {
20
22 switch (Platform) {
23 default:
24 return Platform;
25 case PLATFORM_IOS:
26 return WantSim ? PLATFORM_IOSSIMULATOR : PLATFORM_IOS;
27 case PLATFORM_TVOS:
28 return WantSim ? PLATFORM_TVOSSIMULATOR : PLATFORM_TVOS;
31 }
32}
33
35 switch (Target.getOS()) {
36 default:
37 return PLATFORM_UNKNOWN;
38 case Triple::MacOSX:
39 return PLATFORM_MACOS;
40 case Triple::IOS:
41 if (Target.isSimulatorEnvironment())
43 if (Target.getEnvironment() == Triple::MacABI)
45 return PLATFORM_IOS;
46 case Triple::TvOS:
47 return Target.isSimulatorEnvironment() ? PLATFORM_TVOSSIMULATOR
49 case Triple::WatchOS:
50 return Target.isSimulatorEnvironment() ? PLATFORM_WATCHOSSIMULATOR
52 // TODO: add bridgeOS & driverKit once in llvm::Triple
53 }
54}
55
57 PlatformSet Result;
58 for (const auto &Target : Targets)
59 Result.insert(mapToPlatformType(Target));
60 return Result;
61}
62
64 switch (Platform) {
66 return "unknown";
67 case PLATFORM_MACOS:
68 return "macOS";
69 case PLATFORM_IOS:
70 return "iOS";
71 case PLATFORM_TVOS:
72 return "tvOS";
74 return "watchOS";
76 return "bridgeOS";
78 return "macCatalyst";
80 return "iOS Simulator";
82 return "tvOS Simulator";
84 return "watchOS Simulator";
86 return "DriverKit";
87 }
88 llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
89}
90
93 .Case("osx", PLATFORM_MACOS)
94 .Case("macos", PLATFORM_MACOS)
95 .Case("ios", PLATFORM_IOS)
96 .Case("tvos", PLATFORM_TVOS)
97 .Case("watchos", PLATFORM_WATCHOS)
98 .Case("bridgeos", PLATFORM_BRIDGEOS)
99 .Case("ios-macabi", PLATFORM_MACCATALYST)
100 .Case("ios-simulator", PLATFORM_IOSSIMULATOR)
101 .Case("tvos-simulator", PLATFORM_TVOSSIMULATOR)
102 .Case("watchos-simulator", PLATFORM_WATCHOSSIMULATOR)
103 .Case("driverkit", PLATFORM_DRIVERKIT)
105}
106
108 std::string Version) {
109 switch (Platform) {
110 case PLATFORM_UNKNOWN:
111 return "darwin" + Version;
112 case PLATFORM_MACOS:
113 return "macos" + Version;
114 case PLATFORM_IOS:
115 return "ios" + Version;
116 case PLATFORM_TVOS:
117 return "tvos" + Version;
118 case PLATFORM_WATCHOS:
119 return "watchos" + Version;
121 return "bridgeos" + Version;
123 return "ios" + Version + "-macabi";
125 return "ios" + Version + "-simulator";
127 return "tvos" + Version + "-simulator";
129 return "watchos" + Version + "-simulator";
131 return "driverkit" + Version;
132 }
133 llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
134}
135
137 const VersionTuple MinSupportedOS = Triple.getMinimumSupportedOSVersion();
138 if (MinSupportedOS > Triple.getOSVersion())
139 return MinSupportedOS;
140 return Triple.getOSVersion();
141}
142
143} // end namespace MachO.
144} // end namespace llvm.
std::string Name
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
VersionTuple getOSVersion() const
Parse the version number from the OS name component of the triple, if present.
Definition: Triple.cpp:1211
VersionTuple getMinimumSupportedOSVersion() const
Some platforms have different minimum supported OS versions that varies by the architecture specified...
Definition: Triple.cpp:1848
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:31
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::string getOSAndEnvironmentName(PlatformType Platform, std::string Version="")
Definition: Platform.cpp:107
PlatformType
Definition: MachO.h:499
@ PLATFORM_MACCATALYST
Definition: MachO.h:506
@ PLATFORM_DRIVERKIT
Definition: MachO.h:510
@ PLATFORM_WATCHOS
Definition: MachO.h:504
@ PLATFORM_UNKNOWN
Definition: MachO.h:500
@ PLATFORM_WATCHOSSIMULATOR
Definition: MachO.h:509
@ PLATFORM_IOS
Definition: MachO.h:502
@ PLATFORM_TVOS
Definition: MachO.h:503
@ PLATFORM_TVOSSIMULATOR
Definition: MachO.h:508
@ PLATFORM_BRIDGEOS
Definition: MachO.h:505
@ PLATFORM_MACOS
Definition: MachO.h:501
@ PLATFORM_IOSSIMULATOR
Definition: MachO.h:507
VersionTuple mapToSupportedOSVersion(const Triple &Triple)
Definition: Platform.cpp:136
PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
Definition: Platform.cpp:56
PlatformType mapToPlatformType(PlatformType Platform, bool WantSim)
Definition: Platform.cpp:21
StringRef getPlatformName(PlatformType Platform)
Definition: Platform.cpp:63
PlatformType getPlatformFromName(StringRef Name)
Definition: Platform.cpp:91
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18