blob: ef00bd8570fa95d8a28a4a52de9253cd7ec57652 [file] [log] [blame]
Zachary Turner5ce0f4a2017-02-03 21:22:27 +00001//===- 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
12using namespace llvm;
13using namespace llvm::codeview;
14using namespace llvm::codeview::detail;
15
16GuidAdapter::GuidAdapter(StringRef Guid)
17 : FormatAdapter(makeArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {}
18
19GuidAdapter::GuidAdapter(ArrayRef<uint8_t> Guid)
20 : FormatAdapter(std::move(Guid)) {}
21
22void 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}