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;
29 case PLATFORM_WATCHOS:
30 return WantSim ? PLATFORM_WATCHOSSIMULATOR : PLATFORM_WATCHOS;
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())
42 return PLATFORM_IOSSIMULATOR;
43 if (Target.getEnvironment() == Triple::MacABI)
44 return PLATFORM_MACCATALYST;
45 return PLATFORM_IOS;
46 case Triple::TvOS:
47 return Target.isSimulatorEnvironment() ? PLATFORM_TVOSSIMULATOR
48 : PLATFORM_TVOS;
49 case Triple::WatchOS:
50 return Target.isSimulatorEnvironment() ? PLATFORM_WATCHOSSIMULATOR
51 : PLATFORM_WATCHOS;
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) {
65#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
66 marketing) \
67 case PLATFORM_##platform: \
68 return #marketing;
69#include "llvm/BinaryFormat/MachO.def"
70 }
71 llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
72}
73
76 .Case("osx", PLATFORM_MACOS)
77#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
78 marketing) \
79 .Case(#target, PLATFORM_##platform)
80#include "llvm/BinaryFormat/MachO.def"
81 .Default(PLATFORM_UNKNOWN);
82}
83
85 std::string Version) {
86 switch (Platform) {
87 case PLATFORM_UNKNOWN:
88 return "darwin" + Version;
89 case PLATFORM_MACOS:
90 return "macos" + Version;
91 case PLATFORM_IOS:
92 return "ios" + Version;
93 case PLATFORM_TVOS:
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;
109 }
110 llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
111}
112
114 const VersionTuple MinSupportedOS = Triple.getMinimumSupportedOSVersion();
115 if (MinSupportedOS > Triple.getOSVersion())
116 return MinSupportedOS;
117 return Triple.getOSVersion();
118}
119
120} // end namespace MachO.
121} // 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:1215
VersionTuple getMinimumSupportedOSVersion() const
Some platforms have different minimum supported OS versions that varies by the architecture specified...
Definition: Triple.cpp:1852
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
#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:84
PlatformType
Definition: MachO.h:500
VersionTuple mapToSupportedOSVersion(const Triple &Triple)
Definition: Platform.cpp:113
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:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18