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 19namespace llvm { 20 21class Triple; 22 23namespace 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. 28class Target { 29public: 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(Triple)), Platform(mapToPlatformType(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 47inline bool operator==(const Target &LHS, const Target &RHS) { 48 // In most cases the deployment version is not useful to compare. 49 return std::tie(LHS.Arch, LHS.Platform) == std::tie(RHS.Arch, RHS.Platform); 50} 51 52inline bool operator!=(const Target &LHS, const Target &RHS) { 53 return !(LHS == RHS); 54} 55 56inline bool operator<(const Target &LHS, const Target &RHS) { 57 // In most cases the deployment version is not useful to compare. 58 return std::tie(LHS.Arch, LHS.Platform) < std::tie(RHS.Arch, RHS.Platform); 59} 60 61inline bool operator==(const Target &LHS, const Architecture &RHS) { 62 return LHS.Arch == RHS; 63} 64 65inline bool operator!=(const Target &LHS, const Architecture &RHS) { 66 return LHS.Arch != RHS; 67} 68 69PlatformVersionSet mapToPlatformVersionSet(ArrayRef<Target> Targets); 70PlatformSet mapToPlatformSet(ArrayRef<Target> Targets); 71ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets); 72 73std::string getTargetTripleName(const Target &Targ); 74 75raw_ostream &operator<<(raw_ostream &OS, const Target &Target); 76 77} // namespace MachO 78} // namespace llvm 79 80#endif // LLVM_TEXTAPI_TARGET_H 81