LLVM 22.0.0git
PackedVersion.h
Go to the documentation of this file.
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
18#include <cstdint>
19#include <string>
20#include <utility>
21
22namespace llvm {
23class raw_ostream;
24class StringRef;
25
26namespace MachO {
27
29 uint32_t Version{0};
30
31public:
32 constexpr PackedVersion() = default;
33 constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {}
34 PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
35 : Version((Major << 16) | ((Minor & 0xff) << 8) | (Subminor & 0xff)) {}
36
38 unsigned Minor = 0, Subminor = 0;
39 if (auto VTMinor = VT.getMinor())
40 Minor = *VTMinor;
41 if (auto VTSub = VT.getSubminor())
42 Subminor = *VTSub;
43 *this = PackedVersion(VT.getMajor(), Minor, Subminor);
44 }
45
46 bool empty() const { return Version == 0; }
47
48 /// Retrieve the major version number.
49 unsigned getMajor() const { return Version >> 16; }
50
51 /// Retrieve the minor version number, if provided.
52 unsigned getMinor() const { return (Version >> 8) & 0xff; }
53
54 /// Retrieve the subminor version number, if provided.
55 unsigned getSubminor() const { return Version & 0xff; }
56
57 LLVM_ABI bool parse32(StringRef Str);
58 LLVM_ABI std::pair<bool, bool> parse64(StringRef Str);
59
60 bool operator<(const PackedVersion &O) const { return Version < O.Version; }
61
62 bool operator==(const PackedVersion &O) const { return Version == O.Version; }
63
64 bool operator!=(const PackedVersion &O) const { return Version != O.Version; }
65
66 uint32_t rawValue() const { return Version; }
67
68 LLVM_ABI operator std::string() const;
69
70 LLVM_ABI void print(raw_ostream &OS) const;
71};
72
74 Version.print(OS);
75 return OS;
76}
77
78} // end namespace MachO.
79} // end namespace llvm.
80
81#endif // LLVM_TEXTAPI_PACKEDVERSION_H
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
Defines the llvm::VersionTuple class, which represents a version in the form major[....
bool operator==(const PackedVersion &O) const
Definition: PackedVersion.h:62
LLVM_ABI void print(raw_ostream &OS) const
unsigned getMinor() const
Retrieve the minor version number, if provided.
Definition: PackedVersion.h:52
LLVM_ABI bool parse32(StringRef Str)
constexpr PackedVersion()=default
LLVM_ABI std::pair< bool, bool > parse64(StringRef Str)
bool operator!=(const PackedVersion &O) const
Definition: PackedVersion.h:64
PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
Definition: PackedVersion.h:34
constexpr PackedVersion(uint32_t RawVersion)
Definition: PackedVersion.h:33
PackedVersion(VersionTuple VT)
Definition: PackedVersion.h:37
uint32_t rawValue() const
Definition: PackedVersion.h:66
unsigned getSubminor() const
Retrieve the subminor version number, if provided.
Definition: PackedVersion.h:55
unsigned getMajor() const
Retrieve the major version number.
Definition: PackedVersion.h:49
bool operator<(const PackedVersion &O) const
Definition: PackedVersion.h:60
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:30
unsigned getMajor() const
Retrieve the major version number.
Definition: VersionTuple.h:72
std::optional< unsigned > getSubminor() const
Retrieve the subminor version number, if provided.
Definition: VersionTuple.h:82
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
Definition: VersionTuple.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18