LLVM 20.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#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
25 marketing) \
26 .Case(#tapi_target, PLATFORM_##platform)
27#include "llvm/BinaryFormat/MachO.def"
28 .Default(PLATFORM_UNKNOWN);
29
30 if (Platform == PLATFORM_UNKNOWN) {
31 if (PlatformStr.starts_with("<") && PlatformStr.ends_with(">")) {
32 PlatformStr = PlatformStr.drop_front().drop_back();
33 unsigned long long RawValue;
34 if (!PlatformStr.getAsInteger(10, RawValue))
35 Platform = (PlatformType)RawValue;
36 }
37 }
38
40}
41
42Target::operator std::string() const {
43 auto Version = MinDeployment.empty() ? "" : MinDeployment.getAsString();
44
45 return (getArchitectureName(Arch) + " (" + getPlatformName(Platform) +
46 Version + ")")
47 .str();
48}
49
51 OS << std::string(Target);
52 return OS;
53}
54
56 PlatformVersionSet Result;
57 for (const auto &Target : Targets)
58 Result.insert({Target.Platform, Target.MinDeployment});
59 return Result;
60}
61
63 PlatformSet Result;
64 for (const auto &Target : Targets)
65 Result.insert(Target.Platform);
66 return Result;
67}
68
70 ArchitectureSet Result;
71 for (const auto &Target : Targets)
72 Result.set(Target.Arch);
73 return Result;
74}
75
76std::string getTargetTripleName(const Target &Targ) {
77 auto Version =
78 Targ.MinDeployment.empty() ? "" : Targ.MinDeployment.getAsString();
79
80 return (getArchitectureName(Targ.Arch) + "-apple-" +
82 .str();
83}
84
85} // end namespace MachO.
86} // 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:481
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:685
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
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:66
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:76
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:90
PlatformType
Definition: MachO.h:500
PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
Definition: Platform.cpp:62
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:55
StringRef getPlatformName(PlatformType Platform)
Definition: Platform.cpp:69
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:69
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18