LLVM  15.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/StringSwitch.h"
11 #include "llvm/ADT/Twine.h"
13 
14 namespace llvm {
15 namespace MachO {
16 
18  auto Result = TargetValue.split('-');
19  auto ArchitectureStr = Result.first;
20  auto Architecture = getArchitectureFromName(ArchitectureStr);
21  auto PlatformStr = Result.second;
24  .Case("macos", PLATFORM_MACOS)
25  .Case("ios", PLATFORM_IOS)
26  .Case("tvos", PLATFORM_TVOS)
27  .Case("watchos", PLATFORM_WATCHOS)
28  .Case("bridgeos", PLATFORM_BRIDGEOS)
29  .Case("maccatalyst", PLATFORM_MACCATALYST)
30  .Case("ios-simulator", PLATFORM_IOSSIMULATOR)
31  .Case("tvos-simulator", PLATFORM_TVOSSIMULATOR)
32  .Case("watchos-simulator", PLATFORM_WATCHOSSIMULATOR)
33  .Case("driverkit", PLATFORM_DRIVERKIT)
35 
36  if (Platform == PLATFORM_UNKNOWN) {
37  if (PlatformStr.startswith("<") && PlatformStr.endswith(">")) {
38  PlatformStr = PlatformStr.drop_front().drop_back();
39  unsigned long long RawValue;
40  if (!PlatformStr.getAsInteger(10, RawValue))
41  Platform = (PlatformType)RawValue;
42  }
43  }
44 
45  return Target{Architecture, Platform};
46 }
47 
48 Target::operator std::string() const {
49  return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) + ")")
50  .str();
51 }
52 
54  OS << std::string(Target);
55  return OS;
56 }
57 
59  PlatformSet Result;
60  for (const auto &Target : Targets)
61  Result.insert(Target.Platform);
62  return Result;
63 }
64 
66  ArchitectureSet Result;
67  for (const auto &Target : Targets)
68  Result.set(Target.Arch);
69  return Result;
70 }
71 
72 std::string getTargetTripleName(const Target &Targ) {
73  return (getArchitectureName(Targ.Arch) + "-apple-" +
75  .str();
76 }
77 
78 } // end namespace MachO.
79 } // end namespace llvm.
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
llvm::MachO::Target::Arch
Architecture Arch
Definition: Target.h:38
llvm::MachO::PLATFORM_MACOS
@ PLATFORM_MACOS
Definition: MachO.h:494
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::MachO::PLATFORM_WATCHOSSIMULATOR
@ PLATFORM_WATCHOSSIMULATOR
Definition: MachO.h:502
llvm::MachO::mapToArchitectureSet
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:65
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:183
llvm::MachO::Target
Definition: Target.h:26
llvm::MachO::PLATFORM_IOS
@ PLATFORM_IOS
Definition: MachO.h:495
llvm::MachO::PLATFORM_MACCATALYST
@ PLATFORM_MACCATALYST
Definition: MachO.h:499
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::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
Target.h
llvm::MachO::PLATFORM_IOSSIMULATOR
@ PLATFORM_IOSSIMULATOR
Definition: MachO.h:500
llvm::MachO::PLATFORM_UNKNOWN
@ PLATFORM_UNKNOWN
Definition: MachO.h:493
llvm::MachO::Target::create
static llvm::Expected< Target > create(StringRef Target)
Definition: Target.cpp:17
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:753
Twine.h
llvm::MachO::getOSAndEnvironmentName
std::string getOSAndEnvironmentName(PlatformType Platform, std::string Version="")
Definition: Platform.cpp:106
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::MachO::PlatformType
PlatformType
Definition: MachO.h:492
llvm::MachO::Target::Platform
PlatformType Platform
Definition: Target.h:39
llvm::MachO::ArchitectureSet
Definition: ArchitectureSet.h:29
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::PLATFORM_BRIDGEOS
@ PLATFORM_BRIDGEOS
Definition: MachO.h:498
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::PLATFORM_TVOS
@ PLATFORM_TVOS
Definition: MachO.h:496
llvm::MachO::PLATFORM_TVOSSIMULATOR
@ PLATFORM_TVOSSIMULATOR
Definition: MachO.h:501
llvm::MachO::getTargetTripleName
std::string getTargetTripleName(const Target &Targ)
Definition: Target.cpp:72
StringSwitch.h
llvm::MachO::PLATFORM_WATCHOS
@ PLATFORM_WATCHOS
Definition: MachO.h:497
llvm::MachO::mapToPlatformSet
PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
Definition: Platform.cpp:56
llvm::MachO::PLATFORM_DRIVERKIT
@ PLATFORM_DRIVERKIT
Definition: MachO.h:503
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
llvm::MachO::getArchitectureName
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
Definition: Architecture.cpp:42
raw_ostream.h
llvm::MachO::getPlatformName
StringRef getPlatformName(PlatformType Platform)
Definition: Platform.cpp:63