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