1 //===- Formatters.h ---------------------------------------------*- 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 #ifndef LLVM_DEBUGINFO_CODEVIEW_FORMATTERS_H 11 #define LLVM_DEBUGINFO_CODEVIEW_FORMATTERS_H 12 13 #include "llvm/ADT/ArrayRef.h" 14 #include "llvm/ADT/StringRef.h" 15 #include "llvm/DebugInfo/CodeView/TypeIndex.h" 16 #include "llvm/Support/FormatAdapters.h" 17 #include "llvm/Support/FormatProviders.h" 18 #include "llvm/Support/FormatVariadic.h" 19 20 namespace llvm { 21 namespace codeview { 22 namespace detail { 23 class GuidAdapter final : public llvm::FormatAdapter<ArrayRef<uint8_t>> { 24 ArrayRef<uint8_t> Guid; 25 26 public: 27 explicit GuidAdapter(ArrayRef<uint8_t> Guid); 28 explicit GuidAdapter(StringRef Guid); 29 void format(llvm::raw_ostream &Stream, StringRef Style); 30 }; 31 } 32 33 inline detail::GuidAdapter fmt_guid(StringRef Item) { 34 return detail::GuidAdapter(Item); 35 } 36 37 inline detail::GuidAdapter fmt_guid(ArrayRef<uint8_t> Item) { 38 return detail::GuidAdapter(Item); 39 } 40 } 41 42 template <> struct format_provider<codeview::TypeIndex> { 43 public: 44 static void format(const codeview::TypeIndex &V, llvm::raw_ostream &Stream, 45 StringRef Style) { 46 if (V.isNoneType()) 47 Stream << "<no type>"; 48 else { 49 Stream << formatv("{0:X+4}", V.getIndex()); 50 if (V.isSimple()) 51 Stream << " (" << codeview::TypeIndex::simpleTypeName(V) << ")"; 52 } 53 } 54 }; 55 } 56 57 #endif 58