LLVM  10.0.0svn
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 "llvm/ADT/StringRef.h"
18 
19 namespace llvm {
20 namespace MachO {
21 
23  uint32_t Version{0};
24 
25 public:
26  constexpr PackedVersion() = default;
27  explicit constexpr PackedVersion(uint32_t RawVersion) : Version(RawVersion) {}
28  PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
29  : Version((Major << 16) | ((Minor & 0xff) << 8) | (Subminor & 0xff)) {}
30 
31  bool empty() const { return Version == 0; }
32 
33  /// Retrieve the major version number.
34  unsigned getMajor() const { return Version >> 16; }
35 
36  /// Retrieve the minor version number, if provided.
37  unsigned getMinor() const { return (Version >> 8) & 0xff; }
38 
39  /// Retrieve the subminor version number, if provided.
40  unsigned getSubminor() const { return Version & 0xff; }
41 
42  bool parse32(StringRef Str);
43  std::pair<bool, bool> parse64(StringRef Str);
44 
45  bool operator<(const PackedVersion &O) const { return Version < O.Version; }
46 
47  bool operator==(const PackedVersion &O) const { return Version == O.Version; }
48 
49  bool operator!=(const PackedVersion &O) const { return Version != O.Version; }
50 
51  uint32_t rawValue() const { return Version; }
52 
53  void print(raw_ostream &OS) const;
54 };
55 
56 inline raw_ostream &operator<<(raw_ostream &OS, const PackedVersion &Version) {
57  Version.print(OS);
58  return OS;
59 }
60 
61 } // end namespace MachO.
62 } // end namespace llvm.
63 
64 #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:51
constexpr PackedVersion()=default
bool parse32(StringRef Str)
void print(raw_ostream &OS) const
bool operator<(const PackedVersion &O) const
Definition: PackedVersion.h:45
unsigned getMajor() const
Retrieve the major version number.
Definition: PackedVersion.h:34
PackedVersion(unsigned Major, unsigned Minor, unsigned Subminor)
Definition: PackedVersion.h:28
raw_ostream & operator<<(raw_ostream &OS, Architecture Arch)
std::pair< bool, bool > parse64(StringRef Str)
bool operator!=(const PackedVersion &O) const
Definition: PackedVersion.h:49
bool operator==(const PackedVersion &O) const
Definition: PackedVersion.h:47
unsigned getMinor() const
Retrieve the minor version number, if provided.
Definition: PackedVersion.h:37
unsigned getSubminor() const
Retrieve the subminor version number, if provided.
Definition: PackedVersion.h:40
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
constexpr PackedVersion(uint32_t RawVersion)
Definition: PackedVersion.h:27