Target.h 2.1 KB

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