xref: /freebsd/contrib/llvm-project/llvm/include/llvm/TextAPI/Target.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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 
20 namespace llvm {
21 
22 class Triple;
23 
24 namespace 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.
29 class Target {
30 public:
31   Target() = default;
32   Target(Architecture Arch, PlatformType Platform,
33          VersionTuple MinDeployment = {})
Arch(Arch)34       : Arch(Arch), Platform(Platform), MinDeployment(MinDeployment) {}
Target(const llvm::Triple & Triple)35   explicit Target(const llvm::Triple &Triple)
36       : Arch(mapToArchitecture(Triple)), Platform(mapToPlatformType(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 
48 inline bool operator==(const Target &LHS, const Target &RHS) {
49   // In most cases the deployment version is not useful to compare.
50   return std::tie(LHS.Arch, LHS.Platform) == std::tie(RHS.Arch, RHS.Platform);
51 }
52 
53 inline bool operator!=(const Target &LHS, const Target &RHS) {
54   return !(LHS == RHS);
55 }
56 
57 inline bool operator<(const Target &LHS, const Target &RHS) {
58   // In most cases the deployment version is not useful to compare.
59   return std::tie(LHS.Arch, LHS.Platform) < std::tie(RHS.Arch, RHS.Platform);
60 }
61 
62 inline bool operator==(const Target &LHS, const Architecture &RHS) {
63   return LHS.Arch == RHS;
64 }
65 
66 inline bool operator!=(const Target &LHS, const Architecture &RHS) {
67   return LHS.Arch != RHS;
68 }
69 
70 LLVM_ABI PlatformVersionSet mapToPlatformVersionSet(ArrayRef<Target> Targets);
71 LLVM_ABI PlatformSet mapToPlatformSet(ArrayRef<Target> Targets);
72 LLVM_ABI ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets);
73 
74 LLVM_ABI std::string getTargetTripleName(const Target &Targ);
75 
76 LLVM_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