LLVM 22.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
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.
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:485
PlatformType Platform
Definition Target.h:44
static LLVM_ABI llvm::Expected< Target > create(StringRef Target)
Definition Target.cpp:17
Architecture Arch
Definition Target.h:43
VersionTuple MinDeployment
Definition Target.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A switch()-like statement whose cases are string literals.
LLVM_ABI 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).
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LLVM_ABI std::string getTargetTripleName(const Target &Targ)
Definition Target.cpp:76
LLVM_ABI Architecture getArchitectureFromName(StringRef Name)
Convert a name to an architecture slice.
LLVM_ABI StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
LLVM_ABI std::string getOSAndEnvironmentName(PlatformType Platform, std::string Version="")
Definition Platform.cpp:90
SmallSet< std::pair< PlatformType, VersionTuple >, 3 > PlatformVersionSet
Definition Platform.h:24
LLVM_ABI PlatformSet mapToPlatformSet(ArrayRef< Triple > Targets)
Definition Platform.cpp:62
SmallSet< PlatformType, 3 > PlatformSet
Definition Platform.h:23
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
LLVM_ABI PlatformVersionSet mapToPlatformVersionSet(ArrayRef< Target > Targets)
Definition Target.cpp:55
LLVM_ABI StringRef getPlatformName(PlatformType Platform)
Definition Platform.cpp:69
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
LLVM_ABI ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition Target.cpp:69
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:302
FunctionAddr VTableAddr uintptr_t uintptr_t TargetValue
Definition InstrProf.h:187