/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/tools/lldb-test/FormatUtil.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- FormatUtil.cpp ----------------------------------------- *- C++ --*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #include "FormatUtil.h" |
10 | | #include "llvm/Support/Format.h" |
11 | | #include "llvm/Support/FormatVariadic.h" |
12 | | |
13 | | using namespace lldb_private; |
14 | | using namespace llvm; |
15 | | |
16 | 593k | LinePrinter::Line::~Line() { |
17 | 593k | if (P) |
18 | 593k | P->NewLine(); |
19 | 593k | } |
20 | | |
21 | | LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream) |
22 | 69 | : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {} |
23 | | |
24 | 65.8k | void LinePrinter::Indent(uint32_t Amount) { |
25 | 65.8k | if (Amount == 0) |
26 | 0 | Amount = IndentSpaces; |
27 | 65.8k | CurrentIndent += Amount; |
28 | 65.8k | } |
29 | | |
30 | 65.8k | void LinePrinter::Unindent(uint32_t Amount) { |
31 | 65.8k | if (Amount == 0) |
32 | 0 | Amount = IndentSpaces; |
33 | 65.8k | CurrentIndent = std::max<int>(0, CurrentIndent - Amount); |
34 | 65.8k | } |
35 | | |
36 | 659k | void LinePrinter::NewLine() { |
37 | 659k | OS << "\n"; |
38 | 659k | } |
39 | | |
40 | | void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data, |
41 | 50 | uint32_t StartOffset) { |
42 | 50 | if (Data.empty()) { |
43 | 4 | line() << Label << " ()"; |
44 | 4 | return; |
45 | 4 | } |
46 | 46 | line() << Label << " ("; |
47 | 46 | OS << format_bytes_with_ascii(Data, StartOffset, 32, 4, |
48 | 46 | CurrentIndent + IndentSpaces, true); |
49 | 46 | NewLine(); |
50 | 46 | line() << ")"; |
51 | 46 | } |
52 | | |
53 | | void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data, |
54 | 0 | uint64_t Base, uint32_t StartOffset) { |
55 | 0 | if (Data.empty()) { |
56 | 0 | line() << Label << " ()"; |
57 | 0 | return; |
58 | 0 | } |
59 | 0 | line() << Label << " ("; |
60 | 0 | Base += StartOffset; |
61 | 0 | OS << format_bytes_with_ascii(Data, Base, 32, 4, CurrentIndent + IndentSpaces, |
62 | 0 | true); |
63 | 0 | NewLine(); |
64 | 0 | line() << ")"; |
65 | 0 | } |