2017-07-01 01:06:03 +02:00
|
|
|
//===- Formatters.cpp -----------------------------------------------------===//
|
2017-02-03 22:22:27 +01:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/DebugInfo/CodeView/Formatters.h"
|
2017-07-01 01:06:03 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2017-07-18 01:59:44 +02:00
|
|
|
#include "llvm/DebugInfo/CodeView/GUID.h"
|
2017-07-01 01:06:03 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
2017-02-03 22:22:27 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::codeview;
|
|
|
|
using namespace llvm::codeview::detail;
|
|
|
|
|
|
|
|
GuidAdapter::GuidAdapter(StringRef Guid)
|
|
|
|
: FormatAdapter(makeArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {}
|
|
|
|
|
|
|
|
GuidAdapter::GuidAdapter(ArrayRef<uint8_t> Guid)
|
|
|
|
: FormatAdapter(std::move(Guid)) {}
|
|
|
|
|
2017-07-01 01:06:03 +02:00
|
|
|
void GuidAdapter::format(raw_ostream &Stream, StringRef Style) {
|
2017-02-03 22:22:27 +01:00
|
|
|
static const char *Lookup = "0123456789ABCDEF";
|
|
|
|
|
|
|
|
assert(Item.size() == 16 && "Expected 16-byte GUID");
|
|
|
|
Stream << "{";
|
|
|
|
for (int i = 0; i < 16;) {
|
|
|
|
uint8_t Byte = Item[i];
|
|
|
|
uint8_t HighNibble = (Byte >> 4) & 0xF;
|
|
|
|
uint8_t LowNibble = Byte & 0xF;
|
|
|
|
Stream << Lookup[HighNibble] << Lookup[LowNibble];
|
|
|
|
++i;
|
|
|
|
if (i >= 4 && i <= 10 && i % 2 == 0)
|
|
|
|
Stream << "-";
|
|
|
|
}
|
|
|
|
Stream << "}";
|
|
|
|
}
|
2017-07-18 01:59:44 +02:00
|
|
|
|
|
|
|
raw_ostream &llvm::codeview::operator<<(raw_ostream &OS, const GUID &Guid) {
|
|
|
|
codeview::detail::GuidAdapter A(Guid.Guid);
|
|
|
|
A.format(OS, "");
|
|
|
|
return OS;
|
|
|
|
}
|