1 //===- Formatters.cpp -----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/Formatters.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/DebugInfo/CodeView/GUID.h"
12 #include "llvm/Support/raw_ostream.h"
17 using namespace llvm::codeview
;
18 using namespace llvm::codeview::detail
;
20 GuidAdapter::GuidAdapter(StringRef Guid
)
21 : FormatAdapter(makeArrayRef(Guid
.bytes_begin(), Guid
.bytes_end())) {}
23 GuidAdapter::GuidAdapter(ArrayRef
<uint8_t> Guid
)
24 : FormatAdapter(std::move(Guid
)) {}
26 void GuidAdapter::format(raw_ostream
&Stream
, StringRef Style
) {
27 static const char *Lookup
= "0123456789ABCDEF";
29 assert(Item
.size() == 16 && "Expected 16-byte GUID");
31 for (int i
= 0; i
< 16;) {
32 uint8_t Byte
= Item
[i
];
33 uint8_t HighNibble
= (Byte
>> 4) & 0xF;
34 uint8_t LowNibble
= Byte
& 0xF;
35 Stream
<< Lookup
[HighNibble
] << Lookup
[LowNibble
];
37 if (i
>= 4 && i
<= 10 && i
% 2 == 0)
43 raw_ostream
&llvm::codeview::operator<<(raw_ostream
&OS
, const GUID
&Guid
) {
44 codeview::detail::GuidAdapter
A(Guid
.Guid
);