9#ifndef LLVM_SUPPORT_SCOPEDPRINTER_H
10#define LLVM_SUPPORT_SCOPEDPRINTER_H
45 template <
typename EnumT,
typename = std::enable_if_t<std::is_enum_v<EnumT>>>
70 template <
typename EnumT,
typename = std::enable_if_t<std::is_enum_v<EnumT>>>
96 : OS(OS), Kind(Kind) {}
108 void indent(
int Levels = 1) { IndentLevel += Levels; }
111 IndentLevel = IndentLevel > Levels ? IndentLevel - Levels : 0;
122 for (
int i = 0; i < IndentLevel; ++i)
128 template <
typename T,
typename TEnum,
unsigned NumStrs>
137 template <
typename T,
typename TFlag,
unsigned NumStrs>
139 TFlag EnumMask1 = {}, TFlag EnumMask2 = {},
140 TFlag EnumMask3 = {}, ArrayRef<FlagEntry> ExtraFlags = {}) {
141 SmallVector<FlagEntry, 10> SetFlags(ExtraFlags);
143 for (
const auto &Flag : Flags) {
144 if (
Flag.value() == TFlag{})
148 if ((
Flag.value() & EnumMask1) != TFlag{})
149 EnumMask = EnumMask1;
150 else if ((
Flag.value() & EnumMask2) != TFlag{})
151 EnumMask = EnumMask2;
152 else if ((
Flag.value() & EnumMask3) != TFlag{})
153 EnumMask = EnumMask3;
154 bool IsEnum = (
Flag.value() & EnumMask) != TFlag{};
156 (IsEnum && (
Value & EnumMask) ==
Flag.value())) {
157 SetFlags.emplace_back(
Flag.name(),
Flag.value());
162 printFlagsImpl(Label, hex(
Value), SetFlags);
165 template <
typename T>
169 printFlagsImpl(Label,
hex(
Value), SetFlags);
182 printFlagsImpl(Label,
hex(
Value), SetFlags);
194 startLine() << Label <<
": " <<
static_cast<unsigned>(
Value) <<
"\n";
241 template <
typename T>
250 template <
typename T,
typename... TArgs>
254 ((
getOStream() <<
'.' << MinorVersions), ...);
258 template <
typename T>
261 for (
const auto &Item :
List)
267 printListImpl(Label,
List);
271 printListImpl(Label,
List);
275 printListImpl(Label,
List);
279 printListImpl(Label,
List);
283 printListImpl(Label,
List);
290 printListImpl(Label, NumberList);
294 printListImpl(Label,
List);
298 printListImpl(Label,
List);
302 printListImpl(Label,
List);
307 for (
const int8_t &Item :
List)
309 printListImpl(Label, NumberList);
313 printListImpl(Label,
List);
316 template <
typename T,
typename U>
320 for (
const auto &Item :
List) {
329 for (
const auto &Item :
List)
331 printHexListImpl(Label, HexList);
339 printHexImpl(Label, Str,
hex(
Value));
342 template <
typename T>
344 printSymbolOffsetImpl(Label, Symbol,
hex(
Value));
354 printStringEscapedImpl(Label,
Value);
358 printBinaryImpl(Label, Str,
Value,
false);
364 printBinaryImpl(Label, Str, V,
false);
374 printBinaryImpl(Label,
StringRef(), V,
false);
380 printBinaryImpl(Label,
StringRef(), V,
false);
395 printBinaryImpl(Label,
StringRef(), V,
true);
423 return LHS.Name <
RHS.Name;
426 virtual void printBinaryImpl(StringRef Label, StringRef Str,
427 ArrayRef<uint8_t> Value,
bool Block,
430 virtual void printFlagsImpl(StringRef Label, HexNumber Value,
431 ArrayRef<FlagEntry> Flags) {
432 startLine() << Label <<
" [ (" << Value <<
")\n";
433 for (
const auto &Flag : Flags)
434 startLine() <<
" " << Flag.Name <<
" (" << hex(Flag.Value) <<
")\n";
435 startLine() <<
"]\n";
438 virtual void printFlagsImpl(StringRef Label, HexNumber
Value,
439 ArrayRef<HexNumber> Flags) {
440 startLine() <<
Label <<
" [ (" <<
Value <<
")\n";
441 for (
const auto &Flag : Flags)
442 startLine() <<
" " <<
Flag <<
'\n';
443 startLine() <<
"]\n";
446 template <
typename T>
void printListImpl(StringRef Label,
const T List) {
447 startLine() <<
Label <<
": [";
449 for (
const auto &Item : List)
454 virtual void printHexListImpl(StringRef Label,
455 const ArrayRef<HexNumber> List) {
456 startLine() <<
Label <<
": [";
458 for (
const auto &Item : List)
459 OS <<
LS << hex(Item);
463 virtual void printHexImpl(StringRef Label, HexNumber
Value) {
464 startLine() <<
Label <<
": " <<
Value <<
"\n";
467 virtual void printHexImpl(StringRef Label, StringRef Str, HexNumber
Value) {
468 startLine() <<
Label <<
": " << Str <<
" (" <<
Value <<
")\n";
471 virtual void printSymbolOffsetImpl(StringRef Label, StringRef Symbol,
476 virtual void printNumberImpl(StringRef Label, StringRef Str,
478 startLine() <<
Label <<
": " << Str <<
" (" <<
Value <<
")\n";
481 virtual void printStringEscapedImpl(StringRef Label, StringRef
Value) {
482 startLine() <<
Label <<
": ";
483 OS.write_escaped(
Value);
487 void scopedBegin(
char Symbol) {
488 startLine() <<
Symbol <<
'\n';
492 void scopedBegin(StringRef Label,
char Symbol) {
493 startLine() <<
Label;
500 void scopedEnd(
char Symbol) {
502 startLine() <<
Symbol <<
'\n';
508 ScopedPrinterKind
Kind;
515 startLine() << Label <<
": " << hex(
Value) <<
"\n";
533 enum class ScopeKind {
539 struct ScopeContext {
542 ScopeContext(Scope Context, ScopeKind Kind = ScopeKind::NoAttribute)
543 :
Context(Context), Kind(Kind) {}
548 std::unique_ptr<DelimitedScope> OuterScope;
552 std::unique_ptr<DelimitedScope> &&OuterScope =
553 std::unique_ptr<DelimitedScope>{});
560 JOS.attribute(Label,
Value);
564 JOS.attribute(Label,
Value);
568 JOS.attribute(Label,
Value);
572 JOS.attribute(Label,
Value);
576 JOS.attribute(Label,
Value);
580 JOS.attribute(Label,
Value);
584 JOS.attribute(Label,
Value);
588 JOS.attribute(Label,
Value);
592 JOS.attribute(Label,
Value);
596 JOS.attribute(Label,
Value);
600 JOS.attribute(Label,
Value);
604 JOS.attribute(Label,
Value);
608 JOS.attribute(Label,
Value);
612 JOS.attributeBegin(Label);
618 JOS.attribute(Label,
Value);
622 printListImpl(Label,
List);
626 printListImpl(Label,
List);
630 printListImpl(Label,
List);
634 printListImpl(Label,
List);
638 printListImpl(Label,
List);
642 printListImpl(Label,
List);
646 printListImpl(Label,
List);
650 printListImpl(Label,
List);
654 printListImpl(Label,
List);
658 printListImpl(Label,
List);
662 JOS.attributeArray(Label, [&]() {
672 JOS.attribute(Label,
Value);
676 scopedBegin({Scope::Object, ScopeKind::NoAttribute});
680 scopedBegin(Label, Scope::Object);
686 scopedBegin({Scope::Array, ScopeKind::NoAttribute});
690 scopedBegin(Label, Scope::Array);
699 void printAPSInt(
const APSInt &Value) {
704 void printFlagsImpl(StringRef Label, HexNumber
Value,
706 JOS.attributeObject(Label, [&]() {
707 JOS.attribute(
"Value", hexNumberToInt(
Value));
708 JOS.attributeArray(
"Flags", [&]() {
709 for (
const FlagEntry &Flag : Flags) {
711 JOS.attribute(
"Name",
Flag.Name);
712 JOS.attribute(
"Value",
Flag.Value);
719 void printFlagsImpl(StringRef Label, HexNumber
Value,
721 JOS.attributeObject(Label, [&]() {
722 JOS.attribute(
"Value", hexNumberToInt(
Value));
723 JOS.attributeArray(
"Flags", [&]() {
724 for (
const HexNumber &Flag : Flags) {
725 JOS.value(
Flag.Value);
731 template <
typename T>
void printListImpl(StringRef Label,
const T &
List) {
732 JOS.attributeArray(Label, [&]() {
733 for (
const auto &Item :
List)
738 void printHexListImpl(StringRef Label,
740 JOS.attributeArray(Label, [&]() {
741 for (
const HexNumber &Item :
List) {
742 JOS.value(hexNumberToInt(Item));
747 void printHexImpl(StringRef Label, HexNumber
Value)
override {
748 JOS.attribute(Label, hexNumberToInt(
Value));
751 void printHexImpl(StringRef Label, StringRef Str, HexNumber
Value)
override {
752 JOS.attributeObject(Label, [&]() {
753 JOS.attribute(
"Name", Str);
754 JOS.attribute(
"Value", hexNumberToInt(
Value));
758 void printSymbolOffsetImpl(StringRef Label, StringRef Symbol,
759 HexNumber
Value)
override {
760 JOS.attributeObject(Label, [&]() {
761 JOS.attribute(
"SymName", Symbol);
762 JOS.attribute(
"Offset", hexNumberToInt(
Value));
766 void printNumberImpl(StringRef Label, StringRef Str,
767 StringRef
Value)
override {
768 JOS.attributeObject(Label, [&]() {
769 JOS.attribute(
"Name", Str);
770 JOS.attributeBegin(
"Value");
771 JOS.rawValueBegin() <<
Value;
777 void printBinaryImpl(StringRef Label, StringRef Str, ArrayRef<uint8_t>
Value,
778 bool Block, uint32_t StartOffset = 0)
override {
779 JOS.attributeObject(Label, [&]() {
781 JOS.attribute(
"Value", Str);
782 JOS.attribute(
"Offset", StartOffset);
783 JOS.attributeArray(
"Bytes", [&]() {
784 for (uint8_t Val :
Value)
790 void scopedBegin(ScopeContext ScopeCtx) {
791 if (ScopeCtx.Context == Scope::Object)
793 else if (ScopeCtx.Context == Scope::Array)
795 ScopeHistory.push_back(ScopeCtx);
798 void scopedBegin(StringRef Label, Scope Ctx) {
799 ScopeKind Kind = ScopeKind::Attribute;
800 if (ScopeHistory.empty() || ScopeHistory.back().Context != Scope::Object) {
802 Kind = ScopeKind::NestedAttribute;
804 JOS.attributeBegin(Label);
805 scopedBegin({Ctx, Kind});
809 ScopeContext ScopeCtx = ScopeHistory.back();
810 if (ScopeCtx.Context == Scope::Object)
812 else if (ScopeCtx.Context == Scope::Array)
814 if (ScopeCtx.Kind == ScopeKind::Attribute ||
815 ScopeCtx.Kind == ScopeKind::NestedAttribute)
817 if (ScopeCtx.Kind == ScopeKind::NestedAttribute)
819 ScopeHistory.pop_back();
amdgpu next use AMDGPU Next Use Analysis Printer
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
static constexpr std::size_t number(BlockVerifier::State S)
This file supports working with JSON data.
This file contains library features backported from future STL versions.
This file defines the SmallVector class.
An arbitrary precision integer that knows its signedness.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef toString(TValue Value, unsigned StrIdx=0) const
void printNumber(StringRef Label, signed char Value) override
void printNumber(StringRef Label, double Value) override
void printList(StringRef Label, const ArrayRef< std::string > List) override
void printNumber(StringRef Label, float Value) override
void printNumber(StringRef Label, short Value) override
void printNumber(StringRef Label, long long Value) override
void printList(StringRef Label, const ArrayRef< uint8_t > List) override
void printList(StringRef Label, const ArrayRef< int32_t > List) override
void printNumber(StringRef Label, char Value) override
void printBoolean(StringRef Label, bool Value) override
void printNumber(StringRef Label, unsigned char Value) override
void printList(StringRef Label, const ArrayRef< int64_t > List) override
void printNumber(StringRef Label, int Value) override
LLVM_ABI JSONScopedPrinter(raw_ostream &OS, bool PrettyPrint=false, std::unique_ptr< DelimitedScope > &&OuterScope=std::unique_ptr< DelimitedScope >{})
void printList(StringRef Label, const ArrayRef< bool > List) override
void arrayBegin() override
void printList(StringRef Label, const ArrayRef< APSInt > List) override
void printList(StringRef Label, const ArrayRef< uint64_t > List) override
void printList(StringRef Label, const ArrayRef< uint16_t > List) override
void printNumber(StringRef Label, long Value) override
void printList(StringRef Label, const ArrayRef< int16_t > List) override
void objectEnd() override
static bool classof(const ScopedPrinter *SP)
void printNumber(StringRef Label, const APSInt &Value) override
void printList(StringRef Label, const ArrayRef< uint32_t > List) override
void printNumber(StringRef Label, unsigned int Value) override
void arrayBegin(StringRef Label) override
void printString(StringRef Value) override
void printNumber(StringRef Label, unsigned short Value) override
void objectBegin(StringRef Label) override
void printNumber(StringRef Label, unsigned long Value) override
void printString(StringRef Label, StringRef Value) override
void printList(StringRef Label, const ArrayRef< int8_t > List) override
void printNumber(StringRef Label, unsigned long long Value) override
void objectBegin() override
A helper class to return the specified delimiter string after the first invocation of operator String...
virtual void printList(StringRef Label, const ArrayRef< int32_t > List)
void printHexList(StringRef Label, const T &List)
virtual void printList(StringRef Label, const ArrayRef< uint32_t > List)
void printBinary(StringRef Label, StringRef Str, ArrayRef< char > Value)
virtual void printString(StringRef Value)
void printBinaryBlock(StringRef Label, ArrayRef< uint8_t > Value, uint32_t StartOffset)
void printStringEscaped(StringRef Label, StringRef Value)
void printBinaryBlock(StringRef Label, StringRef Value)
virtual void printNumber(StringRef Label, unsigned short Value)
virtual void printNumber(StringRef Label, long Value)
virtual void printList(StringRef Label, const ArrayRef< int64_t > List)
void printFlags(StringRef Label, T Value, SmallVectorImpl< FlagEntry > &SetFlags)
virtual void printNumber(StringRef Label, unsigned int Value)
void indent(int Levels=1)
virtual void printList(StringRef Label, const ArrayRef< int16_t > List)
virtual void printNumber(StringRef Label, long long Value)
void printFlags(StringRef Label, T Value)
virtual void printList(StringRef Label, const ArrayRef< std::string > List)
void unindent(int Levels=1)
void printBinaryBlock(StringRef Label, ArrayRef< uint8_t > Value)
virtual void arrayBegin(StringRef Label)
virtual void printList(StringRef Label, const ArrayRef< bool > List)
virtual void printList(StringRef Label, const ArrayRef< APSInt > List)
ScopedPrinterKind getKind() const
virtual void printNumber(StringRef Label, const APSInt &Value)
ScopedPrinter(raw_ostream &OS, ScopedPrinterKind Kind=ScopedPrinterKind::Base)
void printList(StringRef Label, const T &List, const U &Printer)
virtual void printNumber(StringRef Label, short Value)
void printBinary(StringRef Label, StringRef Value)
virtual raw_ostream & getOStream()
virtual void printList(StringRef Label, const ArrayRef< int8_t > List)
static bool classof(const ScopedPrinter *SP)
void printFlags(StringRef Label, T Value, EnumStrings< TFlag, NumStrs > Flags, TFlag EnumMask1={}, TFlag EnumMask2={}, TFlag EnumMask3={}, ArrayRef< FlagEntry > ExtraFlags={})
virtual void printNumber(StringRef Label, unsigned long Value)
virtual raw_ostream & startLine()
virtual void printNumber(StringRef Label, char Value)
virtual void printNumber(StringRef Label, int Value)
void printBinary(StringRef Label, StringRef Str, ArrayRef< uint8_t > Value)
virtual void printList(StringRef Label, const ArrayRef< uint64_t > List)
virtual void printNumber(StringRef Label, float Value)
void printHex(StringRef Label, T Value)
virtual void objectBegin(StringRef Label)
void setPrefix(StringRef P)
void printVersion(StringRef Label, T MajorVersion, TArgs... MinorVersions)
virtual ~ScopedPrinter()=default
void printEnum(StringRef Label, T Value, EnumStrings< TEnum, NumStrs > EnumValues)
virtual void arrayBegin()
virtual void printBoolean(StringRef Label, bool Value)
void printHex(StringRef Label, StringRef Str, T Value)
void printNumber(StringRef Label, StringRef Str, T Value)
virtual void objectBegin()
virtual void printNumber(StringRef Label, signed char Value)
virtual void printNumber(StringRef Label, unsigned char Value)
virtual void printNumber(StringRef Label, unsigned long long Value)
virtual void printList(StringRef Label, const ArrayRef< uint16_t > List)
virtual void printString(StringRef Label, StringRef Value)
virtual void printList(StringRef Label, const ArrayRef< uint8_t > List)
void printSymbolOffset(StringRef Label, StringRef Symbol, T Value)
virtual void printNumber(StringRef Label, double Value)
void printBinary(StringRef Label, ArrayRef< char > Value)
void printList(StringRef Label, const ArrayRef< T > List)
void printBinary(StringRef Label, ArrayRef< uint8_t > Value)
void printObject(StringRef Label, const T &Value)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
LLVM Value Representation.
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
LLVM_ABI raw_ostream & rawValueBegin()
LLVM_ABI void rawValueEnd()
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
detail::packed_endian_specific_integral< uint16_t, llvm::endianness::little, unaligned > ulittle16_t
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
void sort(IteratorTy Start, IteratorTy End)
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
const char * to_string(ThinOrFullLTOPhase Phase)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
ArrayRef(const T &OneElt) -> ArrayRef< T >
virtual void setPrinter(ScopedPrinter &W)=0
DelimitedScope(ScopedPrinter &W)
virtual ~DelimitedScope()=default
DictScope(ScopedPrinter &W)
DictScope(ScopedPrinter &W, StringRef N)
void setPrinter(ScopedPrinter &W) override
FlagEntry(StringRef Name, signed long Value)
FlagEntry(StringRef Name, signed int Value)
FlagEntry(StringRef Name, unsigned short Value)
FlagEntry(StringRef Name, unsigned long long Value)
FlagEntry(StringRef Name, unsigned long Value)
FlagEntry(StringRef Name, signed long long Value)
FlagEntry(StringRef Name, char Value)
FlagEntry(StringRef Name, signed char Value)
FlagEntry(StringRef Name, signed short Value)
FlagEntry(StringRef Name, EnumT Value)
FlagEntry(StringRef Name, unsigned int Value)
FlagEntry(StringRef Name, unsigned char Value)
HexNumber(unsigned char Value)
HexNumber(signed int Value)
HexNumber(signed long long Value)
HexNumber(signed long Value)
HexNumber(unsigned int Value)
HexNumber(unsigned long long Value)
HexNumber(signed char Value)
HexNumber(signed short Value)
HexNumber(unsigned long Value)
HexNumber(unsigned short Value)
ListScope(ScopedPrinter &W)
void setPrinter(ScopedPrinter &W) override
ListScope(ScopedPrinter &W, StringRef N)