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);
245 template <
typename T>
256 printVersionInternal(Version...);
260 template <
typename T>
263 for (
const auto &Item :
List)
269 printListImpl(Label,
List);
273 printListImpl(Label,
List);
277 printListImpl(Label,
List);
281 printListImpl(Label,
List);
285 printListImpl(Label,
List);
290 for (
const uint8_t &Item :
List)
292 printListImpl(Label, NumberList);
296 printListImpl(Label,
List);
300 printListImpl(Label,
List);
304 printListImpl(Label,
List);
309 for (
const int8_t &Item :
List)
311 printListImpl(Label, NumberList);
315 printListImpl(Label,
List);
318 template <
typename T,
typename U>
322 for (
const auto &Item :
List) {
331 for (
const auto &Item :
List)
333 printHexListImpl(Label, HexList);
341 printHexImpl(Label, Str,
hex(
Value));
344 template <
typename T>
346 printSymbolOffsetImpl(Label, Symbol,
hex(
Value));
356 printStringEscapedImpl(Label,
Value);
360 printBinaryImpl(Label, Str,
Value,
false);
366 printBinaryImpl(Label, Str, V,
false);
376 printBinaryImpl(Label,
StringRef(), V,
false);
382 printBinaryImpl(Label,
StringRef(), V,
false);
397 printBinaryImpl(Label,
StringRef(), V,
true);
424 template <
typename T>
void printVersionInternal(
T Value) {
428 template <
typename S,
typename T,
typename... TArgs>
429 void printVersionInternal(S Value,
T Value2, TArgs... Args) {
431 printVersionInternal(Value2, Args...);
434 static bool flagName(
const FlagEntry &
LHS,
const FlagEntry &
RHS) {
435 return LHS.Name <
RHS.Name;
438 virtual void printBinaryImpl(StringRef Label, StringRef Str,
439 ArrayRef<uint8_t> Value,
bool Block,
442 virtual void printFlagsImpl(StringRef Label, HexNumber Value,
443 ArrayRef<FlagEntry>
Flags) {
445 for (
const auto &Flag :
Flags)
450 virtual void printFlagsImpl(StringRef Label, HexNumber Value,
451 ArrayRef<HexNumber>
Flags) {
453 for (
const auto &Flag :
Flags)
458 template <
typename T>
void printListImpl(StringRef Label,
const T List) {
461 for (
const auto &Item :
List)
466 virtual void printHexListImpl(StringRef Label,
467 const ArrayRef<HexNumber>
List) {
470 for (
const auto &Item :
List)
471 OS <<
LS <<
hex(Item);
475 virtual void printHexImpl(StringRef Label, HexNumber Value) {
479 virtual void printHexImpl(StringRef Label, StringRef Str, HexNumber Value) {
483 virtual void printSymbolOffsetImpl(StringRef Label, StringRef Symbol,
488 virtual void printNumberImpl(StringRef Label, StringRef Str,
493 virtual void printStringEscapedImpl(StringRef Label, StringRef Value) {
499 void scopedBegin(
char Symbol) {
504 void scopedBegin(StringRef Label,
char Symbol) {
512 void scopedEnd(
char Symbol) {
525ScopedPrinter::printHex<support::ulittle16_t>(
StringRef Label,
527 startLine() << Label <<
": " << hex(
Value) <<
"\n";
530struct DelimitedScope;
539 enum class ScopeKind {
545 struct ScopeContext {
548 ScopeContext(Scope
Context, ScopeKind Kind = ScopeKind::NoAttribute)
554 std::unique_ptr<DelimitedScope> OuterScope;
558 std::unique_ptr<DelimitedScope> &&OuterScope =
559 std::unique_ptr<DelimitedScope>{});
616 printListImpl(Label,
List);
620 printListImpl(Label,
List);
624 printListImpl(Label,
List);
628 printListImpl(Label,
List);
632 printListImpl(Label,
List);
636 printListImpl(Label,
List);
640 printListImpl(Label,
List);
644 printListImpl(Label,
List);
648 printListImpl(Label,
List);
652 printListImpl(Label,
List);
670 scopedBegin({Scope::Object, ScopeKind::NoAttribute});
674 scopedBegin(Label, Scope::Object);
680 scopedBegin({Scope::Array, ScopeKind::NoAttribute});
684 scopedBegin(Label, Scope::Array);
693 void printAPSInt(
const APSInt &Value) {
698 void printFlagsImpl(StringRef Label, HexNumber Value,
699 ArrayRef<FlagEntry>
Flags)
override {
701 JOS.
attribute(
"Value", hexNumberToInt(Value));
703 for (
const FlagEntry &Flag :
Flags) {
713 void printFlagsImpl(StringRef Label, HexNumber Value,
714 ArrayRef<HexNumber>
Flags)
override {
716 JOS.
attribute(
"Value", hexNumberToInt(Value));
718 for (
const HexNumber &Flag :
Flags) {
725 template <
typename T>
void printListImpl(StringRef Label,
const T &
List) {
727 for (
const auto &Item :
List)
732 void printHexListImpl(StringRef Label,
733 const ArrayRef<HexNumber>
List)
override {
735 for (
const HexNumber &Item :
List) {
736 JOS.
value(hexNumberToInt(Item));
741 void printHexImpl(StringRef Label, HexNumber Value)
override {
742 JOS.
attribute(Label, hexNumberToInt(Value));
745 void printHexImpl(StringRef Label, StringRef Str, HexNumber Value)
override {
748 JOS.
attribute(
"Value", hexNumberToInt(Value));
752 void printSymbolOffsetImpl(StringRef Label, StringRef Symbol,
753 HexNumber Value)
override {
756 JOS.
attribute(
"Offset", hexNumberToInt(Value));
760 void printNumberImpl(StringRef Label, StringRef Str,
761 StringRef Value)
override {
771 void printBinaryImpl(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value,
778 for (uint8_t Val : Value)
784 void scopedBegin(ScopeContext ScopeCtx) {
785 if (ScopeCtx.Context == Scope::Object)
787 else if (ScopeCtx.Context == Scope::Array)
792 void scopedBegin(StringRef Label, Scope Ctx) {
793 ScopeKind
Kind = ScopeKind::Attribute;
794 if (ScopeHistory.
empty() || ScopeHistory.
back().Context != Scope::Object) {
796 Kind = ScopeKind::NestedAttribute;
799 scopedBegin({Ctx,
Kind});
803 ScopeContext ScopeCtx = ScopeHistory.
back();
804 if (ScopeCtx.Context == Scope::Object)
806 else if (ScopeCtx.Context == Scope::Array)
808 if (ScopeCtx.Kind == ScopeKind::Attribute ||
809 ScopeCtx.Kind == ScopeKind::NestedAttribute)
811 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 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, 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)
virtual void printNumber(StringRef Label, float Value)
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)
virtual void printNumber(StringRef Label, double 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)
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)