LLVM 20.0.0git
Formatters.cpp
Go to the documentation of this file.
1//===- Formatters.cpp -----------------------------------------------------===//
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
10#include "llvm/ADT/ArrayRef.h"
12#include "llvm/Support/Endian.h"
14#include "llvm/Support/Format.h"
16#include <cassert>
17
18using namespace llvm;
19using namespace llvm::codeview;
20using namespace llvm::codeview::detail;
21
23 : FormatAdapter(ArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {}
24
27
28// From https://docs.microsoft.com/en-us/windows/win32/msi/guid documentation:
29// The GUID data type is a text string representing a Class identifier (ID).
30// All GUIDs must be authored in uppercase.
31// The valid format for a GUID is {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} where
32// X is a hex digit (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F).
33//
34// The individual string components must be padded to comply with the specific
35// lengths of {8-4-4-4-12} characters.
36// The llvm-yaml2obj tool checks that a GUID follow that format:
37// - the total length to be 38 (including the curly braces.
38// - there is a dash at the positions: 8, 13, 18 and 23.
40 assert(Item.size() == 16 && "Expected 16-byte GUID");
41 struct MSGuid {
46 };
47 const MSGuid *G = reinterpret_cast<const MSGuid *>(Item.data());
48 Stream
49 << '{' << format_hex_no_prefix(G->Data1, 8, /*Upper=*/true)
50 << '-' << format_hex_no_prefix(G->Data2, 4, /*Upper=*/true)
51 << '-' << format_hex_no_prefix(G->Data3, 4, /*Upper=*/true)
52 << '-' << format_hex_no_prefix(G->Data4 >> 48, 4, /*Upper=*/true) << '-'
53 << format_hex_no_prefix(G->Data4 & ((1ULL << 48) - 1), 12, /*Upper=*/true)
54 << '}';
55}
56
59 A.format(OS, "");
60 return OS;
61}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define G(x, y, z)
Definition: MD5.cpp:56
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
const T * data() const
Definition: ArrayRef.h:162
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
GuidAdapter(ArrayRef< uint8_t > Guid)
Definition: Formatters.cpp:25
void format(raw_ostream &Stream, StringRef Style) override
Definition: Formatters.cpp:39
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, const GUID &Guid)
Definition: Formatters.cpp:57
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
Definition: Format.h:200
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
This represents the 'GUID' type from windows.h.
Definition: GUID.h:21