LLVM 17.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
16#include <cstdint>
17#include <string>
18#include <utility>
19
20namespace llvm {
21class raw_ostream;
22class StringRef;
23
24namespace MachO {
25
27 uint32_t Version{0};
28
29public:
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
63 Version.print(OS);
64 return OS;
65}
66
67} // end namespace MachO.
68} // end namespace llvm.
69
70#endif // LLVM_TEXTAPI_PACKEDVERSION_H
raw_pwrite_stream & OS
bool operator==(const PackedVersion &O) const
Definition: PackedVersion.h:51
void print(raw_ostream &OS) const
unsigned getMinor() const
Retrieve the minor version number, if provided.
Definition: PackedVersion.h:41
bool parse32(StringRef Str)
constexpr PackedVersion()=default
std::pair< bool, bool > parse64(StringRef Str)
bool operator!=(const PackedVersion &O) const
Definition: PackedVersion.h:53
PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
Definition: PackedVersion.h:32
constexpr PackedVersion(uint32_t RawVersion)
Definition: PackedVersion.h:31
uint32_t rawValue() const
Definition: PackedVersion.h:55
unsigned getSubminor() const
Retrieve the subminor version number, if provided.
Definition: PackedVersion.h:44
unsigned getMajor() const
Retrieve the major version number.
Definition: PackedVersion.h:38
bool operator<(const PackedVersion &O) const
Definition: PackedVersion.h:49
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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