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