LLVM  14.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 
13 #include "llvm/TextAPI/Platform.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/ADT/Triple.h"
17 
18 namespace llvm {
19 namespace MachO {
20 
21 PlatformKind mapToPlatformKind(PlatformKind Platform, bool WantSim) {
22  switch (Platform) {
23  default:
24  return Platform;
25  case PlatformKind::iOS:
27  case PlatformKind::tvOS:
31  }
32  llvm_unreachable("Unknown llvm::MachO::PlatformKind enum");
33 }
34 
36  switch (Target.getOS()) {
37  default:
38  return PlatformKind::unknown;
39  case Triple::MacOSX:
40  return PlatformKind::macOS;
41  case Triple::IOS:
42  if (Target.isSimulatorEnvironment())
44  if (Target.getEnvironment() == Triple::MacABI)
46  return PlatformKind::iOS;
47  case Triple::TvOS:
48  return Target.isSimulatorEnvironment() ? PlatformKind::tvOSSimulator
50  case Triple::WatchOS:
51  return Target.isSimulatorEnvironment() ? PlatformKind::watchOSSimulator
53  // TODO: add bridgeOS & driverKit once in llvm::Triple
54  }
55  llvm_unreachable("Unknown Target Triple");
56 }
57 
59  PlatformSet Result;
60  for (const auto &Target : Targets)
61  Result.insert(mapToPlatformKind(Target));
62  return Result;
63 }
64 
66  switch (Platform) {
68  return "unknown";
70  return "macOS";
71  case PlatformKind::iOS:
72  return "iOS";
73  case PlatformKind::tvOS:
74  return "tvOS";
76  return "watchOS";
78  return "bridgeOS";
80  return "macCatalyst";
82  return "iOS Simulator";
84  return "tvOS Simulator";
86  return "watchOS Simulator";
88  return "DriverKit";
89  }
90  llvm_unreachable("Unknown llvm::MachO::PlatformKind enum");
91 }
92 
95  .Case("macos", PlatformKind::macOS)
96  .Case("ios", PlatformKind::iOS)
97  .Case("tvos", PlatformKind::tvOS)
98  .Case("watchos", PlatformKind::watchOS)
99  .Case("bridgeos", PlatformKind::macOS)
100  .Case("ios-macabi", PlatformKind::macCatalyst)
101  .Case("ios-simulator", PlatformKind::iOSSimulator)
102  .Case("tvos-simulator", PlatformKind::tvOSSimulator)
103  .Case("watchos-simulator", PlatformKind::watchOSSimulator)
104  .Case("driverkit", PlatformKind::driverKit)
106 }
107 
109  std::string Version) {
110  switch (Platform) {
112  return "darwin" + Version;
113  case PlatformKind::macOS:
114  return "macos" + Version;
115  case PlatformKind::iOS:
116  return "ios" + Version;
117  case PlatformKind::tvOS:
118  return "tvos" + Version;
120  return "watchos" + Version;
122  return "bridgeos" + Version;
124  return "ios" + Version + "-macabi";
126  return "ios" + Version + "-simulator";
128  return "tvos" + Version + "-simulator";
130  return "watchos" + Version + "-simulator";
132  return "driverkit" + Version;
133  }
134  llvm_unreachable("Unknown llvm::MachO::PlatformKind enum");
135 }
136 
137 } // end namespace MachO.
138 } // end namespace llvm.
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
llvm::MachO::Target
Definition: Target.h:24
llvm::Triple::IOS
@ IOS
Definition: Triple.h:176
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
llvm::Triple::WatchOS
@ WatchOS
Definition: Triple.h:197
llvm::Triple::TvOS
@ TvOS
Definition: Triple.h:196
Platform.h
llvm::MachO::PlatformKind::iOS
@ iOS
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
llvm::MachO::PlatformKind::watchOSSimulator
@ watchOSSimulator
llvm::Triple::MacOSX
@ MacOSX
Definition: Triple.h:180
llvm::MachO::PlatformKind::macCatalyst
@ macCatalyst
llvm::MachO::PlatformKind::bridgeOS
@ bridgeOS
llvm::MachO::getPlatformName
StringRef getPlatformName(PlatformKind Platform)
Definition: Platform.cpp:65
ArrayRef.h
llvm::MachO::PlatformKind::driverKit
@ driverKit
llvm::MachO::mapToPlatformKind
PlatformKind mapToPlatformKind(PlatformKind Platform, bool WantSim)
Definition: Platform.cpp:21
Triple.h
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
llvm::MachO::getPlatformFromName
PlatformKind getPlatformFromName(StringRef Name)
Definition: Platform.cpp:93
llvm::MachO::PlatformKind::watchOS
@ watchOS
llvm::MachO::PlatformKind::macOS
@ macOS
llvm::MachO::getOSAndEnvironmentName
std::string getOSAndEnvironmentName(PlatformKind Platform, std::string Version="")
Definition: Platform.cpp:108
llvm::MachO::PlatformKind::tvOS
@ tvOS
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
StringSwitch.h
llvm::MachO::PlatformKind::iOSSimulator
@ iOSSimulator
llvm::Triple::MacABI
@ MacABI
Definition: Triple.h:231
llvm::MachO::mapToPlatformSet
PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
Definition: Platform.cpp:58
llvm::MachO::PlatformKind::tvOSSimulator
@ tvOSSimulator
llvm::MachO::PlatformKind
PlatformKind
Defines the list of MachO platforms.
Definition: Platform.h:22
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
llvm::MachO::PlatformKind::unknown
@ unknown