LLVM 18.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
11#include "llvm/ADT/Twine.h"
13
14namespace llvm {
15namespace 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
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
46}
47
48Target::operator std::string() const {
49 auto Version = MinDeployment.empty() ? "" : MinDeployment.getAsString();
50
51 return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) +
52 Version + ")")
53 .str();
54}
55
57 OS << std::string(Target);
58 return OS;
59}
60
62 PlatformVersionSet Result;
63 for (const auto &Target : Targets)
64 Result.insert({Target.Platform, Target.MinDeployment});
65 return Result;
66}
67
69 PlatformSet Result;
70 for (const auto &Target : Targets)
71 Result.insert(Target.Platform);
72 return Result;
73}
74
76 ArchitectureSet Result;
77 for (const auto &Target : Targets)
78 Result.set(Target.Arch);
79 return Result;
80}
81
82std::string getTargetTripleName(const Target &Targ) {
83 auto Version =
84 Targ.MinDeployment.empty() ? "" : Targ.MinDeployment.getAsString();
85
86 return (getArchitectureName(Targ.Arch) + "-apple-" +
87 getOSAndEnvironmentName(Targ.Platform, Version))
88 .str();
89}
90
91} // end namespace MachO.
92} // end namespace llvm.
raw_pwrite_stream & OS
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Tagged union holding either a T or a Error.
Definition: Error.h:474
PlatformType Platform
Definition: Target.h:43
static llvm::Expected< Target > create(StringRef Target)
Definition: Target.cpp:17
Architecture Arch
Definition: Target.h:42
VersionTuple MinDeployment
Definition: Target.h:44
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:704
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
std::string getAsString() const
Retrieve a string representation of the version number.
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero).
Definition: VersionTuple.h:68
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
std::string getTargetTripleName(const Target &Targ)
Definition: Target.cpp:82
Architecture getArchitectureFromName(StringRef Name)
Convert a name to an architecture slice.
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
std::string getOSAndEnvironmentName(PlatformType Platform, std::string Version="")
Definition: Platform.cpp:107
PlatformType
Definition: MachO.h:499
@ PLATFORM_MACCATALYST
Definition: MachO.h:506
@ PLATFORM_DRIVERKIT
Definition: MachO.h:510
@ PLATFORM_WATCHOS
Definition: MachO.h:504
@ PLATFORM_UNKNOWN
Definition: MachO.h:500
@ PLATFORM_WATCHOSSIMULATOR
Definition: MachO.h:509
@ PLATFORM_IOS
Definition: MachO.h:502
@ PLATFORM_TVOS
Definition: MachO.h:503
@ PLATFORM_TVOSSIMULATOR
Definition: MachO.h:508
@ PLATFORM_BRIDGEOS
Definition: MachO.h:505
@ PLATFORM_MACOS
Definition: MachO.h:501
@ PLATFORM_IOSSIMULATOR
Definition: MachO.h:507
PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
Definition: Platform.cpp:56
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:27
PlatformVersionSet mapToPlatformVersionSet(ArrayRef< Target > Targets)
Definition: Target.cpp:61
StringRef getPlatformName(PlatformType Platform)
Definition: Platform.cpp:63
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18