Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- LVSymbol.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 LVSymbol class, which is used to describe a debug
0010 // information symbol.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H
0015 #define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H
0016 
0017 #include "llvm/DebugInfo/LogicalView/Core/LVElement.h"
0018 
0019 namespace llvm {
0020 namespace logicalview {
0021 
0022 enum class LVSymbolKind {
0023   IsCallSiteParameter,
0024   IsConstant,
0025   IsInheritance,
0026   IsMember,
0027   IsParameter,
0028   IsUnspecified,
0029   IsVariable,
0030   LastEntry
0031 };
0032 using LVSymbolKindSet = std::set<LVSymbolKind>;
0033 using LVSymbolDispatch = std::map<LVSymbolKind, LVSymbolGetFunction>;
0034 using LVSymbolRequest = std::vector<LVSymbolGetFunction>;
0035 
0036 class LVSymbol final : public LVElement {
0037   enum class Property { HasLocation, FillGaps, LastEntry };
0038 
0039   // Typed bitvector with kinds and properties for this symbol.
0040   LVProperties<LVSymbolKind> Kinds;
0041   LVProperties<Property> Properties;
0042   static LVSymbolDispatch Dispatch;
0043 
0044   // CodeView symbol Linkage name.
0045   size_t LinkageNameIndex = 0;
0046 
0047   // Reference to DW_AT_specification, DW_AT_abstract_origin attribute.
0048   LVSymbol *Reference = nullptr;
0049   std::unique_ptr<LVLocations> Locations;
0050   LVLocation *CurrentLocation = nullptr;
0051 
0052   // Bitfields length.
0053   uint32_t BitSize = 0;
0054 
0055   // Index in the String pool representing any initial value.
0056   size_t ValueIndex = 0;
0057 
0058   // Coverage factor in units (bytes).
0059   unsigned CoverageFactor = 0;
0060   float CoveragePercentage = 0;
0061 
0062   // Add a location gap into the location list.
0063   LVLocations::iterator addLocationGap(LVLocations::iterator Pos,
0064                                        LVAddress LowPC, LVAddress HighPC);
0065 
0066   // Find the current symbol in the given 'Targets'.
0067   LVSymbol *findIn(const LVSymbols *Targets) const;
0068 
0069 public:
0070   LVSymbol() : LVElement(LVSubclassID::LV_SYMBOL) {
0071     setIsSymbol();
0072     setIncludeInPrint();
0073   }
0074   LVSymbol(const LVSymbol &) = delete;
0075   LVSymbol &operator=(const LVSymbol &) = delete;
0076   ~LVSymbol() = default;
0077 
0078   static bool classof(const LVElement *Element) {
0079     return Element->getSubclassID() == LVSubclassID::LV_SYMBOL;
0080   }
0081 
0082   KIND(LVSymbolKind, IsCallSiteParameter);
0083   KIND(LVSymbolKind, IsConstant);
0084   KIND(LVSymbolKind, IsInheritance);
0085   KIND(LVSymbolKind, IsMember);
0086   KIND(LVSymbolKind, IsParameter);
0087   KIND(LVSymbolKind, IsUnspecified);
0088   KIND(LVSymbolKind, IsVariable);
0089 
0090   PROPERTY(Property, HasLocation);
0091   PROPERTY(Property, FillGaps);
0092 
0093   const char *kind() const override;
0094 
0095   // Access DW_AT_specification, DW_AT_abstract_origin reference.
0096   LVSymbol *getReference() const { return Reference; }
0097   void setReference(LVSymbol *Symbol) override {
0098     Reference = Symbol;
0099     setHasReference();
0100   }
0101   void setReference(LVElement *Element) override {
0102     assert((!Element || isa<LVSymbol>(Element)) && "Invalid element");
0103     setReference(static_cast<LVSymbol *>(Element));
0104   }
0105 
0106   void setLinkageName(StringRef LinkageName) override {
0107     LinkageNameIndex = getStringPool().getIndex(LinkageName);
0108   }
0109   StringRef getLinkageName() const override {
0110     return getStringPool().getString(LinkageNameIndex);
0111   }
0112   size_t getLinkageNameIndex() const override { return LinkageNameIndex; }
0113 
0114   uint32_t getBitSize() const override { return BitSize; }
0115   void setBitSize(uint32_t Size) override { BitSize = Size; }
0116 
0117   // Process the values for a DW_AT_const_value.
0118   StringRef getValue() const override {
0119     return getStringPool().getString(ValueIndex);
0120   }
0121   void setValue(StringRef Value) override {
0122     ValueIndex = getStringPool().getIndex(Value);
0123   }
0124   size_t getValueIndex() const override { return ValueIndex; }
0125 
0126   // Add a Location Entry.
0127   void addLocationConstant(dwarf::Attribute Attr, LVUnsigned Constant,
0128                            uint64_t LocDescOffset);
0129   void addLocationOperands(LVSmall Opcode, ArrayRef<uint64_t> Operands);
0130   void addLocation(dwarf::Attribute Attr, LVAddress LowPC, LVAddress HighPC,
0131                    LVUnsigned SectionOffset, uint64_t LocDescOffset,
0132                    bool CallSiteLocation = false);
0133 
0134   // Fill gaps in the location list.
0135   void fillLocationGaps();
0136 
0137   // Get all the locations associated with symbols.
0138   void getLocations(LVLocations &LocationList, LVValidLocation ValidLocation,
0139                     bool RecordInvalid = false);
0140   void getLocations(LVLocations &LocationList) const;
0141 
0142   // Calculate coverage factor.
0143   void calculateCoverage();
0144 
0145   unsigned getCoverageFactor() const { return CoverageFactor; }
0146   void setCoverageFactor(unsigned Value) { CoverageFactor = Value; }
0147   float getCoveragePercentage() const { return CoveragePercentage; }
0148   void setCoveragePercentage(float Value) { CoveragePercentage = Value; }
0149 
0150   // Print location in raw format.
0151   void printLocations(raw_ostream &OS, bool Full = true) const;
0152 
0153   // Follow a chain of references given by DW_AT_abstract_origin and/or
0154   // DW_AT_specification and update the symbol name.
0155   StringRef resolveReferencesChain();
0156 
0157   void resolveName() override;
0158   void resolveReferences() override;
0159 
0160   static LVSymbolDispatch &getDispatch() { return Dispatch; }
0161 
0162   static bool parametersMatch(const LVSymbols *References,
0163                               const LVSymbols *Targets);
0164 
0165   static void getParameters(const LVSymbols *Symbols, LVSymbols *Parameters);
0166 
0167   // Iterate through the 'References' set and check that all its elements
0168   // are present in the 'Targets' set. For a missing element, mark its
0169   // parents as missing.
0170   static void markMissingParents(const LVSymbols *References,
0171                                  const LVSymbols *Targets);
0172 
0173   // Returns true if current type is logically equal to the given 'Symbol'.
0174   bool equals(const LVSymbol *Symbol) const;
0175 
0176   // Returns true if the given 'References' are logically equal to the
0177   // given 'Targets'.
0178   static bool equals(const LVSymbols *References, const LVSymbols *Targets);
0179 
0180   // Report the current symbol as missing or added during comparison.
0181   void report(LVComparePass Pass) override;
0182 
0183   void print(raw_ostream &OS, bool Full = true) const override;
0184   void printExtra(raw_ostream &OS, bool Full = true) const override;
0185 
0186 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0187   void dump() const override { print(dbgs()); }
0188 #endif
0189 };
0190 
0191 } // end namespace logicalview
0192 } // end namespace llvm
0193 
0194 #endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H