blob: 0d9158ae5f0d3d0b510ffff87d1d631faaccacb5 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===- 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 Deprezf4ef2d02021-04-20 13:36:24 +020016#include <cstdint>
17#include <utility>
Andrew Walbran3d2c1972020-04-07 12:24:26 +010018
19namespace llvm {
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020020class raw_ostream;
21class StringRef;
22
Andrew Walbran3d2c1972020-04-07 12:24:26 +010023namespace MachO {
24
25class PackedVersion {
26 uint32_t Version{0};
27
28public:
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
59inline 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