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/Architecture.h"
15#include "llvm/TextAPI/ArchitectureSet.h"
16#include "llvm/TextAPI/Platform.h"
17
18namespace llvm {
19namespace 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.
24class Target {
25public:
26 Target() = default;
27 Target(Architecture Arch, PlatformKind Platform)
28 : Arch(Arch), Platform(Platform) {}
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
40inline bool operator==(const Target &LHS, const Target &RHS) {
41 return std::tie(LHS.Arch, LHS.Platform) == std::tie(RHS.Arch, RHS.Platform);
42}
43
44inline bool operator!=(const Target &LHS, const Target &RHS) {
45 return std::tie(LHS.Arch, LHS.Platform) != std::tie(RHS.Arch, RHS.Platform);
46}
47
48inline bool operator<(const Target &LHS, const Target &RHS) {
49 return std::tie(LHS.Arch, LHS.Platform) < std::tie(RHS.Arch, RHS.Platform);
50}
51
52inline bool operator==(const Target &LHS, const Architecture &RHS) {
53 return LHS.Arch == RHS;
54}
55
56inline bool operator!=(const Target &LHS, const Architecture &RHS) {
57 return LHS.Arch != RHS;
58}
59
60PlatformSet mapToPlatformSet(ArrayRef<Target> Targets);
61ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets);
62
63raw_ostream &operator<<(raw_ostream &OS, const Target &Target);
64
65} // namespace MachO
66} // namespace llvm
67
68#endif // LLVM_TEXTAPI_MACHO_TARGET_H
69