Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 1 | //===- llvm/TextAPI/MachO/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 | |
| 13 | #ifndef LLVM_TEXTAPI_MACHO_PACKED_VERSION_H |
| 14 | #define LLVM_TEXTAPI_MACHO_PACKED_VERSION_H |
| 15 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 16 | #include <cstdint> |
| 17 | #include <utility> |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 20 | class raw_ostream; |
| 21 | class StringRef; |
| 22 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 23 | namespace MachO { |
| 24 | |
| 25 | class PackedVersion { |
| 26 | uint32_t Version{0}; |
| 27 | |
| 28 | public: |
| 29 | constexpr PackedVersion() = default; |
| 30 | explicit constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {} |
| 31 | PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor) |
| 32 | : Version((Major << 16) | ((Minor & 0xff) << 8) | (Subminor & 0xff)) {} |
| 33 | |
| 34 | bool empty() const { return Version == 0; } |
| 35 | |
| 36 | /// Retrieve the major version number. |
| 37 | unsigned getMajor() const { return Version >> 16; } |
| 38 | |
| 39 | /// Retrieve the minor version number, if provided. |
| 40 | unsigned getMinor() const { return (Version >> 8) & 0xff; } |
| 41 | |
| 42 | /// Retrieve the subminor version number, if provided. |
| 43 | unsigned getSubminor() const { return Version & 0xff; } |
| 44 | |
| 45 | bool parse32(StringRef Str); |
| 46 | std::pair<bool, bool> parse64(StringRef Str); |
| 47 | |
| 48 | bool operator<(const PackedVersion &O) const { return Version < O.Version; } |
| 49 | |
| 50 | bool operator==(const PackedVersion &O) const { return Version == O.Version; } |
| 51 | |
| 52 | bool operator!=(const PackedVersion &O) const { return Version != O.Version; } |
| 53 | |
| 54 | uint32_t rawValue() const { return Version; } |
| 55 | |
| 56 | void print(raw_ostream &OS) const; |
| 57 | }; |
| 58 | |
| 59 | inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) { |
| 60 | Version.print(OS); |
| 61 | return OS; |
| 62 | } |
| 63 | |
| 64 | } // end namespace MachO. |
| 65 | } // end namespace llvm. |
| 66 | |
| 67 | #endif // LLVM_TEXTAPI_MACHO_PACKED_VERSION_H |