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