LLVM  13.0.0git
Target.cpp
Go to the documentation of this file.
1 //===- Target.cpp -----------------------------------------------*- 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/TextAPI/Target.h"
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/ADT/SmallVector.h"
12 #include "llvm/ADT/StringExtras.h"
13 #include "llvm/ADT/StringSwitch.h"
14 #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;
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)
36  .Case("driverkit", PlatformKind::driverKit)
38 
40  if (PlatformStr.startswith("<") && PlatformStr.endswith(">")) {
41  PlatformStr = PlatformStr.drop_front().drop_back();
42  unsigned long long RawValue;
43  if (!PlatformStr.getAsInteger(10, RawValue))
44  Platform = (PlatformKind)RawValue;
45  }
46  }
47 
48  return Target{Architecture, Platform};
49 }
50 
51 Target::operator std::string() const {
52  return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) + ")")
53  .str();
54 }
55 
57  OS << std::string(Target);
58  return OS;
59 }
60 
62  PlatformSet Result;
63  for (const auto &Target : Targets)
64  Result.insert(Target.Platform);
65  return Result;
66 }
67 
69  ArchitectureSet Result;
70  for (const auto &Target : Targets)
71  Result.set(Target.Arch);
72  return Result;
73 }
74 
75 } // end namespace MachO.
76 } // end namespace llvm.
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
llvm::MachO::Target::Arch
Architecture Arch
Definition: Target.h:36
llvm
Definition: AllocatorList.h:23
llvm::MachO::mapToArchitectureSet
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:68
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
llvm::MachO::Target
Definition: Target.h:24
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::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
Format.h
Target.h
llvm::MachO::Target::create
static llvm::Expected< Target > create(StringRef Target)
Definition: Target.cpp:20
SmallString.h
llvm::StringRef::split
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:727
llvm::MachO::PlatformKind::iOS
@ iOS
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::MachO::PlatformKind::watchOSSimulator
@ watchOSSimulator
llvm::MachO::ArchitectureSet
Definition: ArchitectureSet.h:29
llvm::MachO::PlatformKind::macCatalyst
@ macCatalyst
llvm::MachO::Architecture
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:27
llvm::MachO::operator<<
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
Definition: Architecture.cpp:92
llvm::MachO::PlatformKind::bridgeOS
@ bridgeOS
StringExtras.h
llvm::MachO::getPlatformName
StringRef getPlatformName(PlatformKind Platform)
Definition: Platform.cpp:65
llvm::MachO::PlatformKind::driverKit
@ driverKit
llvm::MachO::Target::Platform
PlatformKind Platform
Definition: Target.h:37
llvm::MachO::getArchitectureFromName
Architecture getArchitectureFromName(StringRef Name)
Convert a name to an architecture slice.
Definition: Architecture.cpp:34
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::MachO::PlatformKind::watchOS
@ watchOS
llvm::MachO::PlatformKind::macOS
@ macOS
llvm::MachO::PlatformKind::tvOS
@ tvOS
StringSwitch.h
llvm::MachO::PlatformKind::iOSSimulator
@ iOSSimulator
SmallVector.h
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::getArchitectureName
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
Definition: Architecture.cpp:42
raw_ostream.h
llvm::MachO::PlatformKind::unknown
@ unknown