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