1 //===- FormatUtil.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 "FormatUtil.h" 11 #include "llvm/Support/Format.h" 12 #include "llvm/Support/FormatVariadic.h" 13 14 using namespace lldb_private; 15 using namespace llvm; 16 17 LinePrinter::Line::~Line() { 18 if (P) 19 P->NewLine(); 20 } 21 22 LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream) 23 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {} 24 25 void LinePrinter::Indent(uint32_t Amount) { 26 if (Amount == 0) 27 Amount = IndentSpaces; 28 CurrentIndent += Amount; 29 } 30 31 void LinePrinter::Unindent(uint32_t Amount) { 32 if (Amount == 0) 33 Amount = IndentSpaces; 34 CurrentIndent = std::max<int>(0, CurrentIndent - Amount); 35 } 36 37 void LinePrinter::NewLine() { 38 OS << "\n"; 39 } 40 41 void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data, 42 uint32_t StartOffset) { 43 if (Data.empty()) { 44 line() << Label << " ()"; 45 return; 46 } 47 line() << Label << " ("; 48 OS << format_bytes_with_ascii(Data, StartOffset, 32, 4, 49 CurrentIndent + IndentSpaces, true); 50 NewLine(); 51 line() << ")"; 52 } 53 54 void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data, 55 uint64_t Base, uint32_t StartOffset) { 56 if (Data.empty()) { 57 line() << Label << " ()"; 58 return; 59 } 60 line() << Label << " ("; 61 Base += StartOffset; 62 OS << format_bytes_with_ascii(Data, Base, 32, 4, CurrentIndent + IndentSpaces, 63 true); 64 NewLine(); 65 line() << ")"; 66 } 67