Target.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/TextAPI/Target.h - TAPI Target ----------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TEXTAPI_TARGET_H
  14. #define LLVM_TEXTAPI_TARGET_H
  15. #include "llvm/Support/Error.h"
  16. #include "llvm/TextAPI/Architecture.h"
  17. #include "llvm/TextAPI/ArchitectureSet.h"
  18. #include "llvm/TextAPI/Platform.h"
  19. namespace llvm {
  20. class Triple;
  21. namespace MachO {
  22. // This is similar to a llvm Triple, but the triple doesn't have all the
  23. // information we need. For example there is no enum value for x86_64h. The
  24. // only way to get that information is to parse the triple string.
  25. class Target {
  26. public:
  27. Target() = default;
  28. Target(Architecture Arch, PlatformType Platform)
  29. : Arch(Arch), Platform(Platform) {}
  30. explicit Target(const llvm::Triple &Triple)
  31. : Arch(mapToArchitecture(Triple)), Platform(mapToPlatformType(Triple)) {}
  32. static llvm::Expected<Target> create(StringRef Target);
  33. operator std::string() const;
  34. Architecture Arch;
  35. PlatformType Platform;
  36. };
  37. inline bool operator==(const Target &LHS, const Target &RHS) {
  38. return std::tie(LHS.Arch, LHS.Platform) == std::tie(RHS.Arch, RHS.Platform);
  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. inline bool operator<(const Target &LHS, const Target &RHS) {
  44. return std::tie(LHS.Arch, LHS.Platform) < std::tie(RHS.Arch, RHS.Platform);
  45. }
  46. inline bool operator==(const Target &LHS, const Architecture &RHS) {
  47. return LHS.Arch == RHS;
  48. }
  49. inline bool operator!=(const Target &LHS, const Architecture &RHS) {
  50. return LHS.Arch != RHS;
  51. }
  52. PlatformSet mapToPlatformSet(ArrayRef<Target> Targets);
  53. ArchitectureSet mapToArchitectureSet(ArrayRef<Target> Targets);
  54. std::string getTargetTripleName(const Target &Targ);
  55. raw_ostream &operator<<(raw_ostream &OS, const Target &Target);
  56. } // namespace MachO
  57. } // namespace llvm
  58. #endif // LLVM_TEXTAPI_TARGET_H
  59. #ifdef __GNUC__
  60. #pragma GCC diagnostic pop
  61. #endif