1 //===- llvm/TextAPI/PackedVersion.h - PackedVersion -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines the Mach-O packed version format.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TEXTAPI_MACHO_PACKED_VERSION_H
16 #define LLVM_TEXTAPI_MACHO_PACKED_VERSION_H
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/raw_ostream.h"
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)) {}
33 bool empty() const { return Version == 0; }
35 /// Retrieve the major version number.
36 unsigned getMajor() const { return Version >> 16; }
38 /// Retrieve the minor version number, if provided.
39 unsigned getMinor() const { return (Version >> 8) & 0xff; }
41 /// Retrieve the subminor version number, if provided.
42 unsigned getSubminor() const { return Version & 0xff; }
44 bool parse32(StringRef Str);
45 std::pair<bool, bool> parse64(StringRef Str);
47 bool operator<(const PackedVersion &O) const { return Version < O.Version; }
49 bool operator==(const PackedVersion &O) const { return Version == O.Version; }
51 bool operator!=(const PackedVersion &O) const { return Version != O.Version; }
53 uint32_t rawValue() const { return Version; }
55 void print(raw_ostream &OS) const;
58 inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) {
63 } // end namespace MachO.
64 } // end namespace llvm.
66 #endif // LLVM_TEXTAPI_MACHO_PACKED_VERSION_H