1//===- llvm/TextAPI/Target.h - TAPI Target ----------------------*- 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#ifndef LLVM_TEXTAPI_TARGET_H
10#define LLVM_TEXTAPI_TARGET_H
11
12#include "llvm/Support/Compiler.h"
13#include "llvm/Support/Error.h"
14#include "llvm/Support/VersionTuple.h"
15#include "llvm/TargetParser/Triple.h"
16#include "llvm/TextAPI/Architecture.h"
17#include "llvm/TextAPI/ArchitectureSet.h"
18#include "llvm/TextAPI/Platform.h"
19
20namespace llvm {
21
22class Triple;
23
24namespace MachO {
25
26// This is similar to a llvm Triple, but the triple doesn't have all the
27// information we need. For example there is no enum value for x86_64h. The
28// only way to get that information is to parse the triple string.
29class Target {
30public:
31 Target() = default;
32 Target(Architecture Arch, PlatformType Platform,
33 VersionTuple MinDeployment = {})
34 : Arch(Arch), Platform(Platform), MinDeployment(MinDeployment) {}
35 explicit Target(const llvm::Triple &Triple)
36 : Arch(mapToArchitecture(Target: Triple)), Platform(mapToPlatformType(Target: Triple)),
37 MinDeployment(mapToSupportedOSVersion(Triple)) {}
38
39 LLVM_ABI static llvm::Expected<Target> create(StringRef Target);
40
41 LLVM_ABI operator std::string() const;
42
43 Architecture Arch;
44 PlatformType Platform;
45 VersionTuple MinDeployment;
46};
47
48inline bool operator==(const Target &LHS, const Target &RHS) {
49 // In most cases the deployment version is not useful to compare.
50 return std::tie(args: LHS.Arch, args: LHS.Platform) == std::tie(args: RHS.Arch, args: RHS.Platform);
51}
52
53inline bool operator!=(const Target &LHS, const Target &RHS) {
54 return !(LHS == RHS);
55}
56
57inline bool operator<(const Target &LHS, const Target &RHS) {
58 // In most cases the deployment version is not useful to compare.
59 return std::tie(args: LHS.Arch, args: LHS.Platform) < std::tie(args: RHS.Arch, args: RHS.Platform);
60}
61
62inline bool operator==(const Target &LHS, const Architecture &RHS) {
63 return LHS.Arch == RHS;
64}
65
66inline bool operator!=(const Target &LHS, const Architecture &RHS) {
67 return LHS.Arch != RHS;
68}
69
70LLVM_ABI PlatformVersionSet mapToPlatformVersionSet(ArrayRef<Target> Targets);
71LLVM_ABI PlatformSet mapToPlatformSet(ArrayRef<Target> Targets);
72LLVM_ABI ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets);
73
74LLVM_ABI std::string getTargetTripleName(const Target &Targ);
75
76LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const Target &Target);
77
78} // namespace MachO
79} // namespace llvm
80
81#endif // LLVM_TEXTAPI_TARGET_H
82