PackedVersion.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===- llvm/TextAPI/PackedVersion.h - PackedVersion -------------*- 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. // Defines the Mach-O packed version format.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_TEXTAPI_MACHO_PACKEDVERSION_H
  13. #define LLVM_TEXTAPI_MACHO_PACKEDVERSION_H
  14. #include <cstdint>
  15. #include <utility>
  16. namespace llvm {
  17. class raw_ostream;
  18. class StringRef;
  19. namespace MachO {
  20. class PackedVersion {
  21. uint32_t Version{0};
  22. public:
  23. constexpr PackedVersion() = default;
  24. explicit constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {}
  25. PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
  26. : Version((Major << 16) | ((Minor & 0xff) << 8) | (Subminor & 0xff)) {}
  27. bool empty() const { return Version == 0; }
  28. /// Retrieve the major version number.
  29. unsigned getMajor() const { return Version >> 16; }
  30. /// Retrieve the minor version number, if provided.
  31. unsigned getMinor() const { return (Version >> 8) & 0xff; }
  32. /// Retrieve the subminor version number, if provided.
  33. unsigned getSubminor() const { return Version & 0xff; }
  34. bool parse32(StringRef Str);
  35. std::pair<bool, bool> parse64(StringRef Str);
  36. bool operator<(const PackedVersion &O) const { return Version < O.Version; }
  37. bool operator==(const PackedVersion &O) const { return Version == O.Version; }
  38. bool operator!=(const PackedVersion &O) const { return Version != O.Version; }
  39. uint32_t rawValue() const { return Version; }
  40. void print(raw_ostream &OS) const;
  41. };
  42. inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) {
  43. Version.print(OS);
  44. return OS;
  45. }
  46. } // end namespace MachO.
  47. } // end namespace llvm.
  48. #endif // LLVM_TEXTAPI_MACHO_PACKEDVERSION_H