PackedVersion.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/TextAPI/PackedVersion.h - PackedVersion -------------*- 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. //
  14. // Defines the Mach-O packed version format.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_TEXTAPI_PACKEDVERSION_H
  18. #define LLVM_TEXTAPI_PACKEDVERSION_H
  19. #include <cstdint>
  20. #include <utility>
  21. namespace llvm {
  22. class raw_ostream;
  23. class StringRef;
  24. namespace MachO {
  25. class PackedVersion {
  26. uint32_t Version{0};
  27. public:
  28. constexpr PackedVersion() = default;
  29. explicit constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {}
  30. PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
  31. : Version((Major << 16) | ((Minor & 0xff) << 8) | (Subminor & 0xff)) {}
  32. bool empty() const { return Version == 0; }
  33. /// Retrieve the major version number.
  34. unsigned getMajor() const { return Version >> 16; }
  35. /// Retrieve the minor version number, if provided.
  36. unsigned getMinor() const { return (Version >> 8) & 0xff; }
  37. /// Retrieve the subminor version number, if provided.
  38. unsigned getSubminor() const { return Version & 0xff; }
  39. bool parse32(StringRef Str);
  40. std::pair<bool, bool> parse64(StringRef Str);
  41. bool operator<(const PackedVersion &O) const { return Version < O.Version; }
  42. bool operator==(const PackedVersion &O) const { return Version == O.Version; }
  43. bool operator!=(const PackedVersion &O) const { return Version != O.Version; }
  44. uint32_t rawValue() const { return Version; }
  45. void print(raw_ostream &OS) const;
  46. };
  47. inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) {
  48. Version.print(OS);
  49. return OS;
  50. }
  51. } // end namespace MachO.
  52. } // end namespace llvm.
  53. #endif // LLVM_TEXTAPI_PACKEDVERSION_H
  54. #ifdef __GNUC__
  55. #pragma GCC diagnostic pop
  56. #endif