LLVM  12.0.0git
PackedVersion.h
Go to the documentation of this file.
1 //===- 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 
16 #include <cstdint>
17 #include <utility>
18 
19 namespace llvm {
20 class raw_ostream;
21 class StringRef;
22 
23 namespace MachO {
24 
26  uint32_t Version{0};
27 
28 public:
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 
59 inline 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
This class represents lattice values for constants.
Definition: AllocatorList.h:23
uint32_t rawValue() const
Definition: PackedVersion.h:54
constexpr PackedVersion()=default
bool parse32(StringRef Str)
void print(raw_ostream &OS) const
bool operator<(const PackedVersion &O) const
Definition: PackedVersion.h:48
unsigned getMajor() const
Retrieve the major version number.
Definition: PackedVersion.h:37
PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
Definition: PackedVersion.h:31
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
std::pair< bool, bool > parse64(StringRef Str)
bool operator!=(const PackedVersion &O) const
Definition: PackedVersion.h:52
bool operator==(const PackedVersion &O) const
Definition: PackedVersion.h:50
unsigned getMinor() const
Retrieve the minor version number, if provided.
Definition: PackedVersion.h:40
unsigned getSubminor() const
Retrieve the subminor version number, if provided.
Definition: PackedVersion.h:43
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
constexpr PackedVersion(uint32_t RawVersion)
Definition: PackedVersion.h:30