Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / tools / lldb-test / FormatUtil.h
blob2b2266e8dfbd6b8d8104166199f00eee4d4317cd
1 //===- FormatUtil.h ------------------------------------------- *- 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 #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"
18 #include <list>
20 namespace lldb_private {
22 class LinePrinter {
23 llvm::raw_ostream &OS;
24 int IndentSpaces;
25 int CurrentIndent;
27 public:
28 class Line {
29 LinePrinter *P;
31 public:
32 Line(LinePrinter &P) : P(&P) { P.OS.indent(P.CurrentIndent); }
33 ~Line();
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);
45 void NewLine();
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; }
61 struct AutoIndent {
62 explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
63 : L(&L), Amount(Amount) {
64 L.Indent(Amount);
66 ~AutoIndent() {
67 if (L)
68 L->Unindent(Amount);
71 LinePrinter *L = nullptr;
72 uint32_t Amount = 0;
75 } // namespace lldb_private
77 #endif