1 //===- FormatUtil.h ------------------------------------------- *- C++ --*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_TOOLS_LLDB_TEST_FORMATUTIL_H
10 #define LLDB_TOOLS_LLDB_TEST_FORMATUTIL_H
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/FormatVariadic.h"
16 #include "llvm/Support/raw_ostream.h"
20 namespace lldb_private
{
23 llvm::raw_ostream
&OS
;
32 Line(LinePrinter
&P
) : P(&P
) { P
.OS
.indent(P
.CurrentIndent
); }
35 Line(Line
&&RHS
) : P(RHS
.P
) { RHS
.P
= nullptr; }
36 void operator=(Line
&&) = delete;
38 operator llvm::raw_ostream
&() { return P
->OS
; }
41 LinePrinter(int Indent
, llvm::raw_ostream
&Stream
);
43 void Indent(uint32_t Amount
= 0);
44 void Unindent(uint32_t Amount
= 0);
47 void printLine(const llvm::Twine
&T
) { line() << T
; }
48 template <typename
... Ts
> void formatLine(const char *Fmt
, Ts
&&... Items
) {
49 printLine(llvm::formatv(Fmt
, std::forward
<Ts
>(Items
)...));
52 void formatBinary(llvm::StringRef Label
, llvm::ArrayRef
<uint8_t> Data
,
53 uint32_t StartOffset
);
54 void formatBinary(llvm::StringRef Label
, llvm::ArrayRef
<uint8_t> Data
,
55 uint64_t BaseAddr
, uint32_t StartOffset
);
57 Line
line() { return Line(*this); }
58 int getIndentLevel() const { return CurrentIndent
; }
62 explicit AutoIndent(LinePrinter
&L
, uint32_t Amount
= 0)
63 : L(&L
), Amount(Amount
) {
71 LinePrinter
*L
= nullptr;
75 } // namespace lldb_private