[llvm] r280307 - [codeview] Have visitTypeBegin return the record type.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 31 16:14:32 PDT 2016


Author: zturner
Date: Wed Aug 31 18:14:31 2016
New Revision: 280307

URL: http://llvm.org/viewvc/llvm-project?rev=280307&view=rev
Log:
[codeview] Have visitTypeBegin return the record type.

Previously we were assuming that any visitation of types would
necessarily be against a type we had binary data for.  Reasonable
assumption when were just reading PDBs and dumping them, but once
we start writing PDBs from Yaml this breaks down, because we have
no binary data yet, only Yaml, and from that we need to read the
record kind and perform the switch based on that.

So this patch does that.  Instead of having the visitor switch
on the kind that is already in the CVType record, we change the
visitTypeBegin() method to return the Kind, and switch on the
returned value.  This way, the default implementation can still
return the value from the CVType, but the implementation which
visits Yaml records and serializes binary PDB type records can
use the field in the Yaml as the source of the switch.

Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDumper.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h
    llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
    llvm/trunk/lib/DebugInfo/CodeView/TypeDumper.cpp
    llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
    llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp
    llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.cpp
    llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.h

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDumper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDumper.h?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDumper.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeDumper.h Wed Aug 31 18:14:31 2016
@@ -68,7 +68,8 @@ public:
 
   /// Paired begin/end actions for all types. Receives all record data,
   /// including the fixed-length record prefix.
-  Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
+  Expected<TypeLeafKind>
+  visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
   Error visitTypeEnd(const CVRecord<TypeLeafKind> &Record) override;
 
 #define TYPE_RECORD(EnumName, EnumVal, Name)                                   \

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h Wed Aug 31 18:14:31 2016
@@ -40,12 +40,16 @@ public:
     return Error::success();
   }
 
-  virtual Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override {
+  virtual Expected<TypeLeafKind>
+  visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override {
+    TypeLeafKind Kind = Record.Type;
     for (auto Visitor : Pipeline) {
-      if (auto EC = Visitor->visitTypeBegin(Record))
-        return EC;
+      if (auto ExpectedKind = Visitor->visitTypeBegin(Record))
+        Kind = *ExpectedKind;
+      else
+        return ExpectedKind.takeError();
     }
-    return Error::success();
+    return Kind;
   }
   virtual Error visitTypeEnd(const CVRecord<TypeLeafKind> &Record) override {
     for (auto Visitor : Pipeline) {

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h Wed Aug 31 18:14:31 2016
@@ -33,9 +33,11 @@ public:
   }
 
   /// Paired begin/end actions for all types. Receives all record data,
-  /// including the fixed-length record prefix.
-  virtual Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
-    return Error::success();
+  /// including the fixed-length record prefix.  visitTypeBegin() should return
+  /// the type of the Record, or an error if it cannot be determined.
+  virtual Expected<TypeLeafKind>
+  visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
+    return Record.Type;
   }
   virtual Error visitTypeEnd(const CVRecord<TypeLeafKind> &Record) {
     return Error::success();

Modified: llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CVTypeVisitor.cpp Wed Aug 31 18:14:31 2016
@@ -75,10 +75,13 @@ static Error visitKnownRecord(const CVRe
 }
 
 Error CVTypeVisitor::visitTypeRecord(const CVRecord<TypeLeafKind> &Record) {
-  if (auto EC = Callbacks.visitTypeBegin(Record))
-    return EC;
+  TypeLeafKind Kind;
+  if (auto ExpectedKind = Callbacks.visitTypeBegin(Record))
+    Kind = *ExpectedKind;
+  else
+    return ExpectedKind.takeError();
 
-  switch (Record.Type) {
+  switch (Kind) {
   default:
     if (auto EC = Callbacks.visitUnknownType(Record))
       return EC;
@@ -133,8 +136,9 @@ Error CVTypeVisitor::visitFieldListMembe
     if (!ExpectedRecord)                                                       \
       return ExpectedRecord.takeError();                                       \
     auto &Record = *ExpectedRecord;                                            \
-    if (auto EC = Callbacks.visitTypeBegin(Record))                            \
-      return EC;                                                               \
+    auto ExpectedKind = Callbacks.visitTypeBegin(Record);                      \
+    if (!ExpectedKind || *ExpectedKind != Leaf)                                \
+      return ExpectedKind.takeError();                                         \
     if (auto EC = visitKnownRecord<Name##Record>(Record, Callbacks))           \
       return EC;                                                               \
     if (auto EC = Callbacks.visitTypeEnd(Record))                              \

Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeDumper.cpp?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeDumper.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeDumper.cpp Wed Aug 31 18:14:31 2016
@@ -203,7 +203,8 @@ static StringRef getLeafTypeName(TypeLea
   return "UnknownLeaf";
 }
 
-Error CVTypeDumper::visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
+Expected<TypeLeafKind>
+CVTypeDumper::visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
   // Reset Name to the empty string. If the visitor sets it, we know it.
   Name = "";
 
@@ -223,7 +224,7 @@ Error CVTypeDumper::visitTypeBegin(const
     assert(!IsInFieldList);
     IsInFieldList = true;
   }
-  return Error::success();
+  return Record.Type;
 }
 
 Error CVTypeDumper::visitTypeEnd(const CVRecord<TypeLeafKind> &Record) {

Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeStreamMerger.cpp Wed Aug 31 18:14:31 2016
@@ -70,7 +70,8 @@ public:
 
   Error visitUnknownType(const CVRecord<TypeLeafKind> &Record) override;
 
-  Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
+  Expected<TypeLeafKind>
+  visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
   Error visitTypeEnd(const CVRecord<TypeLeafKind> &Record) override;
 
   bool mergeStream(const CVTypeArray &Types);
@@ -123,13 +124,14 @@ private:
 
 } // end anonymous namespace
 
-Error TypeStreamMerger::visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) {
+Expected<TypeLeafKind>
+TypeStreamMerger::visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) {
   if (Rec.Type == TypeLeafKind::LF_FIELDLIST) {
     assert(!IsInFieldList);
     IsInFieldList = true;
   } else
     BeginIndexMapSize = IndexMap.size();
-  return Error::success();
+  return Rec.Type;
 }
 
 Error TypeStreamMerger::visitTypeEnd(const CVRecord<TypeLeafKind> &Rec) {

Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/TpiStream.cpp Wed Aug 31 18:14:31 2016
@@ -121,10 +121,11 @@ public:
     return verify(Rec);
   }
 
-  Error visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) override {
+  Expected<TypeLeafKind>
+  visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) override {
     ++Index;
     RawRecord = &Rec;
-    return Error::success();
+    return Rec.Type;
   }
 
 private:

Modified: llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.cpp?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.cpp Wed Aug 31 18:14:31 2016
@@ -508,9 +508,13 @@ void ScalarEnumerationTraits<TypeLeafKin
 }
 }
 
-Error llvm::codeview::yaml::YamlTypeDumperCallbacks::visitTypeBegin(
+Expected<TypeLeafKind>
+llvm::codeview::yaml::YamlTypeDumperCallbacks::visitTypeBegin(
     const CVRecord<TypeLeafKind> &CVR) {
+  // When we're outputting, `CVR.Type` already has the right value in it.  But
+  // when we're inputting, we need to read the value.  Since `CVR.Type` is const
+  // we do it into a temp variable.
   TypeLeafKind K = CVR.Type;
   YamlIO.mapRequired("Kind", K);
-  return Error::success();
+  return K;
 }

Modified: llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.h?rev=280307&r1=280306&r2=280307&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.h (original)
+++ llvm/trunk/tools/llvm-pdbdump/CodeViewYaml.h Wed Aug 31 18:14:31 2016
@@ -21,7 +21,8 @@ class YamlTypeDumperCallbacks : public T
 public:
   YamlTypeDumperCallbacks(llvm::yaml::IO &IO) : YamlIO(IO) {}
 
-  virtual Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
+  virtual Expected<TypeLeafKind>
+  visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
 
 #define TYPE_RECORD(EnumName, EnumVal, Name)                                   \
   Error visitKnownRecord(const CVRecord<TypeLeafKind> &CVR,                    \




More information about the llvm-commits mailing list