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 = {}) {
164 SmallVector<FlagEntry, 10> SetFlags;
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);
237 template <
typename T>
248 printVersionInternal(Version...);
252 template <
typename T>
255 for (
const auto &Item :
List)
261 printListImpl(Label,
List);
265 printListImpl(Label,
List);
269 printListImpl(Label,
List);
273 printListImpl(Label,
List);
277 printListImpl(Label,
List);
282 for (
const uint8_t &Item :
List)
284 printListImpl(Label, NumberList);
288 printListImpl(Label,
List);
292 printListImpl(Label,
List);
296 printListImpl(Label,
List);
301 for (
const int8_t &Item :
List)
303 printListImpl(Label, NumberList);
307 printListImpl(Label,
List);
310 template <
typename T,
typename U>
314 for (
const auto &Item :
List) {
323 for (
const auto &Item :
List)
325 printHexListImpl(Label, HexList);
333 printHexImpl(Label, Str,
hex(
Value));
336 template <
typename T>
338 printSymbolOffsetImpl(Label, Symbol,
hex(
Value));
348 printStringEscapedImpl(Label,
Value);
352 printBinaryImpl(Label, Str,
Value,
false);
358 printBinaryImpl(Label, Str, V,
false);
368 printBinaryImpl(Label,
StringRef(), V,
false);
374 printBinaryImpl(Label,
StringRef(), V,
false);
389 printBinaryImpl(Label,
StringRef(), V,
true);
416 template <
typename T>
void printVersionInternal(
T Value) {
420 template <
typename S,
typename T,
typename... TArgs>
421 void printVersionInternal(S Value,
T Value2, TArgs... Args) {
423 printVersionInternal(Value2, Args...);
426 static bool flagName(
const FlagEntry &
LHS,
const FlagEntry &
RHS) {
427 return LHS.Name <
RHS.Name;
430 virtual void printBinaryImpl(StringRef Label, StringRef Str,
431 ArrayRef<uint8_t> Value,
bool Block,
434 virtual void printFlagsImpl(StringRef Label, HexNumber Value,
435 ArrayRef<FlagEntry> Flags) {
437 for (
const auto &Flag : Flags)
442 virtual void printFlagsImpl(StringRef Label, HexNumber Value,
443 ArrayRef<HexNumber> Flags) {
445 for (
const auto &Flag : Flags)
450 template <
typename T>
void printListImpl(StringRef Label,
const T List) {
453 for (
const auto &Item :
List)
458 virtual void printHexListImpl(StringRef Label,
459 const ArrayRef<HexNumber>
List) {
462 for (
const auto &Item :
List)
463 OS <<
LS <<
hex(Item);
467 virtual void printHexImpl(StringRef Label, HexNumber Value) {
471 virtual void printHexImpl(StringRef Label, StringRef Str, HexNumber Value) {
475 virtual void printSymbolOffsetImpl(StringRef Label, StringRef Symbol,
480 virtual void printNumberImpl(StringRef Label, StringRef Str,
485 virtual void printStringEscapedImpl(StringRef Label, StringRef Value) {
491 void scopedBegin(
char Symbol) {
496 void scopedBegin(StringRef Label,
char Symbol) {
504 void scopedEnd(
char Symbol) {
517ScopedPrinter::printHex<support::ulittle16_t>(
StringRef Label,
519 startLine() << Label <<
": " << hex(
Value) <<
"\n";
522struct DelimitedScope;
531 enum class ScopeKind {
537 struct ScopeContext {
540 ScopeContext(Scope
Context, ScopeKind Kind = ScopeKind::NoAttribute)
546 std::unique_ptr<DelimitedScope> OuterScope;
550 std::unique_ptr<DelimitedScope> &&OuterScope =
551 std::unique_ptr<DelimitedScope>{});
600 printListImpl(Label,
List);
604 printListImpl(Label,
List);
608 printListImpl(Label,
List);
612 printListImpl(Label,
List);
616 printListImpl(Label,
List);
620 printListImpl(Label,
List);
624 printListImpl(Label,
List);
628 printListImpl(Label,
List);
632 printListImpl(Label,
List);
636 printListImpl(Label,
List);
654 scopedBegin({Scope::Object, ScopeKind::NoAttribute});
658 scopedBegin(Label, Scope::Object);
664 scopedBegin({Scope::Array, ScopeKind::NoAttribute});
668 scopedBegin(Label, Scope::Array);
677 void printAPSInt(
const APSInt &Value) {
682 void printFlagsImpl(StringRef Label, HexNumber Value,
683 ArrayRef<FlagEntry> Flags)
override {
685 JOS.
attribute(
"RawFlags", hexNumberToInt(Value));
687 for (
const FlagEntry &Flag : Flags) {
697 void printFlagsImpl(StringRef Label, HexNumber Value,
698 ArrayRef<HexNumber> Flags)
override {
700 JOS.
attribute(
"RawFlags", hexNumberToInt(Value));
702 for (
const HexNumber &Flag : Flags) {
709 template <
typename T>
void printListImpl(StringRef Label,
const T &
List) {
711 for (
const auto &Item :
List)
716 void printHexListImpl(StringRef Label,
717 const ArrayRef<HexNumber>
List)
override {
719 for (
const HexNumber &Item :
List) {
720 JOS.
value(hexNumberToInt(Item));
725 void printHexImpl(StringRef Label, HexNumber Value)
override {
726 JOS.
attribute(Label, hexNumberToInt(Value));
729 void printHexImpl(StringRef Label, StringRef Str, HexNumber Value)
override {
732 JOS.
attribute(
"RawValue", hexNumberToInt(Value));
736 void printSymbolOffsetImpl(StringRef Label, StringRef Symbol,
737 HexNumber Value)
override {
740 JOS.
attribute(
"Offset", hexNumberToInt(Value));
744 void printNumberImpl(StringRef Label, StringRef Str,
745 StringRef Value)
override {
755 void printBinaryImpl(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value,
762 for (uint8_t Val : Value)
768 void scopedBegin(ScopeContext ScopeCtx) {
769 if (ScopeCtx.Context == Scope::Object)
771 else if (ScopeCtx.Context == Scope::Array)
776 void scopedBegin(StringRef Label, Scope Ctx) {
777 ScopeKind
Kind = ScopeKind::Attribute;
778 if (ScopeHistory.
empty() || ScopeHistory.
back().Context != Scope::Object) {
780 Kind = ScopeKind::NestedAttribute;
783 scopedBegin({Ctx,
Kind});
787 ScopeContext ScopeCtx = ScopeHistory.
back();
788 if (ScopeCtx.Context == Scope::Object)
790 else if (ScopeCtx.Context == Scope::Array)
792 if (ScopeCtx.Kind == ScopeKind::Attribute ||
793 ScopeCtx.Kind == ScopeKind::NestedAttribute)
795 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")
This file supports working with JSON data.
Memory true print Memory SSA Printer
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 printList(StringRef Label, const ArrayRef< std::string > List) override
void printNumber(StringRef Label, int32_t Value) override
void printList(StringRef Label, const ArrayRef< uint8_t > List) override
void printNumber(StringRef Label, int8_t Value) override
void printList(StringRef Label, const ArrayRef< int32_t > List) override
void printNumber(StringRef Label, uint64_t Value) override
void printBoolean(StringRef Label, bool Value) override
void printList(StringRef Label, const ArrayRef< int64_t > List) override
void printList(StringRef Label, const ArrayRef< bool > List) override
void arrayBegin() override
void printList(StringRef Label, const ArrayRef< APSInt > List) override
void printNumber(StringRef Label, int64_t Value) override
void printList(StringRef Label, const ArrayRef< uint64_t > List) override
void printList(StringRef Label, const ArrayRef< uint16_t > List) override
void printList(StringRef Label, const ArrayRef< int16_t > List) override
void printNumber(StringRef Label, uint8_t Value) override
void objectEnd() override
void printNumber(StringRef Label, uint16_t Value) override
void printNumber(StringRef Label, int16_t Value) 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 arrayBegin(StringRef Label) override
void printNumber(StringRef Label, uint32_t Value) override
void printString(StringRef Value) override
void objectBegin(StringRef Label) override
void printString(StringRef Label, StringRef Value) override
void printList(StringRef Label, const ArrayRef< int8_t > List) override
void objectBegin() override
virtual void printList(StringRef Label, const ArrayRef< int32_t > List)
void printHexList(StringRef Label, const T &List)
virtual void printNumber(StringRef Label, int32_t Value)
virtual void printList(StringRef Label, const ArrayRef< uint32_t > List)
virtual void printNumber(StringRef Label, uint8_t Value)
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 printList(StringRef Label, const ArrayRef< int64_t > List)
void indent(int Levels=1)
virtual void printList(StringRef Label, const ArrayRef< int16_t > List)
void printFlags(StringRef Label, T Value)
virtual void printList(StringRef Label, const ArrayRef< std::string > List)
virtual void printNumber(StringRef Label, uint16_t Value)
virtual void printNumber(StringRef Label, int8_t Value)
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 printFlags(StringRef Label, T Value, ArrayRef< EnumEntry< TFlag > > Flags, TFlag EnumMask1={}, TFlag EnumMask2={}, TFlag EnumMask3={})
void printList(StringRef Label, const T &List, const U &Printer)
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 raw_ostream & startLine()
void printBinary(StringRef Label, StringRef Str, ArrayRef< uint8_t > Value)
virtual void printList(StringRef Label, const ArrayRef< uint64_t > List)
void printHex(StringRef Label, T Value)
virtual void objectBegin(StringRef Label)
virtual void printNumber(StringRef Label, int64_t Value)
void setPrefix(StringRef P)
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 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, int16_t Value)
void printBinary(StringRef Label, ArrayRef< char > Value)
virtual void printNumber(StringRef Label, uint32_t Value)
void printList(StringRef Label, const ArrayRef< T > List)
void printBinary(StringRef Label, ArrayRef< uint8_t > Value)
virtual void printNumber(StringRef Label, uint64_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.
std::string & str()
Returns the string's reference.
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)
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)