9#ifndef LLVM_SUPPORT_SCOPEDPRINTER_H
10#define LLVM_SUPPORT_SCOPEDPRINTER_H
92template <
typename T,
typename TEnum>
95 if (EnumItem.Value ==
Value)
96 return std::string(EnumItem.AltName);
97 return utohexstr(
Value,
true);
109 :
OS(
OS), Kind(Kind) {}
121 void indent(
int Levels = 1) { IndentLevel += Levels; }
124 IndentLevel = IndentLevel > Levels ? IndentLevel - Levels : 0;
135 for (
int i = 0; i < IndentLevel; ++i)
141 template <
typename T,
typename TEnum>
146 for (
const auto &EnumItem : EnumValues) {
147 if (EnumItem.Value ==
Value) {
148 Name = EnumItem.Name;
160 template <
typename T,
typename TFlag>
162 TFlag EnumMask1 = {}, TFlag EnumMask2 = {},
163 TFlag EnumMask3 = {}, ArrayRef<FlagEntry> ExtraFlags = {}) {
164 SmallVector<FlagEntry, 10> SetFlags(ExtraFlags);
166 for (
const auto &Flag : Flags) {
171 if (
Flag.Value & EnumMask1)
172 EnumMask = EnumMask1;
173 else if (
Flag.Value & EnumMask2)
174 EnumMask = EnumMask2;
175 else if (
Flag.Value & EnumMask3)
176 EnumMask = EnumMask3;
177 bool IsEnum = (
Flag.Value & EnumMask) != 0;
178 if ((!IsEnum && (Value &
Flag.Value) ==
Flag.Value) ||
179 (IsEnum && (
Value & EnumMask) ==
Flag.Value)) {
180 SetFlags.emplace_back(
Flag.Name,
Flag.Value);
185 printFlagsImpl(Label,
hex(Value), SetFlags);
198 printFlagsImpl(Label,
hex(
Value), SetFlags);
210 startLine() << Label <<
": " <<
static_cast<unsigned>(
Value) <<
"\n";
257 template <
typename T>
268 printVersionInternal(
Version...);
272 template <
typename T>
275 for (
const auto &Item :
List)
281 printListImpl(Label,
List);
285 printListImpl(Label,
List);
289 printListImpl(Label,
List);
293 printListImpl(Label,
List);
297 printListImpl(Label,
List);
304 printListImpl(Label, NumberList);
308 printListImpl(Label,
List);
312 printListImpl(Label,
List);
316 printListImpl(Label,
List);
321 for (
const int8_t &Item :
List)
323 printListImpl(Label, NumberList);
327 printListImpl(Label,
List);
330 template <
typename T,
typename U>
334 for (
const auto &Item :
List) {
343 for (
const auto &Item :
List)
345 printHexListImpl(Label, HexList);
353 printHexImpl(Label, Str,
hex(
Value));
356 template <
typename T>
358 printSymbolOffsetImpl(Label, Symbol,
hex(
Value));
368 printStringEscapedImpl(Label,
Value);
372 printBinaryImpl(Label, Str,
Value,
false);
378 printBinaryImpl(Label, Str, V,
false);
388 printBinaryImpl(Label,
StringRef(), V,
false);
394 printBinaryImpl(Label,
StringRef(), V,
false);
409 printBinaryImpl(Label,
StringRef(), V,
true);
436 template <
typename T>
void printVersionInternal(
T Value) {
440 template <
typename S,
typename T,
typename... TArgs>
441 void printVersionInternal(S Value,
T Value2, TArgs... Args) {
443 printVersionInternal(Value2, Args...);
446 static bool flagName(
const FlagEntry &
LHS,
const FlagEntry &
RHS) {
447 return LHS.Name <
RHS.Name;
450 virtual void printBinaryImpl(StringRef Label, StringRef Str,
451 ArrayRef<uint8_t> Value,
bool Block,
454 virtual void printFlagsImpl(StringRef Label, HexNumber Value,
455 ArrayRef<FlagEntry> Flags) {
457 for (
const auto &Flag : Flags)
462 virtual void printFlagsImpl(StringRef Label, HexNumber Value,
463 ArrayRef<HexNumber> Flags) {
465 for (
const auto &Flag : Flags)
470 template <
typename T>
void printListImpl(StringRef Label,
const T List) {
473 for (
const auto &Item :
List)
478 virtual void printHexListImpl(StringRef Label,
479 const ArrayRef<HexNumber>
List) {
482 for (
const auto &Item :
List)
483 OS <<
LS <<
hex(Item);
487 virtual void printHexImpl(StringRef Label, HexNumber Value) {
491 virtual void printHexImpl(StringRef Label, StringRef Str, HexNumber Value) {
495 virtual void printSymbolOffsetImpl(StringRef Label, StringRef Symbol,
500 virtual void printNumberImpl(StringRef Label, StringRef Str,
505 virtual void printStringEscapedImpl(StringRef Label, StringRef Value) {
511 void scopedBegin(
char Symbol) {
516 void scopedBegin(StringRef Label,
char Symbol) {
524 void scopedEnd(
char Symbol) {
537ScopedPrinter::printHex<support::ulittle16_t>(
StringRef Label,
539 startLine() << Label <<
": " << hex(
Value) <<
"\n";
542struct DelimitedScope;
551 enum class ScopeKind {
557 struct ScopeContext {
560 ScopeContext(Scope Context, ScopeKind Kind = ScopeKind::NoAttribute)
561 : Context(Context), Kind(Kind) {}
566 std::unique_ptr<DelimitedScope> OuterScope;
570 std::unique_ptr<DelimitedScope> &&OuterScope =
571 std::unique_ptr<DelimitedScope>{});
640 printListImpl(Label,
List);
644 printListImpl(Label,
List);
648 printListImpl(Label,
List);
652 printListImpl(Label,
List);
656 printListImpl(Label,
List);
660 printListImpl(Label,
List);
664 printListImpl(Label,
List);
668 printListImpl(Label,
List);
672 printListImpl(Label,
List);
676 printListImpl(Label,
List);
694 scopedBegin({Scope::Object, ScopeKind::NoAttribute});
698 scopedBegin(Label, Scope::Object);
704 scopedBegin({Scope::Array, ScopeKind::NoAttribute});
708 scopedBegin(Label, Scope::Array);
717 void printAPSInt(
const APSInt &Value) {
722 void printFlagsImpl(StringRef Label, HexNumber Value,
723 ArrayRef<FlagEntry> Flags)
override {
725 JOS.
attribute(
"Value", hexNumberToInt(Value));
727 for (
const FlagEntry &Flag : Flags) {
737 void printFlagsImpl(StringRef Label, HexNumber Value,
738 ArrayRef<HexNumber> Flags)
override {
740 JOS.
attribute(
"Value", hexNumberToInt(Value));
742 for (
const HexNumber &Flag : Flags) {
749 template <
typename T>
void printListImpl(StringRef Label,
const T &
List) {
751 for (
const auto &Item :
List)
756 void printHexListImpl(StringRef Label,
757 const ArrayRef<HexNumber>
List)
override {
759 for (
const HexNumber &Item :
List) {
760 JOS.
value(hexNumberToInt(Item));
765 void printHexImpl(StringRef Label, HexNumber Value)
override {
766 JOS.
attribute(Label, hexNumberToInt(Value));
769 void printHexImpl(StringRef Label, StringRef Str, HexNumber Value)
override {
772 JOS.
attribute(
"Value", hexNumberToInt(Value));
776 void printSymbolOffsetImpl(StringRef Label, StringRef Symbol,
777 HexNumber Value)
override {
780 JOS.
attribute(
"Offset", hexNumberToInt(Value));
784 void printNumberImpl(StringRef Label, StringRef Str,
785 StringRef Value)
override {
795 void printBinaryImpl(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value,
802 for (uint8_t Val : Value)
808 void scopedBegin(ScopeContext ScopeCtx) {
809 if (ScopeCtx.Context == Scope::Object)
811 else if (ScopeCtx.Context == Scope::Array)
816 void scopedBegin(StringRef Label, Scope Ctx) {
817 ScopeKind
Kind = ScopeKind::Attribute;
818 if (ScopeHistory.
empty() || ScopeHistory.
back().Context != Scope::Object) {
820 Kind = ScopeKind::NestedAttribute;
823 scopedBegin({Ctx,
Kind});
827 ScopeContext ScopeCtx = ScopeHistory.
back();
828 if (ScopeCtx.Context == Scope::Object)
830 else if (ScopeCtx.Context == Scope::Array)
832 if (ScopeCtx.Kind == ScopeKind::Attribute ||
833 ScopeCtx.Kind == ScopeKind::NestedAttribute)
835 if (ScopeCtx.Kind == ScopeKind::NestedAttribute)
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
dxil pretty DXIL Metadata Pretty Printer
This file supports working with JSON data.
This file defines the SmallVector class.
An arbitrary precision integer that knows its signedness.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
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
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
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)
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)
void printEnum(StringRef Label, T Value, ArrayRef< EnumEntry< TEnum > > EnumValues)
virtual void printList(StringRef Label, const ArrayRef< bool > List)
virtual void printList(StringRef Label, const ArrayRef< APSInt > List)
void printVersion(StringRef Label, T... Version)
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)
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 printFlags(StringRef Label, T Value, ArrayRef< EnumEntry< TFlag > > Flags, TFlag EnumMask1={}, TFlag EnumMask2={}, TFlag EnumMask3={}, ArrayRef< FlagEntry > ExtraFlags={})
virtual ~ScopedPrinter()=default
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)
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - 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...
void attributeObject(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an object with attributes from the Block.
void attributeBegin(llvm::StringRef Key)
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
raw_ostream & rawValueBegin()
void attributeArray(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an array with elements from the Block.
void value(const Value &V)
Emit a self-contained value (number, string, vector<string> etc).
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
A raw_ostream that writes to an std::string.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
This is an optimization pass for GlobalISel generic memory operations.
std::string to_string(const T &Value)
std::string enumToString(T Value, ArrayRef< EnumEntry< TEnum > > EnumValues)
void sort(IteratorTy Start, IteratorTy End)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
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
constexpr EnumEntry(StringRef N, StringRef A, T V)
constexpr EnumEntry(StringRef N, T V)
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, 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)