xref: /llvm-project/llvm/lib/DebugInfo/LogicalView/Core/LVOptions.cpp (revision c28a977b87defd2f37fd0808d7ba6173133744ce)
1 //===-- LVOptions.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 LVOptions class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/DebugInfo/LogicalView/Core/LVOptions.h"
14 
15 using namespace llvm;
16 using namespace llvm::logicalview;
17 
18 #define DEBUG_TYPE "Options"
19 
20 //===----------------------------------------------------------------------===//
21 // Options extracted from the command line.
22 //===----------------------------------------------------------------------===//
23 static LVOptions Options;
24 LVOptions *LVOptions::getOptions() { return &Options; }
25 void LVOptions::setOptions(LVOptions *CmdOptions) { Options = *CmdOptions; }
26 
27 void LVOptions::resolveDependencies() {
28   // Attributes that are classified as standard options.
29   auto StandardAttributes = [&]() {
30     // Set the 'standard' attribute to indicate its associated attributes.
31     setAttributeStandard();
32 
33     setAttributeBase();
34     setAttributeCoverage();
35     setAttributeDirectories();
36     setAttributeDiscriminator();
37     setAttributeFilename();
38     setAttributeFiles();
39     setAttributeFormat();
40     setAttributeLevel();
41     setAttributeProducer();
42     setAttributePublics();
43     setAttributeRange();
44     setAttributeReference();
45     setAttributeZero();
46   };
47 
48   // Attributes that are classified as extended options.
49   auto ExtendedAttributes = [&]() {
50     // Set the 'extended' attribute to indicate its associated attributes.
51     setAttributeExtended();
52 
53     setAttributeArgument();
54     setAttributeDiscarded();
55     setAttributeEncoded();
56     setAttributeGaps();
57     setAttributeGenerated();
58     setAttributeGlobal();
59     setAttributeInserted();
60     setAttributeLinkage();
61     setAttributeLocal();
62     setAttributeLocation();
63     setAttributeOffset();
64     setAttributePathname();
65     setAttributeQualified();
66     setAttributeQualifier();
67     setAttributeRegister();
68     setAttributeSubrange();
69     setAttributeSystem();
70     setAttributeTypename();
71   };
72 
73   // '--Attribute=standard' settings.
74   if (getAttributeStandard())
75     StandardAttributes();
76 
77   // '--Attribute=extended' settings.
78   if (getAttributeExtended())
79     ExtendedAttributes();
80 
81   // '--Attribute=all' settings.
82   if (getAttributeAll()) {
83     StandardAttributes();
84     ExtendedAttributes();
85   }
86 
87   // '--attribute=pathname' supersedes '--attribute=filename'.
88   if (getAttributePathname())
89     resetAttributeFilename();
90 
91   // Assume '--output=text' as default
92   if (!getOutputText() && !getOutputJson())
93     setOutputText();
94 
95   // '--output=all' settings.
96   if (getOutputAll()) {
97     setOutputJson();
98     setOutputSplit();
99     setOutputText();
100   }
101 
102   // A view split folder was specified.
103   if (getOutputFolder().length())
104     setOutputSplit();
105 
106   // Always use the full pathname with splitted output.
107   if (getOutputSplit())
108     setAttributePathname();
109 
110   // '--print=elements' settings.
111   if (getPrintElements()) {
112     setPrintInstructions();
113     setPrintLines();
114     setPrintScopes();
115     setPrintSymbols();
116     setPrintTypes();
117   }
118 
119   // '--print=all' settings.
120   if (getPrintAll()) {
121     setPrintInstructions();
122     setPrintLines();
123     setPrintScopes();
124     setPrintSizes();
125     setPrintSymbols();
126     setPrintSummary();
127     setPrintTypes();
128     setPrintWarnings();
129   }
130 
131   // '--warning=all' settings.
132   if (getWarningAll()) {
133     setWarningCoverages();
134     setWarningLines();
135     setWarningLocations();
136     setWarningRanges();
137   }
138 
139   // '--internal=all' settings.
140   if (getInternalAll()) {
141     setInternalCmdline();
142     setInternalID();
143     setInternalIntegrity();
144     setInternalNone();
145     setInternalTag();
146   }
147 
148   // '--compare=all' settings.
149   if (getCompareAll()) {
150     setCompareLines();
151     setCompareScopes();
152     setCompareSymbols();
153     setCompareTypes();
154   }
155 
156   // Compare the scopes if a request for compare symbols, types, lines.
157   if (getCompareLines() || getCompareSymbols() || getCompareTypes())
158     setCompareScopes();
159 
160   // Generic request for comparison.
161   if (getCompareScopes())
162     setCompareExecute();
163 
164   // Print any logical line (debug or instruction).
165   if (getPrintInstructions() || getPrintLines())
166     setPrintAnyLine();
167 
168   // Print any logical element (line, scope, symbol or type).
169   if (getPrintAnyLine() || getPrintScopes() || getPrintSymbols() ||
170       getPrintTypes())
171     setPrintAnyElement();
172 
173   // Print 'sizes' or 'summary'.
174   if (getPrintSizes() && getPrintSummary())
175     setPrintSizesSummary();
176 
177   // Generic request for printing.
178   if (getPrintAll() || getPrintAnyElement() || getPrintSizesSummary() ||
179       getPrintWarnings())
180     setPrintExecute();
181 
182   // '--reports=all' settings.
183   if (getReportAll()) {
184     setReportChildren();
185     setReportList();
186     setReportParents();
187     setReportView();
188   }
189 
190   // '--report=view' is a shortcut for '--report=parents,children'.
191   if (getReportView()) {
192     setReportChildren();
193     setReportParents();
194   }
195 
196   // The report will include: Parents or Children.
197   if (getReportParents() || getReportChildren() || getReportView())
198     setReportAnyView();
199 
200   // The report will include: List or Parents or Children.
201   if (getReportList() || getReportAnyView())
202     setReportExecute();
203 
204   // If a view or element comparison has been requested, the following options
205   // must be set, in order to get a correct compare:
206   // 1) Sort the CUs, to get a fast compare.
207   // 2) Encode template instantiations, so the names include template
208   //    parameter information.
209   // 3) Include qualified types.
210   // 4) Include any inserted abstract references.
211   // 5) For added/missing elements add the '+' or '-' tags.
212   if (getCompareExecute()) {
213     resetPrintExecute();
214     setComparePrint();
215     setSortMode(LVSortMode::Line);
216     setAttributeAdded();
217     setAttributeArgument();
218     setAttributeEncoded();
219     setAttributeInserted();
220     setAttributeMissing();
221     setAttributeQualified();
222   }
223 
224   // Enable formatting for printing (indentation, print children).
225   setPrintFormatting();
226 
227   // These attributes are dependent on the capture of location information.
228   if (getAttributeCoverage() || getAttributeGaps() || getAttributeRegister())
229     setAttributeLocation();
230 
231   // Location information is only relevant when printing symbols.
232   if (!getPrintSymbols()) {
233     resetAttributeCoverage();
234     resetAttributeGaps();
235     resetAttributeLocation();
236     resetAttributeRegister();
237   }
238 
239   // Quick check for printing any element source information.
240   if (getAttributeFilename() || getAttributePathname())
241     setAttributeAnySource();
242 
243   // Quick check for printing any location information.
244   if (getAttributeLocation() || getAttributeRange())
245     setAttributeAnyLocation();
246 
247   if (getAttributeRange() || getPrintAnyLine())
248     setGeneralCollectRanges();
249 
250   calculateIndentationSize();
251 
252   // Print collected command line options.
253   LLVM_DEBUG({ dump(); });
254 }
255 
256 void LVOptions::calculateIndentationSize() {
257 #ifndef NDEBUG
258   if (getInternalID()) {
259     std::string String = hexSquareString(0);
260     IndentationSize += String.length();
261   }
262 #endif
263   if (getCompareExecute() && (getAttributeAdded() || getAttributeMissing()))
264     ++IndentationSize;
265   if (getAttributeOffset()) {
266     std::string String = hexSquareString(0);
267     IndentationSize += String.length();
268   }
269   if (getAttributeLevel()) {
270     std::stringstream Stream;
271     Stream.str(std::string());
272     Stream << "[" << std::setfill('0') << std::setw(3) << 0 << "]";
273     IndentationSize += Stream.tellp();
274   }
275   if (getAttributeGlobal())
276     ++IndentationSize;
277 }
278 
279 // Print the current values for all the options, after the dependencies
280 // has been resolved.
281 void LVOptions::print(raw_ostream &OS) const {
282   // --attribute
283   OS << "** Attributes **\n"
284      << "All:           " << getAttributeAll() << ", "
285      << "Argument:      " << getAttributeArgument() << ", "
286      << "Base:          " << getAttributeBase() << ", "
287      << "Coverage:      " << getAttributeCoverage() << "\n"
288      << "Directories:   " << getAttributeDirectories() << ", "
289      << "Discarded:     " << getAttributeDiscarded() << ", "
290      << "Discriminator: " << getAttributeDiscriminator() << ", "
291      << "Encoded:       " << getAttributeEncoded() << "\n"
292      << "Extended:      " << getAttributeExtended() << ", "
293      << "Filename:      " << getAttributeFilename() << ", "
294      << "Files:         " << getAttributeFiles() << ", "
295      << "Format:        " << getAttributeFormat() << "\n"
296      << "Gaps:          " << getAttributeGaps() << ", "
297      << "Generated:     " << getAttributeGenerated() << ", "
298      << "Global:        " << getAttributeGlobal() << ", "
299      << "Inserted:      " << getAttributeInserted() << "\n"
300      << "Level:         " << getAttributeLevel() << ", "
301      << "Linkage:       " << getAttributeLinkage() << ", "
302      << "Local:         " << getAttributeLocal() << ", "
303      << "Location:      " << getAttributeLocation() << "\n"
304      << "Offset:        " << getAttributeOffset() << ", "
305      << "Pathname:      " << getAttributePathname() << ", "
306      << "Producer:      " << getAttributeProducer() << ", "
307      << "Publics:       " << getAttributePublics() << "\n"
308      << "Qualified:     " << getAttributeQualified() << ", "
309      << "Qualifier:     " << getAttributeQualifier() << ", "
310      << "Range:         " << getAttributeRange() << ", "
311      << "Reference:     " << getAttributeReference() << "\n"
312      << "Register:      " << getAttributeRegister() << ", "
313      << "Standard:      " << getAttributeStandard() << ", "
314      << "Subrange:      " << getAttributeSubrange() << ", "
315      << "System:        " << getAttributeSystem() << "\n"
316      << "Typename:      " << getAttributeTypename() << ", "
317      << "Underlying:    " << getAttributeUnderlying() << ", "
318      << "Zero:          " << getAttributeZero() << "\n";
319   OS << "Added:         " << getAttributeAdded() << ", "
320      << "AnyLocation:   " << getAttributeAnyLocation() << ", "
321      << "AnySource:     " << getAttributeAnySource() << ", "
322      << "Missing:       " << getAttributeMissing() << "\n"
323      << "\n";
324 
325   // --compare
326   OS << "** Compare **\n"
327      << "All:     " << getCompareAll() << ", "
328      << "Lines:   " << getCompareLines() << ", "
329      << "Scopes:  " << getCompareScopes() << ", "
330      << "Symbols: " << getCompareSymbols() << ", "
331      << "Types:   " << getCompareTypes() << "\n";
332   OS << "Context: " << getCompareContext() << ", "
333      << "Execute: " << getCompareExecute() << ", "
334      << "Print:   " << getComparePrint() << "\n"
335      << "\n";
336 
337   // --print
338   OS << "** Print **\n"
339      << "All:          " << getPrintAll() << ", "
340      << "Elements:     " << getPrintElements() << ", "
341      << "Instructions: " << getPrintInstructions() << ", "
342      << "Lines:        " << getPrintLines() << "\n"
343      << "Scopes:       " << getPrintScopes() << ", "
344      << "Sizes:        " << getPrintSizes() << ", "
345      << "Summary:      " << getPrintSummary() << ", "
346      << "Symbols:      " << getPrintSymbols() << "\n"
347      << "Types:        " << getPrintTypes() << ", "
348      << "Warnings:     " << getPrintWarnings() << "\n";
349   OS << "AnyElemeny:   " << getPrintAnyElement() << ", "
350      << "AnyLine:      " << getPrintAnyLine() << ", "
351      << "Execute:      " << getPrintExecute() << ", "
352      << "Formatting:   " << getPrintFormatting() << "\n"
353      << "Offset:       " << getPrintOffset() << ", "
354      << "SizesSummary: " << getPrintSizesSummary() << "\n"
355      << "\n";
356 
357   // --report
358   OS << "** Report **\n"
359      << "All:      " << getReportAll() << ", "
360      << "Children: " << getReportChildren() << ", "
361      << "List:     " << getReportList() << ", "
362      << "Parents:  " << getReportParents() << ", "
363      << "View:     " << getReportView() << "\n";
364   OS << "AnyView:  " << getReportAnyView() << ", "
365      << "Execute:  " << getReportExecute() << "\n"
366      << "\n";
367 
368   // --select
369   OS << "** Select **\n"
370      << "IgnoreCase:     " << getSelectIgnoreCase() << ", "
371      << "UseRegex:       " << getSelectUseRegex() << ", "
372      << "Execute:        " << getSelectExecute() << ", "
373      << "GenericKind:    " << getSelectGenericKind() << "\n"
374      << "GenericPattern: " << getSelectGenericPattern() << ", "
375      << "OffsetPattern:  " << getSelectOffsetPattern() << "\n"
376      << "\n";
377 
378   // --warning
379   OS << "** Warning **\n"
380      << "All:       " << getWarningAll() << ", "
381      << "Coverage:  " << getWarningCoverages() << ", "
382      << "Lines:     " << getWarningLines() << ", "
383      << "Locations: " << getWarningLocations() << ", "
384      << "Ranges:    " << getWarningRanges() << "\n"
385      << "\n";
386 
387   // --internal
388   OS << "** Internal **\n"
389      << "All:       " << Options.getInternalAll() << ", "
390      << "Cmdline:   " << Options.getInternalCmdline() << ", "
391      << "ID:        " << Options.getInternalID() << ", "
392      << "Integrity: " << Options.getInternalIntegrity() << ", "
393      << "None:      " << Options.getInternalNone() << "\n"
394      << "Tag:       " << Options.getInternalTag() << "\n"
395      << "\n";
396 }
397