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