LLVM  14.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"
13 #include <algorithm>
14 #include <cassert>
15 
16 using namespace llvm;
17 using namespace llvm::codeview;
18 using namespace llvm::codeview::detail;
19 
21  : FormatAdapter(makeArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {}
22 
24  : FormatAdapter(std::move(Guid)) {}
25 
26 // From https://docs.microsoft.com/en-us/windows/win32/msi/guid documentation:
27 // The GUID data type is a text string representing a Class identifier (ID).
28 // All GUIDs must be authored in uppercase.
29 // The valid format for a GUID is {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} where
30 // X is a hex digit (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F).
31 //
32 // The individual string components must be padded to comply with the specific
33 // lengths of {8-4-4-4-12} characters.
34 // The llvm-yaml2obj tool checks that a GUID follow that format:
35 // - the total length to be 38 (including the curly braces.
36 // - there is a dash at the positions: 8, 13, 18 and 23.
38  assert(Item.size() == 16 && "Expected 16-byte GUID");
39  struct MSGuid {
43  support::ubig64_t Data4;
44  };
45  const MSGuid *G = reinterpret_cast<const MSGuid *>(Item.data());
46  Stream
47  << '{' << format_hex_no_prefix(G->Data1, 8, /*Upper=*/true)
48  << '-' << format_hex_no_prefix(G->Data2, 4, /*Upper=*/true)
49  << '-' << format_hex_no_prefix(G->Data3, 4, /*Upper=*/true)
50  << '-' << format_hex_no_prefix(G->Data4 >> 48, 4, /*Upper=*/true) << '-'
51  << format_hex_no_prefix(G->Data4 & ((1ULL << 48) - 1), 12, /*Upper=*/true)
52  << '}';
53 }
54 
57  A.format(OS, "");
58  return OS;
59 }
llvm::codeview::detail::GuidAdapter::GuidAdapter
GuidAdapter(ArrayRef< uint8_t > Guid)
Definition: Formatters.cpp:23
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
GUID.h
llvm::FormatAdapter< ArrayRef< uint8_t > >::Item
ArrayRef< uint8_t > Item
Definition: FormatAdapters.h:23
llvm::support::detail::packed_endian_specific_integral
Definition: Endian.h:206
llvm::codeview::GUID
This represents the 'GUID' type from windows.h.
Definition: GUID.h:21
llvm::format_hex_no_prefix
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:199
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:162
Formatters.h
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
llvm::codeview::detail::GuidAdapter::format
void format(raw_ostream &Stream, StringRef Style) override
Definition: Formatters.cpp:37
ArrayRef.h
llvm::HexStyle::Style
Style
Definition: MCInstPrinter.h:32
llvm::codeview::detail
Definition: DebugSubsectionVisitor.h:68
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
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:1605
llvm::codeview::operator<<
raw_ostream & operator<<(raw_ostream &OS, const GUID &Guid)
Definition: Formatters.cpp:55
llvm::ArrayRef< uint8_t >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::codeview::detail::GuidAdapter
Definition: Formatters.h:27
llvm::FormatAdapter
Definition: FormatAdapters.h:19
std
Definition: BitVector.h:838
llvm::codeview::GUID::Guid
uint8_t Guid[16]
Definition: GUID.h:22
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
raw_ostream.h