]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/DebugInfo/CodeView/Formatters.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r304460, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / DebugInfo / CodeView / Formatters.cpp
1 //===- Formatters.cpp -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/DebugInfo/CodeView/Formatters.h"
11
12 using namespace llvm;
13 using namespace llvm::codeview;
14 using namespace llvm::codeview::detail;
15
16 GuidAdapter::GuidAdapter(StringRef Guid)
17     : FormatAdapter(makeArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {}
18
19 GuidAdapter::GuidAdapter(ArrayRef<uint8_t> Guid)
20     : FormatAdapter(std::move(Guid)) {}
21
22 void GuidAdapter::format(llvm::raw_ostream &Stream, StringRef Style) {
23   static const char *Lookup = "0123456789ABCDEF";
24
25   assert(Item.size() == 16 && "Expected 16-byte GUID");
26   Stream << "{";
27   for (int i = 0; i < 16;) {
28     uint8_t Byte = Item[i];
29     uint8_t HighNibble = (Byte >> 4) & 0xF;
30     uint8_t LowNibble = Byte & 0xF;
31     Stream << Lookup[HighNibble] << Lookup[LowNibble];
32     ++i;
33     if (i >= 4 && i <= 10 && i % 2 == 0)
34       Stream << "-";
35   }
36   Stream << "}";
37 }