xref: /netbsd-src/external/apache2/llvm/dist/llvm/lib/DebugInfo/CodeView/Formatters.cpp (revision 82d56013d7b633d116a93943de88e08335357a7c)
17330f729Sjoerg //===- Formatters.cpp -----------------------------------------------------===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg 
97330f729Sjoerg #include "llvm/DebugInfo/CodeView/Formatters.h"
107330f729Sjoerg #include "llvm/ADT/ArrayRef.h"
117330f729Sjoerg #include "llvm/DebugInfo/CodeView/GUID.h"
127330f729Sjoerg #include "llvm/Support/raw_ostream.h"
137330f729Sjoerg #include <algorithm>
147330f729Sjoerg #include <cassert>
157330f729Sjoerg 
167330f729Sjoerg using namespace llvm;
177330f729Sjoerg using namespace llvm::codeview;
187330f729Sjoerg using namespace llvm::codeview::detail;
197330f729Sjoerg 
GuidAdapter(StringRef Guid)207330f729Sjoerg GuidAdapter::GuidAdapter(StringRef Guid)
217330f729Sjoerg     : FormatAdapter(makeArrayRef(Guid.bytes_begin(), Guid.bytes_end())) {}
227330f729Sjoerg 
GuidAdapter(ArrayRef<uint8_t> Guid)237330f729Sjoerg GuidAdapter::GuidAdapter(ArrayRef<uint8_t> Guid)
247330f729Sjoerg     : FormatAdapter(std::move(Guid)) {}
257330f729Sjoerg 
format(raw_ostream & Stream,StringRef Style)267330f729Sjoerg void GuidAdapter::format(raw_ostream &Stream, StringRef Style) {
277330f729Sjoerg   assert(Item.size() == 16 && "Expected 16-byte GUID");
28*82d56013Sjoerg   struct MSGuid {
29*82d56013Sjoerg     support::ulittle32_t Data1;
30*82d56013Sjoerg     support::ulittle16_t Data2;
31*82d56013Sjoerg     support::ulittle16_t Data3;
32*82d56013Sjoerg     support::ubig64_t Data4;
33*82d56013Sjoerg   };
34*82d56013Sjoerg   const MSGuid *G = reinterpret_cast<const MSGuid *>(Item.data());
35*82d56013Sjoerg   Stream
36*82d56013Sjoerg       << '{' << format_hex_no_prefix(G->Data1, sizeof(G->Data1), /*Upper=*/true)
37*82d56013Sjoerg       << '-' << format_hex_no_prefix(G->Data2, sizeof(G->Data2), /*Upper=*/true)
38*82d56013Sjoerg       << '-' << format_hex_no_prefix(G->Data3, sizeof(G->Data3), /*Upper=*/true)
39*82d56013Sjoerg       << '-' << format_hex_no_prefix(G->Data4 >> 48, 2, /*Upper=*/true) << '-'
40*82d56013Sjoerg       << format_hex_no_prefix(G->Data4 & ((1ULL << 48) - 1), 6, /*Upper=*/true)
41*82d56013Sjoerg       << '}';
427330f729Sjoerg }
437330f729Sjoerg 
operator <<(raw_ostream & OS,const GUID & Guid)447330f729Sjoerg raw_ostream &llvm::codeview::operator<<(raw_ostream &OS, const GUID &Guid) {
457330f729Sjoerg   codeview::detail::GuidAdapter A(Guid.Guid);
467330f729Sjoerg   A.format(OS, "");
477330f729Sjoerg   return OS;
487330f729Sjoerg }
49