xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DebugInfo/LogicalView/Core/LVCompare.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- LVCompare.h ---------------------------------------------*- C++ -*-===//
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 file defines the LVCompare class, which is used to describe a logical
10 // view comparison.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVCOMPARE_H
15 #define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVCOMPARE_H
16 
17 #include "llvm/DebugInfo/LogicalView/Core/LVObject.h"
18 #include "llvm/Support/Compiler.h"
19 
20 namespace llvm {
21 namespace logicalview {
22 
23 class LVReader;
24 
25 // Record the elements missing or added and their compare pass.
26 using LVPassEntry = std::tuple<LVReader *, LVElement *, LVComparePass>;
27 using LVPassTable = std::vector<LVPassEntry>;
28 
29 class LVCompare final {
30   raw_ostream &OS;
31   LVScopes ScopeStack;
32 
33   // As the comparison is performed twice (by exchanging the reference
34   // and target readers) the element missing/added status does specify
35   // the comparison pass.
36   // By recording each missing/added elements along with its pass, it
37   // allows checking which elements were missing/added during each pass.
38   LVPassTable PassTable;
39 
40   // Reader used on the LHS of the comparison.
41   // In the 'Missing' pass, it points to the reference reader.
42   // In the 'Added' pass it points to the target reader.
43   LVReader *Reader = nullptr;
44 
45   bool FirstMissing = true;
46   bool PrintLines = false;
47   bool PrintScopes = false;
48   bool PrintSymbols = false;
49   bool PrintTypes = false;
50 
51   static void setInstance(LVCompare *Compare);
52 
53   void printCurrentStack();
54   void printSummary() const;
55 
56 public:
57   LVCompare() = delete;
58   LLVM_ABI LVCompare(raw_ostream &OS);
59   LVCompare(const LVCompare &) = delete;
60   LVCompare &operator=(const LVCompare &) = delete;
61   ~LVCompare() = default;
62 
63   LLVM_ABI static LVCompare &getInstance();
64 
65   // Scopes stack used during the missing/added reporting.
push(LVScope * Scope)66   void push(LVScope *Scope) { ScopeStack.push_back(Scope); }
pop()67   void pop() { ScopeStack.pop_back(); }
68 
69   // Perform comparison between the 'Reference' and 'Target' scopes tree.
70   LLVM_ABI Error execute(LVReader *ReferenceReader, LVReader *TargetReader);
71 
addPassEntry(LVReader * Reader,LVElement * Element,LVComparePass Pass)72   void addPassEntry(LVReader *Reader, LVElement *Element, LVComparePass Pass) {
73     PassTable.emplace_back(Reader, Element, Pass);
74   }
getPassTable()75   const LVPassTable &getPassTable() const & { return PassTable; }
76 
77   LLVM_ABI void printItem(LVElement *Element, LVComparePass Pass);
78   LLVM_ABI void print(raw_ostream &OS) const;
79 
80 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
dump()81   void dump() const { print(dbgs()); }
82 #endif
83 };
84 
getComparator()85 inline LVCompare &getComparator() { return LVCompare::getInstance(); }
86 
87 } // end namespace logicalview
88 } // end namespace llvm
89 
90 #endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVCOMPARE_H
91