[llvm] r342284 - [PDB] Refactor a little of the Symbol creation code.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 14 14:03:57 PDT 2018


Author: zturner
Date: Fri Sep 14 14:03:57 2018
New Revision: 342284

URL: http://llvm.org/viewvc/llvm-project?rev=342284&view=rev
Log:
[PDB] Refactor a little of the Symbol creation code.

Eventually we need to be able to support nested types, which don't
have an associated CVType record.  To handle this, remove the
CVType from all of the record classes, and instead store the
deserialized record.  Then move the deserialization up to the thing
that creates the type.  This actually makes error handling better
anyway as we can return an invalid symbol instead of asserting false.

Modified:
    llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypeEnum.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypePointer.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Native/SymbolCache.h
    llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp
    llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp
    llvm/trunk/lib/DebugInfo/PDB/Native/SymbolCache.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypeEnum.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypeEnum.h?rev=342284&r1=342283&r2=342284&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypeEnum.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypeEnum.h Fri Sep 14 14:03:57 2018
@@ -21,8 +21,8 @@ namespace pdb {
 class NativeTypeEnum : public NativeRawSymbol,
                        public codeview::TypeVisitorCallbacks {
 public:
-  NativeTypeEnum(NativeSession &Session, SymIndexId Id,
-                 const codeview::CVType &CV);
+  NativeTypeEnum(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI,
+                 codeview::EnumRecord Record);
   ~NativeTypeEnum() override;
 
   void dump(raw_ostream &OS, int Indent) const override;
@@ -55,7 +55,7 @@ public:
   bool isInterfaceUdt() const override;
 
 protected:
-  codeview::CVType CV;
+  codeview::TypeIndex Index;
   codeview::EnumRecord Record;
 };
 

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypePointer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypePointer.h?rev=342284&r1=342283&r2=342284&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypePointer.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/NativeTypePointer.h Fri Sep 14 14:03:57 2018
@@ -21,9 +21,8 @@ namespace pdb {
 
 class NativeTypePointer : public NativeRawSymbol {
 public:
-  NativeTypePointer(NativeSession &Session, SymIndexId Id, codeview::CVType CV);
   NativeTypePointer(NativeSession &Session, SymIndexId Id,
-                    codeview::PointerRecord PR);
+                    codeview::TypeIndex TI, codeview::PointerRecord PR);
   ~NativeTypePointer() override;
 
   void dump(raw_ostream &OS, int Indent) const override;
@@ -40,6 +39,7 @@ public:
   bool isUnalignedType() const override;
 
 protected:
+  codeview::TypeIndex TI;
   codeview::PointerRecord Record;
 };
 

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/SymbolCache.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/SymbolCache.h?rev=342284&r1=342283&r2=342284&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/SymbolCache.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/SymbolCache.h Fri Sep 14 14:03:57 2018
@@ -38,23 +38,32 @@ class SymbolCache {
     return Id;
   }
 
+  template <typename ConcreteSymbolT, typename CVRecordT, typename... Args>
+  SymIndexId createSymbolForType(codeview::TypeIndex TI, codeview::CVType CVT,
+                                 Args &&... ConstructorArgs) {
+    CVRecordT Record;
+    if (auto EC = TypeDeserializer::deserializeAs<CVRecordT>(CVT, Record)) {
+      consumeError(std::move(EC));
+      return 0;
+    }
+
+    return createSymbol<ConcreteSymbolT>(
+        TI, std::move(Record), std::forward<Args>(ConstructorArgs)...);
+  }
+
 public:
   SymbolCache(NativeSession &Session, DbiStream *Dbi);
 
   template <typename ConcreteSymbolT, typename... Args>
   SymIndexId createSymbol(Args &&... ConstructorArgs) {
     SymIndexId Id = Cache.size();
-    std::unique_ptr<ConcreteSymbolT> Symbol =
-        llvm::make_unique<ConcreteSymbolT>(
-            Session, Id, std::forward<Args>(ConstructorArgs)...);
-    std::unique_ptr<NativeRawSymbol> NRS = std::move(Symbol);
-    Cache.push_back(std::move(NRS));
+
+    auto Result = llvm::make_unique<ConcreteSymbolT>(
+        Session, Id, std::forward<Args>(ConstructorArgs)...);
+    Cache.push_back(std::move(Result));
     return Id;
   }
 
-  std::unique_ptr<PDBSymbolTypeEnum>
-  createEnumSymbol(codeview::TypeIndex Index);
-
   std::unique_ptr<IPDBEnumSymbols>
   createTypeEnumerator(codeview::TypeLeafKind Kind);
 

Modified: llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp?rev=342284&r1=342283&r2=342284&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypeEnum.cpp Fri Sep 14 14:03:57 2018
@@ -24,12 +24,9 @@ using namespace llvm::codeview;
 using namespace llvm::pdb;
 
 NativeTypeEnum::NativeTypeEnum(NativeSession &Session, SymIndexId Id,
-                               const codeview::CVType &CVT)
-    : NativeRawSymbol(Session, PDB_SymType::Enum, Id), CV(CVT),
-      Record(codeview::TypeRecordKind::Enum) {
-  assert(CV.kind() == codeview::TypeLeafKind::LF_ENUM);
-  cantFail(visitTypeRecord(CV, *this));
-}
+                               TypeIndex Index, EnumRecord Record)
+    : NativeRawSymbol(Session, PDB_SymType::Enum, Id), Index(Index),
+      Record(std::move(Record)) {}
 
 NativeTypeEnum::~NativeTypeEnum() {}
 

Modified: llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp?rev=342284&r1=342283&r2=342284&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/NativeTypePointer.cpp Fri Sep 14 14:03:57 2018
@@ -18,17 +18,10 @@ using namespace llvm::codeview;
 using namespace llvm::pdb;
 
 NativeTypePointer::NativeTypePointer(NativeSession &Session, SymIndexId Id,
-                                     codeview::CVType CVT)
-    : NativeRawSymbol(Session, PDB_SymType::PointerType, Id),
-      Record(TypeRecordKind::Pointer) {
-  assert(CVT.kind() == TypeLeafKind::LF_POINTER);
-  cantFail(TypeDeserializer::deserializeAs<PointerRecord>(CVT, Record));
-}
-
-NativeTypePointer::NativeTypePointer(NativeSession &Session, SymIndexId Id,
-                                     PointerRecord PR)
-    : NativeRawSymbol(Session, PDB_SymType::PointerType, Id),
-      Record(std::move(PR)) {}
+                                     codeview::TypeIndex TI,
+                                     codeview::PointerRecord Record)
+    : NativeRawSymbol(Session, PDB_SymType::PointerType, Id), TI(TI),
+      Record(std::move(Record)) {}
 
 NativeTypePointer::~NativeTypePointer() {}
 

Modified: llvm/trunk/lib/DebugInfo/PDB/Native/SymbolCache.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/SymbolCache.cpp?rev=342284&r1=342283&r2=342284&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/SymbolCache.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/SymbolCache.cpp Fri Sep 14 14:03:57 2018
@@ -1,5 +1,6 @@
 #include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
 
+#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
 #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
 #include "llvm/DebugInfo/PDB/Native/NativeEnumTypes.h"
@@ -15,6 +16,7 @@
 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
 
 using namespace llvm;
+using namespace llvm::codeview;
 using namespace llvm::pdb;
 
 // Maps codeview::SimpleTypeKind of a built-in type to the parameters necessary
@@ -46,12 +48,6 @@ SymbolCache::SymbolCache(NativeSession &
     Compilands.resize(Dbi->modules().getModuleCount());
 }
 
-std::unique_ptr<PDBSymbolTypeEnum>
-SymbolCache::createEnumSymbol(codeview::TypeIndex Index) {
-  const auto Id = findSymbolByTypeIndex(Index);
-  return PDBSymbol::createAs<PDBSymbolTypeEnum>(Session, *Cache[Id]);
-}
-
 std::unique_ptr<IPDBEnumSymbols>
 SymbolCache::createTypeEnumerator(codeview::TypeLeafKind Kind) {
   auto Tpi = Session.getPDBFile().getPDBTpiStream();
@@ -98,21 +94,23 @@ SymIndexId SymbolCache::findSymbolByType
     return 0;
   }
   codeview::LazyRandomTypeCollection &Types = Tpi->typeCollection();
-  const codeview::CVType &CVT = Types.getType(Index);
-  // TODO(amccarth):  Make this handle all types, not just LF_ENUMs.
+  codeview::CVType CVT = Types.getType(Index);
+  // TODO(amccarth):  Make this handle all types.
   SymIndexId Id = 0;
   switch (CVT.kind()) {
   case codeview::LF_ENUM:
-    Id = createSymbol<NativeTypeEnum>(CVT);
+    Id = createSymbolForType<NativeTypeEnum, EnumRecord>(Index, std::move(CVT));
     break;
   case codeview::LF_POINTER:
-    Id = createSymbol<NativeTypePointer>(CVT);
+    Id = createSymbolForType<NativeTypePointer, PointerRecord>(Index,
+                                                               std::move(CVT));
     break;
   default:
     Id = createSymbolPlaceholder();
     break;
   }
-  TypeIndexToSymbolId[Index] = Id;
+  if (Id != 0)
+    TypeIndexToSymbolId[Index] = Id;
   return Id;
 }
 




More information about the llvm-commits mailing list