LLVM 20.0.0git
LVObject.cpp
Go to the documentation of this file.
1//===-- LVObject.cpp ------------------------------------------------------===//
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// This implements the LVObject class.
10//
11//===----------------------------------------------------------------------===//
12
17#include <iomanip>
18
19using namespace llvm;
20using namespace llvm::logicalview;
21
22#define DEBUG_TYPE "Object"
23
24#ifndef NDEBUG
25uint64_t LVObject::GID = 0;
26#endif
27
33
34// Get a string representing the indentation level.
35std::string LVObject::indentAsString(LVLevel Level) const {
36 return std::string(Level * 2, ' ');
37}
38
39// Get a string representing the indentation level.
40std::string LVObject::indentAsString() const {
41 return (options().getPrintFormatting() || options().getPrintOffset())
42 ? indentAsString(ScopeLevel)
43 : "";
44}
45
46// String used as padding for printing objects with no line number.
47std::string LVObject::noLineAsString(bool ShowZero) const {
48 return std::string(8, ' ');
49}
50
51// Get a string representation for the given number and discriminator.
53 bool ShowZero) const {
54 // The representation is formatted as:
55 // a) line number (xxxxx) and discriminator (yy): 'xxxxx,yy'
56 // b) Only line number (xxxxx): 'xxxxx '
57 // c) No line number: ' '
58 std::stringstream Stream;
59 if (LineNumber) {
60 if (Discriminator && options().getAttributeDiscriminator())
61 Stream << std::setw(5) << LineNumber << "," << std::left << std::setw(2)
63 else
64 Stream << std::setw(5) << LineNumber << " ";
65 } else
66 Stream << noLineAsString(ShowZero);
67
68 if (options().getInternalNone())
69 Stream.str(noLineAsString(ShowZero));
70
71 return Stream.str();
72}
73
74// Same as 'LineString' but with stripped whitespaces.
75std::string LVObject::lineNumberAsStringStripped(bool ShowZero) const {
76 return std::string(StringRef(lineNumberAsString(ShowZero)).trim());
77}
78
80 bool Spaces) const {
81 std::string String;
83 if (LineNumber)
84 Stream << "@" << LineNumber << (Spaces ? " " : "");
85
86 return String;
87}
88
90 Parent.Scope = Scope;
91 setLevel(Scope->getLevel() + 1);
92}
94 Parent.Symbol = Symbol;
95 setLevel(Symbol->getLevel() + 1);
96}
97
99 // Mark the current object as 'missing'; then traverse the parents chain
100 // marking them as 'special missing' to indicate a missing branch. They
101 // can not be marked as missing, because will generate incorrect reports.
102 LVObject *Parent = this;
103 Parent->setIsMissing();
104 while (Parent) {
105 Parent->setIsMissingLink();
106 Parent = Parent->getParent();
107 }
108}
109
111 bool Full) const {
112 print(OS, Full);
113 return Error::success();
114}
115
117 LVObject *Parent, StringRef Value,
118 bool UseQuotes, bool PrintRef) const {
119 // The current object will be the enclosing scope, use its offset and level.
120 LVObject Object(*Parent);
121 Object.setLevel(Parent->getLevel() + 1);
122 Object.setLineNumber(0);
123 Object.printAttributes(OS, Full);
124
125 // Print the line.
126 std::string TheLineNumber(Object.lineNumberAsString());
127 std::string TheIndentation(Object.indentAsString());
128 OS << format(" %5s %s ", TheLineNumber.c_str(), TheIndentation.c_str());
129
130 OS << Name;
131 if (PrintRef && options().getAttributeOffset())
133 if (UseQuotes)
134 OS << formattedName(Value) << "\n";
135 else
136 OS << Value << "\n";
137}
138
140#ifndef NDEBUG
141 if (options().getInternalID())
143#endif
144 if (options().getCompareExecute() &&
145 (options().getAttributeAdded() || options().getAttributeMissing()))
146 OS << (getIsAdded() ? '+' : getIsMissing() ? '-' : ' ');
147 if (options().getAttributeOffset())
149 if (options().getAttributeLevel()) {
150 std::stringstream Stream;
151 Stream.str(std::string());
152 Stream << "[" << std::setfill('0') << std::setw(3) << getLevel() << "]";
153 std::string TheLevel(Stream.str());
154 OS << TheLevel;
155 }
156 if (options().getAttributeGlobal())
157 OS << (getIsGlobalReference() ? 'X' : ' ');
158}
159
160void LVObject::print(raw_ostream &OS, bool Full) const {
163
164 // Print the line and any discriminator.
165 std::stringstream Stream;
166 Stream << " " << std::setw(5) << lineNumberAsString() << " "
167 << indentAsString() << " ";
168 OS << Stream.str();
169}
static cl::opt< bool > PrintRef("print-ref", cl::ReallyHidden)
raw_pwrite_stream & OS
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVM Value Representation.
Definition: Value.h:74
std::string referenceAsString(uint32_t LineNumber, bool Spaces) const
Definition: LVObject.cpp:79
virtual Error doPrint(bool Split, bool Match, bool Print, raw_ostream &OS, bool Full=true) const
Definition: LVObject.cpp:110
std::string lineAsString(uint32_t LineNumber, LVHalf Discriminator, bool ShowZero) const
Definition: LVObject.cpp:52
std::string indentAsString() const
Definition: LVObject.cpp:40
virtual void print(raw_ostream &OS, bool Full=true) const
Definition: LVObject.cpp:160
void setLevel(LVLevel Level)
Definition: LVObject.h:243
void printAttributes(raw_ostream &OS, bool Full=true) const
Definition: LVObject.cpp:139
virtual std::string lineNumberAsString(bool ShowZero=false) const
Definition: LVObject.h:285
LVLevel getLevel() const
Definition: LVObject.h:242
void setParent(LVScope *Scope)
Definition: LVObject.cpp:89
virtual void printFileIndex(raw_ostream &OS, bool Full=true) const
Definition: LVObject.h:192
uint64_t getID() const
Definition: LVObject.h:318
virtual std::string noLineAsString(bool ShowZero) const
Definition: LVObject.cpp:47
LVOffset getOffset() const
Definition: LVObject.h:238
LVElement * getParent() const
Definition: LVObject.h:248
std::string lineNumberAsStringStripped(bool ShowZero=false) const
Definition: LVObject.cpp:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
StringRef typeUnknown()
Definition: LVObject.cpp:31
StringRef emptyString()
Definition: LVObject.cpp:32
StringRef typeNone()
Definition: LVObject.cpp:28
std::string hexSquareString(uint64_t Value)
Definition: LVSupport.h:117
std::string formattedName(StringRef Name)
Definition: LVSupport.h:220
StringRef typeInt()
Definition: LVObject.cpp:30
LVOptions & options()
Definition: LVOptions.h:445
StringRef typeVoid()
Definition: LVObject.cpp:29
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125