LLVM  10.0.0svn
Target.cpp
Go to the documentation of this file.
1 //===- tapi/Core/Target.cpp - Target ----------------------------*- 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 #include "llvm/ADT/SmallString.h"
10 #include "llvm/ADT/SmallVector.h"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/ADT/StringSwitch.h"
13 #include "llvm/Support/Format.h"
16 
17 namespace llvm {
18 namespace MachO {
19 
21  auto Result = TargetValue.split('-');
22  auto ArchitectureStr = Result.first;
23  auto Architecture = getArchitectureFromName(ArchitectureStr);
24  auto PlatformStr = Result.second;
26  Platform = StringSwitch<PlatformKind>(PlatformStr)
27  .Case("macos", PlatformKind::macOS)
28  .Case("ios", PlatformKind::iOS)
29  .Case("tvos", PlatformKind::tvOS)
30  .Case("watchos", PlatformKind::watchOS)
31  .Case("bridgeos", PlatformKind::bridgeOS)
32  .Case("maccatalyst", PlatformKind::macCatalyst)
33  .Case("ios-simulator", PlatformKind::iOSSimulator)
34  .Case("tvos-simulator", PlatformKind::tvOSSimulator)
35  .Case("watchos-simulator", PlatformKind::watchOSSimulator)
37 
38  if (Platform == PlatformKind::unknown) {
39  if (PlatformStr.startswith("<") && PlatformStr.endswith(">")) {
40  PlatformStr = PlatformStr.drop_front().drop_back();
41  unsigned long long RawValue;
42  if (!PlatformStr.getAsInteger(10, RawValue))
43  Platform = (PlatformKind)RawValue;
44  }
45  }
46 
47  return Target{Architecture, Platform};
48 }
49 
50 Target::operator std::string() const {
51  return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) + ")")
52  .str();
53 }
54 
56  OS << std::string(Target);
57  return OS;
58 }
59 
61  PlatformSet Result;
62  for (const auto &Target : Targets)
63  Result.insert(Target.Platform);
64  return Result;
65 }
66 
68  ArchitectureSet Result;
69  for (const auto &Target : Targets)
70  Result.set(Target.Arch);
71  return Result;
72 }
73 
74 } // end namespace MachO.
75 } // end namespace llvm.
PlatformKind
Defines the list of MachO platforms.
Definition: Platform.h:22
This class represents lattice values for constants.
Definition: AllocatorList.h:23
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:67
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
void set(Architecture Arch)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
static llvm::Expected< Target > create(StringRef Target)
Definition: Target.cpp:20
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
StringRef getPlatformName(PlatformKind Platform)
Definition: Platform.cpp:64
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn&#39;t already there.
Definition: SmallSet.h:180
PlatformKind Platform
Definition: Target.h:37
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:24
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:710
Architecture getArchitectureFromName(StringRef Name)
Convert a name to an architecture slice.
PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
Definition: Platform.cpp:57
Architecture Arch
Definition: Target.h:36
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.