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 | |
| 16 | #include "llvm/ADT/StringRef.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
| 18 | |
| 19 | namespace llvm { |
| 20 | namespace MachO { |
| 21 | |
| 22 | class PackedVersion { |
| 23 | uint32_t Version{0}; |
| 24 | |
| 25 | public: |
| 26 | constexpr PackedVersion() = default; |
| 27 | explicit constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {} |
| 28 | PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor) |
| 29 | : Version((Major << 16) | ((Minor & 0xff) << 8) | (Subminor & 0xff)) {} |
| 30 | |
| 31 | bool empty() const { return Version == 0; } |
| 32 | |
| 33 | /// Retrieve the major version number. |
| 34 | unsigned getMajor() const { return Version >> 16; } |
| 35 | |
| 36 | /// Retrieve the minor version number, if provided. |
| 37 | unsigned getMinor() const { return (Version >> 8) & 0xff; } |
| 38 | |
| 39 | /// Retrieve the subminor version number, if provided. |
| 40 | unsigned getSubminor() const { return Version & 0xff; } |
| 41 | |
| 42 | bool parse32(StringRef Str); |
| 43 | std::pair<bool, bool> parse64(StringRef Str); |
| 44 | |
| 45 | bool operator<(const PackedVersion &O) const { return Version < O.Version; } |
| 46 | |
| 47 | bool operator==(const PackedVersion &O) const { return Version == O.Version; } |
| 48 | |
| 49 | bool operator!=(const PackedVersion &O) const { return Version != O.Version; } |
| 50 | |
| 51 | uint32_t rawValue() const { return Version; } |
| 52 | |
| 53 | void print(raw_ostream &OS) const; |
| 54 | }; |
| 55 | |
| 56 | inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) { |
| 57 | Version.print(OS); |
| 58 | return OS; |
| 59 | } |
| 60 | |
| 61 | } // end namespace MachO. |
| 62 | } // end namespace llvm. |
| 63 | |
| 64 | #endif // LLVM_TEXTAPI_MACHO_PACKED_VERSION_H |