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::LinePrinter(int Indent, llvm::raw_ostream &Stream) 18 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {} 19 20 void LinePrinter::Indent(uint32_t Amount) { 21 if (Amount == 0) 22 Amount = IndentSpaces; 23 CurrentIndent += Amount; 24 } 25 26 void LinePrinter::Unindent(uint32_t Amount) { 27 if (Amount == 0) 28 Amount = IndentSpaces; 29 CurrentIndent = std::max<int>(0, CurrentIndent - Amount); 30 } 31 32 void LinePrinter::NewLine() { 33 OS << "\n"; 34 OS.indent(CurrentIndent); 35 } 36 37 void LinePrinter::print(const Twine &T) { OS << T; } 38 39 void LinePrinter::printLine(const Twine &T) { 40 NewLine(); 41 OS << T; 42 } 43 44 void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data, 45 uint32_t StartOffset) { 46 NewLine(); 47 OS << Label << " ("; 48 if (!Data.empty()) { 49 OS << "\n"; 50 OS << format_bytes_with_ascii(Data, StartOffset, 32, 4, 51 CurrentIndent + IndentSpaces, true); 52 NewLine(); 53 } 54 OS << ")"; 55 } 56 57 void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data, 58 uint64_t Base, uint32_t StartOffset) { 59 NewLine(); 60 OS << Label << " ("; 61 if (!Data.empty()) { 62 OS << "\n"; 63 Base += StartOffset; 64 OS << format_bytes_with_ascii(Data, Base, 32, 4, 65 CurrentIndent + IndentSpaces, true); 66 NewLine(); 67 } 68 OS << ")"; 69 } 70