Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:42

0001 //===-- LVCompare.h ---------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the LVCompare class, which is used to describe a logical
0010 // view comparison.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVCOMPARE_H
0015 #define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVCOMPARE_H
0016 
0017 #include "llvm/DebugInfo/LogicalView/Core/LVObject.h"
0018 
0019 namespace llvm {
0020 namespace logicalview {
0021 
0022 class LVReader;
0023 
0024 // Record the elements missing or added and their compare pass.
0025 using LVPassEntry = std::tuple<LVReader *, LVElement *, LVComparePass>;
0026 using LVPassTable = std::vector<LVPassEntry>;
0027 
0028 class LVCompare final {
0029   raw_ostream &OS;
0030   LVScopes ScopeStack;
0031 
0032   // As the comparison is performed twice (by exchanging the reference
0033   // and target readers) the element missing/added status does specify
0034   // the comparison pass.
0035   // By recording each missing/added elements along with its pass, it
0036   // allows checking which elements were missing/added during each pass.
0037   LVPassTable PassTable;
0038 
0039   // Reader used on the LHS of the comparison.
0040   // In the 'Missing' pass, it points to the reference reader.
0041   // In the 'Added' pass it points to the target reader.
0042   LVReader *Reader = nullptr;
0043 
0044   bool FirstMissing = true;
0045   bool PrintLines = false;
0046   bool PrintScopes = false;
0047   bool PrintSymbols = false;
0048   bool PrintTypes = false;
0049 
0050   static void setInstance(LVCompare *Compare);
0051 
0052   void printCurrentStack();
0053   void printSummary() const;
0054 
0055 public:
0056   LVCompare() = delete;
0057   LVCompare(raw_ostream &OS);
0058   LVCompare(const LVCompare &) = delete;
0059   LVCompare &operator=(const LVCompare &) = delete;
0060   ~LVCompare() = default;
0061 
0062   static LVCompare &getInstance();
0063 
0064   // Scopes stack used during the missing/added reporting.
0065   void push(LVScope *Scope) { ScopeStack.push_back(Scope); }
0066   void pop() { ScopeStack.pop_back(); }
0067 
0068   // Perform comparison between the 'Reference' and 'Target' scopes tree.
0069   Error execute(LVReader *ReferenceReader, LVReader *TargetReader);
0070 
0071   void addPassEntry(LVReader *Reader, LVElement *Element, LVComparePass Pass) {
0072     PassTable.emplace_back(Reader, Element, Pass);
0073   }
0074   const LVPassTable &getPassTable() const & { return PassTable; }
0075 
0076   void printItem(LVElement *Element, LVComparePass Pass);
0077   void print(raw_ostream &OS) const;
0078 
0079 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0080   void dump() const { print(dbgs()); }
0081 #endif
0082 };
0083 
0084 inline LVCompare &getComparator() { return LVCompare::getInstance(); }
0085 
0086 } // end namespace logicalview
0087 } // end namespace llvm
0088 
0089 #endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVCOMPARE_H