LLVM  16.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 PlatformType mapToPlatformType(PlatformType Platform, bool WantSim) {
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:
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
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  case PLATFORM_UNKNOWN:
66  return "unknown";
67  case PLATFORM_MACOS:
68  return "macOS";
69  case PLATFORM_IOS:
70  return "iOS";
71  case PLATFORM_TVOS:
72  return "tvOS";
73  case PLATFORM_WATCHOS:
74  return "watchOS";
75  case PLATFORM_BRIDGEOS:
76  return "bridgeOS";
78  return "macCatalyst";
80  return "iOS Simulator";
82  return "tvOS Simulator";
84  return "watchOS Simulator";
85  case PLATFORM_DRIVERKIT:
86  return "DriverKit";
87  }
88  llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
89 }
90 
93  .Case("macos", PLATFORM_MACOS)
94  .Case("ios", PLATFORM_IOS)
95  .Case("tvos", PLATFORM_TVOS)
96  .Case("watchos", PLATFORM_WATCHOS)
97  .Case("bridgeos", PLATFORM_BRIDGEOS)
98  .Case("ios-macabi", PLATFORM_MACCATALYST)
99  .Case("ios-simulator", PLATFORM_IOSSIMULATOR)
100  .Case("tvos-simulator", PLATFORM_TVOSSIMULATOR)
101  .Case("watchos-simulator", PLATFORM_WATCHOSSIMULATOR)
102  .Case("driverkit", PLATFORM_DRIVERKIT)
104 }
105 
107  std::string Version) {
108  switch (Platform) {
109  case PLATFORM_UNKNOWN:
110  return "darwin" + Version;
111  case PLATFORM_MACOS:
112  return "macos" + Version;
113  case PLATFORM_IOS:
114  return "ios" + Version;
115  case PLATFORM_TVOS:
116  return "tvos" + Version;
117  case PLATFORM_WATCHOS:
118  return "watchos" + Version;
119  case PLATFORM_BRIDGEOS:
120  return "bridgeos" + Version;
122  return "ios" + Version + "-macabi";
124  return "ios" + Version + "-simulator";
126  return "tvos" + Version + "-simulator";
128  return "watchos" + Version + "-simulator";
129  case PLATFORM_DRIVERKIT:
130  return "driverkit" + Version;
131  }
132  llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
133 }
134 
135 } // end namespace MachO.
136 } // end namespace llvm.
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
llvm::MachO::PLATFORM_MACOS
@ PLATFORM_MACOS
Definition: MachO.h:499
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MachO::PLATFORM_WATCHOSSIMULATOR
@ PLATFORM_WATCHOSSIMULATOR
Definition: MachO.h:507
llvm::MachO::Target
Definition: Target.h:26
llvm::Triple::IOS
@ IOS
Definition: Triple.h:191
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::MachO::PLATFORM_IOS
@ PLATFORM_IOS
Definition: MachO.h:500
llvm::MachO::PLATFORM_MACCATALYST
@ PLATFORM_MACCATALYST
Definition: MachO.h:504
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:136
llvm::Triple::WatchOS
@ WatchOS
Definition: Triple.h:213
llvm::MachO::PLATFORM_IOSSIMULATOR
@ PLATFORM_IOSSIMULATOR
Definition: MachO.h:505
llvm::MachO::PLATFORM_UNKNOWN
@ PLATFORM_UNKNOWN
Definition: MachO.h:498
llvm::Triple::TvOS
@ TvOS
Definition: Triple.h:212
llvm::MachO::mapToPlatformType
PlatformType mapToPlatformType(PlatformType Platform, bool WantSim)
Definition: Platform.cpp:21
Platform.h
llvm::MachO::getOSAndEnvironmentName
std::string getOSAndEnvironmentName(PlatformType Platform, std::string Version="")
Definition: Platform.cpp:106
llvm::MachO::PlatformType
PlatformType
Definition: MachO.h:497
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:1056
llvm::MachO::getPlatformFromName
PlatformType getPlatformFromName(StringRef Name)
Definition: Platform.cpp:91
llvm::Triple::MacOSX
@ MacOSX
Definition: Triple.h:195
ArrayRef.h
llvm::MachO::PLATFORM_BRIDGEOS
@ PLATFORM_BRIDGEOS
Definition: MachO.h:503
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:50
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::MachO::PLATFORM_TVOS
@ PLATFORM_TVOS
Definition: MachO.h:501
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::MachO::PLATFORM_TVOSSIMULATOR
@ PLATFORM_TVOSSIMULATOR
Definition: MachO.h:506
StringSwitch.h
llvm::MachO::PLATFORM_WATCHOS
@ PLATFORM_WATCHOS
Definition: MachO.h:502
llvm::Triple::MacABI
@ MacABI
Definition: Triple.h:249
llvm::MachO::mapToPlatformSet
PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
Definition: Platform.cpp:56
llvm::MachO::PLATFORM_DRIVERKIT
@ PLATFORM_DRIVERKIT
Definition: MachO.h:508
llvm::StringSwitch::Default
R Default(T Value)
Definition: StringSwitch.h:182
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
llvm::MachO::getPlatformName
StringRef getPlatformName(PlatformType Platform)
Definition: Platform.cpp:63