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