Coverage Report

Created: 2022-01-25 06:29

/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
592k
LinePrinter::Line::~Line() {
17
592k
  if (P)
18
592k
    P->NewLine();
19
592k
}
20
21
LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
22
57
    : 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
658k
void LinePrinter::NewLine() {
37
658k
  OS << "\n";
38
658k
}
39
40
void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
41
30
                               uint32_t StartOffset) {
42
30
  if (Data.empty()) {
43
1
    line() << Label << " ()";
44
1
    return;
45
1
  }
46
29
  line() << Label << " (";
47
29
  OS << format_bytes_with_ascii(Data, StartOffset, 32, 4,
48
29
                                CurrentIndent + IndentSpaces, true);
49
29
  NewLine();
50
29
  line() << ")";
51
29
}
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
}