FIX: Fix test failure in offload/test/mapping/power_of_two_alignment.c
[llvm-project.git] / lldb / tools / lldb-test / FormatUtil.cpp
blob1e5e1ee08749b5a34e26bf499a065ab44e144475
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 //===----------------------------------------------------------------------===//
9 #include "FormatUtil.h"
10 #include "llvm/Support/Format.h"
11 #include "llvm/Support/FormatVariadic.h"
13 using namespace lldb_private;
14 using namespace llvm;
16 LinePrinter::Line::~Line() {
17 if (P)
18 P->NewLine();
21 LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
22 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {}
24 void LinePrinter::Indent(uint32_t Amount) {
25 if (Amount == 0)
26 Amount = IndentSpaces;
27 CurrentIndent += Amount;
30 void LinePrinter::Unindent(uint32_t Amount) {
31 if (Amount == 0)
32 Amount = IndentSpaces;
33 CurrentIndent = std::max<int>(0, CurrentIndent - Amount);
36 void LinePrinter::NewLine() {
37 OS << "\n";
40 void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
41 uint32_t StartOffset) {
42 if (Data.empty()) {
43 line() << Label << " ()";
44 return;
46 line() << Label << " (";
47 OS << format_bytes_with_ascii(Data, StartOffset, 32, 4,
48 CurrentIndent + IndentSpaces, true);
49 NewLine();
50 line() << ")";
53 void LinePrinter::formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
54 uint64_t Base, uint32_t StartOffset) {
55 if (Data.empty()) {
56 line() << Label << " ()";
57 return;
59 line() << Label << " (";
60 Base += StartOffset;
61 OS << format_bytes_with_ascii(Data, Base, 32, 4, CurrentIndent + IndentSpaces,
62 true);
63 NewLine();
64 line() << ")";