-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathPlatform.cpp
121 lines (111 loc) · 3.95 KB
/
Platform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//===- llvm/TextAPI/Platform.cpp - Platform ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Implementations of Platform Helper functions.
//
//===----------------------------------------------------------------------===//
#include "llvm/TextAPI/Platform.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/TargetParser/Triple.h"
namespace llvm {
namespace MachO {
PlatformType mapToPlatformType(PlatformType Platform, bool WantSim) {
switch (Platform) {
default:
return Platform;
case PLATFORM_IOS:
return WantSim ? PLATFORM_IOSSIMULATOR : PLATFORM_IOS;
case PLATFORM_TVOS:
return WantSim ? PLATFORM_TVOSSIMULATOR : PLATFORM_TVOS;
case PLATFORM_WATCHOS:
return WantSim ? PLATFORM_WATCHOSSIMULATOR : PLATFORM_WATCHOS;
}
}
PlatformType mapToPlatformType(const Triple &Target) {
switch (Target.getOS()) {
default:
return PLATFORM_UNKNOWN;
case Triple::MacOSX:
return PLATFORM_MACOS;
case Triple::IOS:
if (Target.isSimulatorEnvironment())
return PLATFORM_IOSSIMULATOR;
if (Target.getEnvironment() == Triple::MacABI)
return PLATFORM_MACCATALYST;
return PLATFORM_IOS;
case Triple::TvOS:
return Target.isSimulatorEnvironment() ? PLATFORM_TVOSSIMULATOR
: PLATFORM_TVOS;
case Triple::WatchOS:
return Target.isSimulatorEnvironment() ? PLATFORM_WATCHOSSIMULATOR
: PLATFORM_WATCHOS;
// TODO: add bridgeOS & driverKit once in llvm::Triple
}
}
PlatformSet mapToPlatformSet(ArrayRef<Triple> Targets) {
PlatformSet Result;
for (const auto &Target : Targets)
Result.insert(mapToPlatformType(Target));
return Result;
}
StringRef getPlatformName(PlatformType Platform) {
switch (Platform) {
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
case PLATFORM_##platform: \
return #marketing;
#include "llvm/BinaryFormat/MachO.def"
}
llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
}
PlatformType getPlatformFromName(StringRef Name) {
return StringSwitch<PlatformType>(Name)
.Case("osx", PLATFORM_MACOS)
#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
marketing) \
.Case(#target, PLATFORM_##platform)
#include "llvm/BinaryFormat/MachO.def"
.Default(PLATFORM_UNKNOWN);
}
std::string getOSAndEnvironmentName(PlatformType Platform,
std::string Version) {
switch (Platform) {
case PLATFORM_UNKNOWN:
return "darwin" + Version;
case PLATFORM_MACOS:
return "macos" + Version;
case PLATFORM_IOS:
return "ios" + Version;
case PLATFORM_TVOS:
return "tvos" + Version;
case PLATFORM_WATCHOS:
return "watchos" + Version;
case PLATFORM_BRIDGEOS:
return "bridgeos" + Version;
case PLATFORM_MACCATALYST:
return "ios" + Version + "-macabi";
case PLATFORM_IOSSIMULATOR:
return "ios" + Version + "-simulator";
case PLATFORM_TVOSSIMULATOR:
return "tvos" + Version + "-simulator";
case PLATFORM_WATCHOSSIMULATOR:
return "watchos" + Version + "-simulator";
case PLATFORM_DRIVERKIT:
return "driverkit" + Version;
}
llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
}
VersionTuple mapToSupportedOSVersion(const Triple &Triple) {
const VersionTuple MinSupportedOS = Triple.getMinimumSupportedOSVersion();
if (MinSupportedOS > Triple.getOSVersion())
return MinSupportedOS;
return Triple.getOSVersion();
}
} // end namespace MachO.
} // end namespace llvm.