Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Support/ScopedPrinter.h
Line
Count
Source (jump to first uncovered line)
1
//===-- ScopedPrinter.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
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_SUPPORT_SCOPEDPRINTER_H
10
#define LLVM_SUPPORT_SCOPEDPRINTER_H
11
12
#include "llvm/ADT/APSInt.h"
13
#include "llvm/ADT/ArrayRef.h"
14
#include "llvm/ADT/SmallVector.h"
15
#include "llvm/ADT/StringRef.h"
16
#include "llvm/Support/DataTypes.h"
17
#include "llvm/Support/Endian.h"
18
#include "llvm/Support/raw_ostream.h"
19
#include <algorithm>
20
21
namespace llvm {
22
23
template <typename T> struct EnumEntry {
24
  StringRef Name;
25
  // While Name suffices in most of the cases, in certain cases
26
  // GNU style and LLVM style of ELFDumper do not
27
  // display same string for same enum. The AltName if initialized appropriately
28
  // will hold the string that GNU style emits.
29
  // Example:
30
  // "EM_X86_64" string on LLVM style for Elf_Ehdr->e_machine corresponds to
31
  // "Advanced Micro Devices X86-64" on GNU style
32
  StringRef AltName;
33
  T Value;
34
2.00M
  EnumEntry(StringRef N, StringRef A, T V) : Name(N), AltName(A), Value(V) {}
35
142M
  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
llvm::EnumEntry<unsigned int>::EnumEntry(llvm::StringRef, unsigned int)
Line
Count
Source
35
15.1M
  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
llvm::EnumEntry<llvm::codeview::SymbolKind>::EnumEntry(llvm::StringRef, llvm::codeview::SymbolKind)
Line
Count
Source
35
21.2M
  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
llvm::EnumEntry<llvm::codeview::TypeLeafKind>::EnumEntry(llvm::StringRef, llvm::codeview::TypeLeafKind)
Line
Count
Source
35
36.7M
  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
llvm::EnumEntry<unsigned short>::EnumEntry(llvm::StringRef, unsigned short)
Line
Count
Source
35
55.8M
  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
llvm::EnumEntry<unsigned char>::EnumEntry(llvm::StringRef, unsigned char)
Line
Count
Source
35
7.30M
  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
llvm::EnumEntry<llvm::codeview::SourceLanguage>::EnumEntry(llvm::StringRef, llvm::codeview::SourceLanguage)
Line
Count
Source
35
2.05M
  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
llvm::EnumEntry<llvm::COFF::SectionCharacteristics>::EnumEntry(llvm::StringRef, llvm::COFF::SectionCharacteristics)
Line
Count
Source
35
4.04M
  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
36
};
37
38
struct HexNumber {
39
  // To avoid sign-extension we have to explicitly cast to the appropriate
40
  // unsigned type. The overloads are here so that every type that is implicitly
41
  // convertible to an integer (including enums and endian helpers) can be used
42
  // without requiring type traits or call-site changes.
43
0
  HexNumber(char Value) : Value(static_cast<unsigned char>(Value)) {}
44
0
  HexNumber(signed char Value) : Value(static_cast<unsigned char>(Value)) {}
45
0
  HexNumber(signed short Value) : Value(static_cast<unsigned short>(Value)) {}
46
1.75k
  HexNumber(signed int Value) : Value(static_cast<unsigned int>(Value)) {}
47
  HexNumber(signed long Value) : Value(static_cast<unsigned long>(Value)) {}
48
  HexNumber(signed long long Value)
49
      : Value(static_cast<unsigned long long>(Value)) {}
50
293k
  HexNumber(unsigned char Value) : Value(Value) {}
51
10.3k
  HexNumber(unsigned short Value) : Value(Value) {}
52
891k
  HexNumber(unsigned int Value) : Value(Value) {}
53
  HexNumber(unsigned long Value) : Value(Value) {}
54
1.33M
  HexNumber(unsigned long long Value) : Value(Value) {}
55
  uint64_t Value;
56
};
57
58
raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value);
59
const std::string to_hexString(uint64_t Value, bool UpperCase = true);
60
61
218k
template <class T> const std::string to_string(const T &Value) {
62
218k
  std::string number;
63
218k
  llvm::raw_string_ostream stream(number);
64
218k
  stream << Value;
65
218k
  return stream.str();
66
218k
}
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const llvm::to_string<float>(float const&)
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const llvm::to_string<int>(int const&)
Line
Count
Source
61
66
template <class T> const std::string to_string(const T &Value) {
62
66
  std::string number;
63
66
  llvm::raw_string_ostream stream(number);
64
66
  stream << Value;
65
66
  return stream.str();
66
66
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const llvm::to_string<unsigned int>(unsigned int const&)
Line
Count
Source
61
17.3k
template <class T> const std::string to_string(const T &Value) {
62
17.3k
  std::string number;
63
17.3k
  llvm::raw_string_ostream stream(number);
64
17.3k
  stream << Value;
65
17.3k
  return stream.str();
66
17.3k
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const llvm::to_string<long long>(long long const&)
Line
Count
Source
61
133k
template <class T> const std::string to_string(const T &Value) {
62
133k
  std::string number;
63
133k
  llvm::raw_string_ostream stream(number);
64
133k
  stream << Value;
65
133k
  return stream.str();
66
133k
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const llvm::to_string<unsigned long>(unsigned long const&)
Line
Count
Source
61
67.7k
template <class T> const std::string to_string(const T &Value) {
62
67.7k
  std::string number;
63
67.7k
  llvm::raw_string_ostream stream(number);
64
67.7k
  stream << Value;
65
67.7k
  return stream.str();
66
67.7k
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const llvm::to_string<unsigned long long>(unsigned long long const&)
Line
Count
Source
61
16
template <class T> const std::string to_string(const T &Value) {
62
16
  std::string number;
63
16
  llvm::raw_string_ostream stream(number);
64
16
  stream << Value;
65
16
  return stream.str();
66
16
}
67
68
class ScopedPrinter {
69
public:
70
4.52k
  ScopedPrinter(raw_ostream &OS) : OS(OS), IndentLevel(0) {}
71
72
  void flush() { OS.flush(); }
73
74
583k
  void indent(int Levels = 1) { IndentLevel += Levels; }
75
76
583k
  void unindent(int Levels = 1) {
77
583k
    IndentLevel = std::max(0, IndentLevel - Levels);
78
583k
  }
79
80
0
  void resetIndent() { IndentLevel = 0; }
81
82
  int getIndentLevel() { return IndentLevel; }
83
84
110
  void setPrefix(StringRef P) { Prefix = P; }
85
86
7.42M
  void printIndent() {
87
7.42M
    OS << Prefix;
88
21.1M
    for (int i = 0; i < IndentLevel; 
++i13.7M
)
89
13.7M
      OS << "  ";
90
7.42M
  }
91
92
766k
  template <typename T> HexNumber hex(T Value) { return HexNumber(Value); }
llvm::HexNumber llvm::ScopedPrinter::hex<unsigned char>(unsigned char)
Line
Count
Source
92
293k
  template <typename T> HexNumber hex(T Value) { return HexNumber(Value); }
llvm::HexNumber llvm::ScopedPrinter::hex<unsigned int>(unsigned int)
Line
Count
Source
92
461k
  template <typename T> HexNumber hex(T Value) { return HexNumber(Value); }
llvm::HexNumber llvm::ScopedPrinter::hex<unsigned short>(unsigned short)
Line
Count
Source
92
7.93k
  template <typename T> HexNumber hex(T Value) { return HexNumber(Value); }
llvm::HexNumber llvm::ScopedPrinter::hex<int>(int)
Line
Count
Source
92
47
  template <typename T> HexNumber hex(T Value) { return HexNumber(Value); }
llvm::HexNumber llvm::ScopedPrinter::hex<unsigned long long>(unsigned long long)
Line
Count
Source
92
3.42k
  template <typename T> HexNumber hex(T Value) { return HexNumber(Value); }
93
94
  template <typename T, typename TEnum>
95
  void printEnum(StringRef Label, T Value,
96
316k
                 ArrayRef<EnumEntry<TEnum>> EnumValues) {
97
316k
    StringRef Name;
98
316k
    bool Found = false;
99
1.06M
    for (const auto &EnumItem : EnumValues) {
100
1.06M
      if (EnumItem.Value == Value) {
101
316k
        Name = EnumItem.Name;
102
316k
        Found = true;
103
316k
        break;
104
316k
      }
105
1.06M
    }
106
316k
107
316k
    if (Found) {
108
316k
      startLine() << Label << ": " << Name << " (" << hex(Value) << ")\n";
109
316k
    } else {
110
8
      startLine() << Label << ": " << hex(Value) << "\n";
111
8
    }
112
316k
  }
void llvm::ScopedPrinter::printEnum<unsigned char, unsigned int>(llvm::StringRef, unsigned char, llvm::ArrayRef<llvm::EnumEntry<unsigned int> >)
Line
Count
Source
96
269k
                 ArrayRef<EnumEntry<TEnum>> EnumValues) {
97
269k
    StringRef Name;
98
269k
    bool Found = false;
99
276k
    for (const auto &EnumItem : EnumValues) {
100
276k
      if (EnumItem.Value == Value) {
101
269k
        Name = EnumItem.Name;
102
269k
        Found = true;
103
269k
        break;
104
269k
      }
105
276k
    }
106
269k
107
269k
    if (Found) {
108
269k
      startLine() << Label << ": " << Name << " (" << hex(Value) << ")\n";
109
269k
    } else {
110
8
      startLine() << Label << ": " << hex(Value) << "\n";
111
8
    }
112
269k
  }
void llvm::ScopedPrinter::printEnum<unsigned int, llvm::codeview::TypeLeafKind>(llvm::StringRef, unsigned int, llvm::ArrayRef<llvm::EnumEntry<llvm::codeview::TypeLeafKind> >)
Line
Count
Source
96
25.2k
                 ArrayRef<EnumEntry<TEnum>> EnumValues) {
97
25.2k
    StringRef Name;
98
25.2k
    bool Found = false;
99
623k
    for (const auto &EnumItem : EnumValues) {
100
623k
      if (EnumItem.Value == Value) {
101
25.2k
        Name = EnumItem.Name;
102
25.2k
        Found = true;
103
25.2k
        break;
104
25.2k
      }
105
623k
    }
106
25.2k
107
25.2k
    if (Found) {
108
25.2k
      startLine() << Label << ": " << Name << " (" << hex(Value) << ")\n";
109
25.2k
    } else {
110
0
      startLine() << Label << ": " << hex(Value) << "\n";
111
0
    }
112
25.2k
  }
void llvm::ScopedPrinter::printEnum<unsigned char, unsigned char>(llvm::StringRef, unsigned char, llvm::ArrayRef<llvm::EnumEntry<unsigned char> >)
Line
Count
Source
96
19.8k
                 ArrayRef<EnumEntry<TEnum>> EnumValues) {
97
19.8k
    StringRef Name;
98
19.8k
    bool Found = false;
99
77.6k
    for (const auto &EnumItem : EnumValues) {
100
77.6k
      if (EnumItem.Value == Value) {
101
19.8k
        Name = EnumItem.Name;
102
19.8k
        Found = true;
103
19.8k
        break;
104
19.8k
      }
105
77.6k
    }
106
19.8k
107
19.8k
    if (Found) {
108
19.8k
      startLine() << Label << ": " << Name << " (" << hex(Value) << ")\n";
109
19.8k
    } else {
110
0
      startLine() << Label << ": " << hex(Value) << "\n";
111
0
    }
112
19.8k
  }
void llvm::ScopedPrinter::printEnum<unsigned int, unsigned char>(llvm::StringRef, unsigned int, llvm::ArrayRef<llvm::EnumEntry<unsigned char> >)
Line
Count
Source
96
1.53k
                 ArrayRef<EnumEntry<TEnum>> EnumValues) {
97
1.53k
    StringRef Name;
98
1.53k
    bool Found = false;
99
10.7k
    for (const auto &EnumItem : EnumValues) {
100
10.7k
      if (EnumItem.Value == Value) {
101
1.53k
        Name = EnumItem.Name;
102
1.53k
        Found = true;
103
1.53k
        break;
104
1.53k
      }
105
10.7k
    }
106
1.53k
107
1.53k
    if (Found) {
108
1.53k
      startLine() << Label << ": " << Name << " (" << hex(Value) << ")\n";
109
1.53k
    } else {
110
0
      startLine() << Label << ": " << hex(Value) << "\n";
111
0
    }
112
1.53k
  }
void llvm::ScopedPrinter::printEnum<unsigned short, unsigned short>(llvm::StringRef, unsigned short, llvm::ArrayRef<llvm::EnumEntry<unsigned short> >)
Line
Count
Source
96
677
                 ArrayRef<EnumEntry<TEnum>> EnumValues) {
97
677
    StringRef Name;
98
677
    bool Found = false;
99
71.9k
    for (const auto &EnumItem : EnumValues) {
100
71.9k
      if (EnumItem.Value == Value) {
101
677
        Name = EnumItem.Name;
102
677
        Found = true;
103
677
        break;
104
677
      }
105
71.9k
    }
106
677
107
677
    if (Found) {
108
677
      startLine() << Label << ": " << Name << " (" << hex(Value) << ")\n";
109
677
    } else {
110
0
      startLine() << Label << ": " << hex(Value) << "\n";
111
0
    }
112
677
  }
void llvm::ScopedPrinter::printEnum<unsigned int, unsigned short>(llvm::StringRef, unsigned int, llvm::ArrayRef<llvm::EnumEntry<unsigned short> >)
Line
Count
Source
96
86
                 ArrayRef<EnumEntry<TEnum>> EnumValues) {
97
86
    StringRef Name;
98
86
    bool Found = false;
99
327
    for (const auto &EnumItem : EnumValues) {
100
327
      if (EnumItem.Value == Value) {
101
86
        Name = EnumItem.Name;
102
86
        Found = true;
103
86
        break;
104
86
      }
105
327
    }
106
86
107
86
    if (Found) {
108
86
      startLine() << Label << ": " << Name << " (" << hex(Value) << ")\n";
109
86
    } else {
110
0
      startLine() << Label << ": " << hex(Value) << "\n";
111
0
    }
112
86
  }
Unexecuted instantiation: void llvm::ScopedPrinter::printEnum<unsigned short, llvm::codeview::TypeLeafKind>(llvm::StringRef, unsigned short, llvm::ArrayRef<llvm::EnumEntry<llvm::codeview::TypeLeafKind> >)
113
114
  template <typename T, typename TFlag>
115
  void printFlags(StringRef Label, T Value, ArrayRef<EnumEntry<TFlag>> Flags,
116
                  TFlag EnumMask1 = {}, TFlag EnumMask2 = {},
117
2.81k
                  TFlag EnumMask3 = {}) {
118
2.81k
    typedef EnumEntry<TFlag> FlagEntry;
119
2.81k
    typedef SmallVector<FlagEntry, 10> FlagVector;
120
2.81k
    FlagVector SetFlags;
121
2.81k
122
22.9k
    for (const auto &Flag : Flags) {
123
22.9k
      if (Flag.Value == 0)
124
0
        continue;
125
22.9k
126
22.9k
      TFlag EnumMask{};
127
22.9k
      if (Flag.Value & EnumMask1)
128
0
        EnumMask = EnumMask1;
129
22.9k
      else if (Flag.Value & EnumMask2)
130
0
        EnumMask = EnumMask2;
131
22.9k
      else if (Flag.Value & EnumMask3)
132
0
        EnumMask = EnumMask3;
133
22.9k
      bool IsEnum = (Flag.Value & EnumMask) != 0;
134
22.9k
      if ((!IsEnum && (Value & Flag.Value) == Flag.Value) ||
135
22.9k
          
(20.1k
IsEnum20.1k
&&
(Value & EnumMask) == Flag.Value0
)) {
136
2.82k
        SetFlags.push_back(Flag);
137
2.82k
      }
138
22.9k
    }
139
2.81k
140
2.81k
    llvm::sort(SetFlags, &flagName<TFlag>);
141
2.81k
142
2.81k
    startLine() << Label << " [ (" << hex(Value) << ")\n";
143
2.82k
    for (const auto &Flag : SetFlags) {
144
2.82k
      startLine() << "  " << Flag.Name << " (" << hex(Flag.Value) << ")\n";
145
2.82k
    }
146
2.81k
    startLine() << "]\n";
147
2.81k
  }
void llvm::ScopedPrinter::printFlags<unsigned short, unsigned short>(llvm::StringRef, unsigned short, llvm::ArrayRef<llvm::EnumEntry<unsigned short> >, unsigned short, unsigned short, unsigned short)
Line
Count
Source
117
1.58k
                  TFlag EnumMask3 = {}) {
118
1.58k
    typedef EnumEntry<TFlag> FlagEntry;
119
1.58k
    typedef SmallVector<FlagEntry, 10> FlagVector;
120
1.58k
    FlagVector SetFlags;
121
1.58k
122
17.7k
    for (const auto &Flag : Flags) {
123
17.7k
      if (Flag.Value == 0)
124
0
        continue;
125
17.7k
126
17.7k
      TFlag EnumMask{};
127
17.7k
      if (Flag.Value & EnumMask1)
128
0
        EnumMask = EnumMask1;
129
17.7k
      else if (Flag.Value & EnumMask2)
130
0
        EnumMask = EnumMask2;
131
17.7k
      else if (Flag.Value & EnumMask3)
132
0
        EnumMask = EnumMask3;
133
17.7k
      bool IsEnum = (Flag.Value & EnumMask) != 0;
134
17.7k
      if ((!IsEnum && (Value & Flag.Value) == Flag.Value) ||
135
17.7k
          
(15.3k
IsEnum15.3k
&&
(Value & EnumMask) == Flag.Value0
)) {
136
2.39k
        SetFlags.push_back(Flag);
137
2.39k
      }
138
17.7k
    }
139
1.58k
140
1.58k
    llvm::sort(SetFlags, &flagName<TFlag>);
141
1.58k
142
1.58k
    startLine() << Label << " [ (" << hex(Value) << ")\n";
143
2.39k
    for (const auto &Flag : SetFlags) {
144
2.39k
      startLine() << "  " << Flag.Name << " (" << hex(Flag.Value) << ")\n";
145
2.39k
    }
146
1.58k
    startLine() << "]\n";
147
1.58k
  }
void llvm::ScopedPrinter::printFlags<unsigned char, unsigned char>(llvm::StringRef, unsigned char, llvm::ArrayRef<llvm::EnumEntry<unsigned char> >, unsigned char, unsigned char, unsigned char)
Line
Count
Source
117
1.18k
                  TFlag EnumMask3 = {}) {
118
1.18k
    typedef EnumEntry<TFlag> FlagEntry;
119
1.18k
    typedef SmallVector<FlagEntry, 10> FlagVector;
120
1.18k
    FlagVector SetFlags;
121
1.18k
122
5.02k
    for (const auto &Flag : Flags) {
123
5.02k
      if (Flag.Value == 0)
124
0
        continue;
125
5.02k
126
5.02k
      TFlag EnumMask{};
127
5.02k
      if (Flag.Value & EnumMask1)
128
0
        EnumMask = EnumMask1;
129
5.02k
      else if (Flag.Value & EnumMask2)
130
0
        EnumMask = EnumMask2;
131
5.02k
      else if (Flag.Value & EnumMask3)
132
0
        EnumMask = EnumMask3;
133
5.02k
      bool IsEnum = (Flag.Value & EnumMask) != 0;
134
5.02k
      if ((!IsEnum && (Value & Flag.Value) == Flag.Value) ||
135
5.02k
          
(4.64k
IsEnum4.64k
&&
(Value & EnumMask) == Flag.Value0
)) {
136
388
        SetFlags.push_back(Flag);
137
388
      }
138
5.02k
    }
139
1.18k
140
1.18k
    llvm::sort(SetFlags, &flagName<TFlag>);
141
1.18k
142
1.18k
    startLine() << Label << " [ (" << hex(Value) << ")\n";
143
1.18k
    for (const auto &Flag : SetFlags) {
144
388
      startLine() << "  " << Flag.Name << " (" << hex(Flag.Value) << ")\n";
145
388
    }
146
1.18k
    startLine() << "]\n";
147
1.18k
  }
void llvm::ScopedPrinter::printFlags<unsigned int, unsigned short>(llvm::StringRef, unsigned int, llvm::ArrayRef<llvm::EnumEntry<unsigned short> >, unsigned short, unsigned short, unsigned short)
Line
Count
Source
117
45
                  TFlag EnumMask3 = {}) {
118
45
    typedef EnumEntry<TFlag> FlagEntry;
119
45
    typedef SmallVector<FlagEntry, 10> FlagVector;
120
45
    FlagVector SetFlags;
121
45
122
225
    for (const auto &Flag : Flags) {
123
225
      if (Flag.Value == 0)
124
0
        continue;
125
225
126
225
      TFlag EnumMask{};
127
225
      if (Flag.Value & EnumMask1)
128
0
        EnumMask = EnumMask1;
129
225
      else if (Flag.Value & EnumMask2)
130
0
        EnumMask = EnumMask2;
131
225
      else if (Flag.Value & EnumMask3)
132
0
        EnumMask = EnumMask3;
133
225
      bool IsEnum = (Flag.Value & EnumMask) != 0;
134
225
      if ((!IsEnum && (Value & Flag.Value) == Flag.Value) ||
135
225
          
(180
IsEnum180
&&
(Value & EnumMask) == Flag.Value0
)) {
136
45
        SetFlags.push_back(Flag);
137
45
      }
138
225
    }
139
45
140
45
    llvm::sort(SetFlags, &flagName<TFlag>);
141
45
142
45
    startLine() << Label << " [ (" << hex(Value) << ")\n";
143
45
    for (const auto &Flag : SetFlags) {
144
45
      startLine() << "  " << Flag.Name << " (" << hex(Flag.Value) << ")\n";
145
45
    }
146
45
    startLine() << "]\n";
147
45
  }
148
149
  template <typename T> void printFlags(StringRef Label, T Value) {
150
    startLine() << Label << " [ (" << hex(Value) << ")\n";
151
    uint64_t Flag = 1;
152
    uint64_t Curr = Value;
153
    while (Curr > 0) {
154
      if (Curr & 1)
155
        startLine() << "  " << hex(Flag) << "\n";
156
      Curr >>= 1;
157
      Flag <<= 1;
158
    }
159
    startLine() << "]\n";
160
  }
161
162
1.32M
  void printNumber(StringRef Label, uint64_t Value) {
163
1.32M
    startLine() << Label << ": " << Value << "\n";
164
1.32M
  }
165
166
818k
  void printNumber(StringRef Label, uint32_t Value) {
167
818k
    startLine() << Label << ": " << Value << "\n";
168
818k
  }
169
170
11.5k
  void printNumber(StringRef Label, uint16_t Value) {
171
11.5k
    startLine() << Label << ": " << Value << "\n";
172
11.5k
  }
173
174
2.81k
  void printNumber(StringRef Label, uint8_t Value) {
175
2.81k
    startLine() << Label << ": " << unsigned(Value) << "\n";
176
2.81k
  }
177
178
  void printNumber(StringRef Label, int64_t Value) {
179
    startLine() << Label << ": " << Value << "\n";
180
  }
181
182
540k
  void printNumber(StringRef Label, int32_t Value) {
183
540k
    startLine() << Label << ": " << Value << "\n";
184
540k
  }
185
186
0
  void printNumber(StringRef Label, int16_t Value) {
187
0
    startLine() << Label << ": " << Value << "\n";
188
0
  }
189
190
0
  void printNumber(StringRef Label, int8_t Value) {
191
0
    startLine() << Label << ": " << int(Value) << "\n";
192
0
  }
193
194
17.5k
  void printNumber(StringRef Label, const APSInt &Value) {
195
17.5k
    startLine() << Label << ": " << Value << "\n";
196
17.5k
  }
197
198
  void printBoolean(StringRef Label, bool Value) {
199
    startLine() << Label << ": " << (Value ? "Yes" : "No") << '\n';
200
  }
201
202
  template <typename... T> void printVersion(StringRef Label, T... Version) {
203
    startLine() << Label << ": ";
204
    printVersionInternal(Version...);
205
    getOStream() << "\n";
206
  }
207
208
0
  template <typename T> void printList(StringRef Label, const T &List) {
209
0
    startLine() << Label << ": [";
210
0
    bool Comma = false;
211
0
    for (const auto &Item : List) {
212
0
      if (Comma)
213
0
        OS << ", ";
214
0
      OS << Item;
215
0
      Comma = true;
216
0
    }
217
0
    OS << "]\n";
218
0
  }
219
220
  template <typename T, typename U>
221
  void printList(StringRef Label, const T &List, const U &Printer) {
222
    startLine() << Label << ": [";
223
    bool Comma = false;
224
    for (const auto &Item : List) {
225
      if (Comma)
226
        OS << ", ";
227
      Printer(OS, Item);
228
      Comma = true;
229
    }
230
    OS << "]\n";
231
  }
232
233
  template <typename T> void printHexList(StringRef Label, const T &List) {
234
    startLine() << Label << ": [";
235
    bool Comma = false;
236
    for (const auto &Item : List) {
237
      if (Comma)
238
        OS << ", ";
239
      OS << hex(Item);
240
      Comma = true;
241
    }
242
    OS << "]\n";
243
  }
244
245
18.6k
  template <typename T> void printHex(StringRef Label, T Value) {
246
18.6k
    startLine() << Label << ": " << hex(Value) << "\n";
247
18.6k
  }
void llvm::ScopedPrinter::printHex<unsigned int>(llvm::StringRef, unsigned int)
Line
Count
Source
245
13.5k
  template <typename T> void printHex(StringRef Label, T Value) {
246
13.5k
    startLine() << Label << ": " << hex(Value) << "\n";
247
13.5k
  }
void llvm::ScopedPrinter::printHex<unsigned short>(llvm::StringRef, unsigned short)
Line
Count
Source
245
2.32k
  template <typename T> void printHex(StringRef Label, T Value) {
246
2.32k
    startLine() << Label << ": " << hex(Value) << "\n";
247
2.32k
  }
void llvm::ScopedPrinter::printHex<int>(llvm::StringRef, int)
Line
Count
Source
245
41
  template <typename T> void printHex(StringRef Label, T Value) {
246
41
    startLine() << Label << ": " << hex(Value) << "\n";
247
41
  }
void llvm::ScopedPrinter::printHex<unsigned long long>(llvm::StringRef, unsigned long long)
Line
Count
Source
245
2.76k
  template <typename T> void printHex(StringRef Label, T Value) {
246
2.76k
    startLine() << Label << ": " << hex(Value) << "\n";
247
2.76k
  }
248
249
144k
  template <typename T> void printHex(StringRef Label, StringRef Str, T Value) {
250
144k
    startLine() << Label << ": " << Str << " (" << hex(Value) << ")\n";
251
144k
  }
252
253
  template <typename T>
254
  void printSymbolOffset(StringRef Label, StringRef Symbol, T Value) {
255
    startLine() << Label << ": " << Symbol << '+' << hex(Value) << '\n';
256
  }
257
258
1.12k
  void printString(StringRef Value) { startLine() << Value << "\n"; }
259
260
46.1k
  void printString(StringRef Label, StringRef Value) {
261
46.1k
    startLine() << Label << ": " << Value << "\n";
262
46.1k
  }
263
264
11.4k
  void printString(StringRef Label, const std::string &Value) {
265
11.4k
    printString(Label, StringRef(Value));
266
11.4k
  }
267
268
  void printString(StringRef Label, const char* Value) {
269
    printString(Label, StringRef(Value));
270
  }
271
272
  template <typename T>
273
  void printNumber(StringRef Label, StringRef Str, T Value) {
274
    startLine() << Label << ": " << Str << " (" << Value << ")\n";
275
  }
276
277
0
  void printBinary(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value) {
278
0
    printBinaryImpl(Label, Str, Value, false);
279
0
  }
280
281
  void printBinary(StringRef Label, StringRef Str, ArrayRef<char> Value) {
282
    auto V = makeArrayRef(reinterpret_cast<const uint8_t *>(Value.data()),
283
                          Value.size());
284
    printBinaryImpl(Label, Str, V, false);
285
  }
286
287
  void printBinary(StringRef Label, ArrayRef<uint8_t> Value) {
288
    printBinaryImpl(Label, StringRef(), Value, false);
289
  }
290
291
0
  void printBinary(StringRef Label, ArrayRef<char> Value) {
292
0
    auto V = makeArrayRef(reinterpret_cast<const uint8_t *>(Value.data()),
293
0
                          Value.size());
294
0
    printBinaryImpl(Label, StringRef(), V, false);
295
0
  }
296
297
0
  void printBinary(StringRef Label, StringRef Value) {
298
0
    auto V = makeArrayRef(reinterpret_cast<const uint8_t *>(Value.data()),
299
0
                          Value.size());
300
0
    printBinaryImpl(Label, StringRef(), V, false);
301
0
  }
302
303
  void printBinaryBlock(StringRef Label, ArrayRef<uint8_t> Value,
304
0
                        uint32_t StartOffset) {
305
0
    printBinaryImpl(Label, StringRef(), Value, true, StartOffset);
306
0
  }
307
308
  void printBinaryBlock(StringRef Label, ArrayRef<uint8_t> Value) {
309
    printBinaryImpl(Label, StringRef(), Value, true);
310
  }
311
312
2.57k
  void printBinaryBlock(StringRef Label, StringRef Value) {
313
2.57k
    auto V = makeArrayRef(reinterpret_cast<const uint8_t *>(Value.data()),
314
2.57k
                          Value.size());
315
2.57k
    printBinaryImpl(Label, StringRef(), V, true);
316
2.57k
  }
317
318
  template <typename T> void printObject(StringRef Label, const T &Value) {
319
    startLine() << Label << ": " << Value << "\n";
320
  }
321
322
7.42M
  raw_ostream &startLine() {
323
7.42M
    printIndent();
324
7.42M
    return OS;
325
7.42M
  }
326
327
1.15M
  raw_ostream &getOStream() { return OS; }
328
329
private:
330
  template <typename T> void printVersionInternal(T Value) {
331
    getOStream() << Value;
332
  }
333
334
  template <typename S, typename T, typename... TArgs>
335
  void printVersionInternal(S Value, T Value2, TArgs... Args) {
336
    getOStream() << Value << ".";
337
    printVersionInternal(Value2, Args...);
338
  }
339
340
  template <typename T>
341
1.17k
  static bool flagName(const EnumEntry<T> &lhs, const EnumEntry<T> &rhs) {
342
1.17k
    return lhs.Name < rhs.Name;
343
1.17k
  }
bool llvm::ScopedPrinter::flagName<unsigned short>(llvm::EnumEntry<unsigned short> const&, llvm::EnumEntry<unsigned short> const&)
Line
Count
Source
341
1.16k
  static bool flagName(const EnumEntry<T> &lhs, const EnumEntry<T> &rhs) {
342
1.16k
    return lhs.Name < rhs.Name;
343
1.16k
  }
bool llvm::ScopedPrinter::flagName<unsigned char>(llvm::EnumEntry<unsigned char> const&, llvm::EnumEntry<unsigned char> const&)
Line
Count
Source
341
12
  static bool flagName(const EnumEntry<T> &lhs, const EnumEntry<T> &rhs) {
342
12
    return lhs.Name < rhs.Name;
343
12
  }
344
345
  void printBinaryImpl(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value,
346
                       bool Block, uint32_t StartOffset = 0);
347
348
  raw_ostream &OS;
349
  int IndentLevel;
350
  StringRef Prefix;
351
};
352
353
template <>
354
inline void
355
ScopedPrinter::printHex<support::ulittle16_t>(StringRef Label,
356
                                              support::ulittle16_t Value) {
357
  startLine() << Label << ": " << hex(Value) << "\n";
358
}
359
360
template<char Open, char Close>
361
struct DelimitedScope {
362
  explicit DelimitedScope(ScopedPrinter &W) : W(W) {
363
    W.startLine() << Open << '\n';
364
    W.indent();
365
  }
366
367
555k
  DelimitedScope(ScopedPrinter &W, StringRef N) : W(W) {
368
555k
    W.startLine() << N;
369
555k
    if (!N.empty())
370
555k
      W.getOStream() << ' ';
371
555k
    W.getOStream() << Open << '\n';
372
555k
    W.indent();
373
555k
  }
llvm::DelimitedScope<(char)123, (char)125>::DelimitedScope(llvm::ScopedPrinter&, llvm::StringRef)
Line
Count
Source
367
543k
  DelimitedScope(ScopedPrinter &W, StringRef N) : W(W) {
368
543k
    W.startLine() << N;
369
543k
    if (!N.empty())
370
543k
      W.getOStream() << ' ';
371
543k
    W.getOStream() << Open << '\n';
372
543k
    W.indent();
373
543k
  }
llvm::DelimitedScope<(char)91, (char)93>::DelimitedScope(llvm::ScopedPrinter&, llvm::StringRef)
Line
Count
Source
367
11.6k
  DelimitedScope(ScopedPrinter &W, StringRef N) : W(W) {
368
11.6k
    W.startLine() << N;
369
11.6k
    if (!N.empty())
370
11.6k
      W.getOStream() << ' ';
371
11.6k
    W.getOStream() << Open << '\n';
372
11.6k
    W.indent();
373
11.6k
  }
374
375
555k
  ~DelimitedScope() {
376
555k
    W.unindent();
377
555k
    W.startLine() << Close << '\n';
378
555k
  }
llvm::DelimitedScope<(char)123, (char)125>::~DelimitedScope()
Line
Count
Source
375
543k
  ~DelimitedScope() {
376
543k
    W.unindent();
377
543k
    W.startLine() << Close << '\n';
378
543k
  }
llvm::DelimitedScope<(char)91, (char)93>::~DelimitedScope()
Line
Count
Source
375
11.6k
  ~DelimitedScope() {
376
11.6k
    W.unindent();
377
11.6k
    W.startLine() << Close << '\n';
378
11.6k
  }
379
380
  ScopedPrinter &W;
381
};
382
383
using DictScope = DelimitedScope<'{', '}'>;
384
using ListScope = DelimitedScope<'[', ']'>;
385
386
} // namespace llvm
387
388
#endif