[llvm] r290000 - Resubmit "[CodeView] Hook CodeViewRecordIO for reading/writing symbols."

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 16 14:48:15 PST 2016


Author: zturner
Date: Fri Dec 16 16:48:14 2016
New Revision: 290000

URL: http://llvm.org/viewvc/llvm-project?rev=290000&view=rev
Log:
Resubmit "[CodeView] Hook CodeViewRecordIO for reading/writing symbols."

The original patch was broken due to some undefined behavior
as well as warnings that were triggering -Werror.

Added:
    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h
    llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp
    llvm/trunk/lib/DebugInfo/CodeView/SymbolSerializer.cpp
Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h
    llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt
    llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
    llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp
    llvm/trunk/lib/MC/MCCodeView.cpp
    llvm/trunk/test/DebugInfo/PDB/pdb-yaml-symbols.test
    llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test
    llvm/trunk/tools/llvm-pdbdump/YamlSymbolDumper.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/CodeView.h Fri Dec 16 16:48:14 2016
@@ -535,7 +535,7 @@ enum class ThunkOrdinal : uint8_t {
   BranchIsland
 };
 
-enum class TrampolineType { TrampIncremental, BranchIsland };
+enum class TrampolineType : uint16_t { TrampIncremental, BranchIsland };
 
 // These values correspond to the CV_SourceChksum_t enumeration.
 enum class FileChecksumKind : uint8_t { None, MD5, SHA1, SHA256 };

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/CodeViewRecordIO.h Fri Dec 16 16:48:14 2016
@@ -46,6 +46,17 @@ public:
 
   uint32_t maxFieldLength() const;
 
+  template <typename T> Error mapObject(T &Value) {
+    if (isWriting())
+      return Writer->writeObject(Value);
+
+    const T *ValuePtr;
+    if (auto EC = Reader->readObject(ValuePtr))
+      return EC;
+    Value = *ValuePtr;
+    return Error::success();
+  }
+
   template <typename T> Error mapInteger(T &Value) {
     if (isWriting())
       return Writer->writeInteger(Value);
@@ -75,6 +86,8 @@ public:
   Error mapStringZ(StringRef &Value);
   Error mapGuid(StringRef &Guid);
 
+  Error mapStringZVectorZ(std::vector<StringRef> &Value);
+
   template <typename SizeType, typename T, typename ElementMapper>
   Error mapVectorN(T &Items, const ElementMapper &Mapper) {
     SizeType Size;
@@ -121,6 +134,7 @@ public:
   }
 
   Error mapByteVectorTail(ArrayRef<uint8_t> &Bytes);
+  Error mapByteVectorTail(std::vector<uint8_t> &Bytes);
 
   Error skipPadding();
 

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h Fri Dec 16 16:48:14 2016
@@ -12,6 +12,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
+#include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h"
 #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
 #include "llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h"
 #include "llvm/DebugInfo/MSF/ByteStream.h"
@@ -22,41 +23,50 @@ namespace llvm {
 namespace codeview {
 class SymbolVisitorDelegate;
 class SymbolDeserializer : public SymbolVisitorCallbacks {
+  struct MappingInfo {
+    explicit MappingInfo(ArrayRef<uint8_t> RecordData)
+        : Stream(RecordData), Reader(Stream), Mapping(Reader) {}
+
+    msf::ByteStream Stream;
+    msf::StreamReader Reader;
+    SymbolRecordMapping Mapping;
+  };
+
 public:
   explicit SymbolDeserializer(SymbolVisitorDelegate *Delegate)
       : Delegate(Delegate) {}
 
+  Error visitSymbolBegin(CVSymbol &Record) override {
+    assert(!Mapping && "Already in a symbol mapping!");
+    Mapping = llvm::make_unique<MappingInfo>(Record.content());
+    return Mapping->Mapping.visitSymbolBegin(Record);
+  }
+  Error visitSymbolEnd(CVSymbol &Record) override {
+    assert(Mapping && "Not in a symbol mapping!");
+    auto EC = Mapping->Mapping.visitSymbolEnd(Record);
+    Mapping.reset();
+    return EC;
+  }
+
 #define SYMBOL_RECORD(EnumName, EnumVal, Name)                                 \
   Error visitKnownRecord(CVSymbol &CVR, Name &Record) override {               \
-    return defaultVisitKnownRecord(CVR, Record);                               \
+    return visitKnownRecordImpl(CVR, Record);                                  \
   }
 #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
 #include "CVSymbolTypes.def"
 
-protected:
-  template <typename T>
-  Error deserializeRecord(msf::StreamReader &Reader, SymbolKind Kind,
-                          T &Record) const {
-    uint32_t RecordOffset = Delegate ? Delegate->getRecordOffset(Reader) : 0;
-    SymbolRecordKind RK = static_cast<SymbolRecordKind>(Kind);
-    auto ExpectedRecord = T::deserialize(RK, RecordOffset, Reader);
-    if (!ExpectedRecord)
-      return ExpectedRecord.takeError();
-    Record = std::move(*ExpectedRecord);
-    return Error::success();
-  }
-
 private:
-  template <typename T>
-  Error defaultVisitKnownRecord(CVSymbol &CVR, T &Record) {
-    msf::ByteStream S(CVR.content());
-    msf::StreamReader SR(S);
-    if (auto EC = deserializeRecord(SR, CVR.Type, Record))
+  template <typename T> Error visitKnownRecordImpl(CVSymbol &CVR, T &Record) {
+
+    Record.RecordOffset =
+        Delegate ? Delegate->getRecordOffset(Mapping->Reader) : 0;
+    if (auto EC = Mapping->Mapping.visitKnownRecord(CVR, Record))
       return EC;
     return Error::success();
   }
 
   SymbolVisitorDelegate *Delegate;
+  std::unique_ptr<MappingInfo> Mapping;
 };
 }
 }

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecord.h Fri Dec 16 16:48:14 2016
@@ -29,10 +29,6 @@
 namespace llvm {
 namespace codeview {
 
-using support::ulittle16_t;
-using support::ulittle32_t;
-using support::little32_t;
-
 class SymbolRecord {
 protected:
   explicit SymbolRecord(SymbolRecordKind Kind) : Kind(Kind) {}
@@ -47,181 +43,100 @@ private:
 // S_GPROC32, S_LPROC32, S_GPROC32_ID, S_LPROC32_ID, S_LPROC32_DPC or
 // S_LPROC32_DPC_ID
 class ProcSym : public SymbolRecord {
-public:
-  struct Hdr {
-    ulittle32_t PtrParent;
-    ulittle32_t PtrEnd;
-    ulittle32_t PtrNext;
-    ulittle32_t CodeSize;
-    ulittle32_t DbgStart;
-    ulittle32_t DbgEnd;
-    TypeIndex FunctionType;
-    ulittle32_t CodeOffset;
-    ulittle16_t Segment;
-    uint8_t Flags; // ProcSymFlags enum
-                   // Name: The null-terminated name follows.
-  };
+  static constexpr uint32_t RelocationOffset = 32;
 
+public:
   explicit ProcSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  ProcSym(SymbolRecordKind Kind, uint32_t RecordOffset, const Hdr *H,
-          StringRef Name)
-      : SymbolRecord(Kind), RecordOffset(RecordOffset), Header(*H), Name(Name) {
-  }
-
-  static Expected<ProcSym> deserialize(SymbolRecordKind Kind,
-                                       uint32_t RecordOffset,
-                                       msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
-
-    return ProcSym(Kind, RecordOffset, H, Name);
-  }
+  ProcSym(SymbolRecordKind Kind, uint32_t RecordOffset)
+      : SymbolRecord(Kind), RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, CodeOffset);
+    return RecordOffset + RelocationOffset;
   }
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  uint32_t Parent = 0;
+  uint32_t End = 0;
+  uint32_t Next = 0;
+  uint32_t CodeSize = 0;
+  uint32_t DbgStart = 0;
+  uint32_t DbgEnd = 0;
+  TypeIndex FunctionType;
+  uint32_t CodeOffset = 0;
+  uint16_t Segment = 0;
+  ProcSymFlags Flags = ProcSymFlags::None;
   StringRef Name;
+
+  uint32_t RecordOffset = 0;
 };
 
 // S_THUNK32
 class Thunk32Sym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t Parent;
-    ulittle32_t End;
-    ulittle32_t Next;
-    ulittle32_t Off;
-    ulittle16_t Seg;
-    ulittle16_t Len;
-    uint8_t Ord; // ThunkOrdinal enumeration
-                 // Name: The null-terminated name follows.
-                 // Variant portion of thunk
-  };
-
   explicit Thunk32Sym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  Thunk32Sym(SymbolRecordKind Kind, uint32_t RecordOffset, const Hdr *H,
-             StringRef Name, ArrayRef<uint8_t> VariantData)
-      : SymbolRecord(Kind), RecordOffset(RecordOffset), Header(*H), Name(Name),
-        VariantData(VariantData) {}
-
-  static Expected<Thunk32Sym> deserialize(SymbolRecordKind Kind,
-                                          uint32_t RecordOffset,
-                                          msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    ArrayRef<uint8_t> VariantData;
-
-    CV_DESERIALIZE(Reader, H, Name, CV_ARRAY_FIELD_TAIL(VariantData));
-
-    return Thunk32Sym(Kind, RecordOffset, H, Name, VariantData);
-  }
+  Thunk32Sym(SymbolRecordKind Kind, uint32_t RecordOffset)
+      : SymbolRecord(Kind), RecordOffset(RecordOffset) {}
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  uint32_t Parent;
+  uint32_t End;
+  uint32_t Next;
+  uint32_t Offset;
+  uint16_t Segment;
+  uint16_t Length;
+  ThunkOrdinal Thunk;
   StringRef Name;
   ArrayRef<uint8_t> VariantData;
+
+  uint32_t RecordOffset;
 };
 
 // S_TRAMPOLINE
 class TrampolineSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle16_t Type; // TrampolineType enum
-    ulittle16_t Size;
-    ulittle32_t ThunkOff;
-    ulittle32_t TargetOff;
-    ulittle16_t ThunkSection;
-    ulittle16_t TargetSection;
-  };
-
   explicit TrampolineSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  TrampolineSym(SymbolRecordKind Kind, uint32_t RecordOffset, const Hdr *H)
-      : SymbolRecord(Kind), RecordOffset(RecordOffset), Header(*H) {}
-
-  static Expected<TrampolineSym> deserialize(SymbolRecordKind Kind,
-                                             uint32_t RecordOffset,
-                                             msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-
-    CV_DESERIALIZE(Reader, H);
+  TrampolineSym(SymbolRecordKind Kind, uint32_t RecordOffset)
+      : SymbolRecord(Kind), RecordOffset(RecordOffset) {}
 
-    return TrampolineSym(Kind, RecordOffset, H);
-  }
+  TrampolineType Type;
+  uint16_t Size;
+  uint32_t ThunkOffset;
+  uint32_t TargetOffset;
+  uint16_t ThunkSection;
+  uint16_t TargetSection;
 
   uint32_t RecordOffset;
-  Hdr Header;
 };
 
 // S_SECTION
 class SectionSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle16_t SectionNumber;
-    uint8_t Alignment;
-    uint8_t Reserved; // Must be 0
-    ulittle32_t Rva;
-    ulittle32_t Length;
-    ulittle32_t Characteristics;
-    // Name: The null-terminated name follows.
-  };
-
   explicit SectionSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  SectionSym(SymbolRecordKind Kind, uint32_t RecordOffset, const Hdr *H,
-             StringRef Name)
-      : SymbolRecord(Kind), RecordOffset(RecordOffset), Header(*H), Name(Name) {
-  }
-
-  static Expected<SectionSym> deserialize(SymbolRecordKind Kind,
-                                          uint32_t RecordOffset,
-                                          msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-
-    CV_DESERIALIZE(Reader, H, Name);
+  SectionSym(SymbolRecordKind Kind, uint32_t RecordOffset)
+      : SymbolRecord(Kind), RecordOffset(RecordOffset) {}
 
-    return SectionSym(Kind, RecordOffset, H, Name);
-  }
+  uint16_t SectionNumber;
+  uint8_t Alignment;
+  uint32_t Rva;
+  uint32_t Length;
+  uint32_t Characteristics;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 // S_COFFGROUP
 class CoffGroupSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t Size;
-    ulittle32_t Characteristics;
-    ulittle32_t Offset;
-    ulittle16_t Segment;
-    // Name: The null-terminated name follows.
-  };
-
   explicit CoffGroupSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  CoffGroupSym(SymbolRecordKind Kind, uint32_t RecordOffset, const Hdr *H,
-               StringRef Name)
-      : SymbolRecord(Kind), RecordOffset(RecordOffset), Header(*H), Name(Name) {
-  }
-
-  static Expected<CoffGroupSym> deserialize(SymbolRecordKind Kind,
-                                            uint32_t RecordOffset,
-                                            msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-
-    CV_DESERIALIZE(Reader, H, Name);
+  CoffGroupSym(SymbolRecordKind Kind, uint32_t RecordOffset)
+      : SymbolRecord(Kind), RecordOffset(RecordOffset) {}
 
-    return CoffGroupSym(Kind, RecordOffset, H, Name);
-  }
+  uint32_t Size;
+  uint32_t Characteristics;
+  uint32_t Offset;
+  uint16_t Segment;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 class ScopeEndSym : public SymbolRecord {
@@ -230,40 +145,17 @@ public:
   ScopeEndSym(SymbolRecordKind Kind, uint32_t RecordOffset)
       : SymbolRecord(Kind), RecordOffset(RecordOffset) {}
 
-  static Expected<ScopeEndSym> deserialize(SymbolRecordKind Kind,
-                                           uint32_t RecordOffset,
-                                           msf::StreamReader &Reader) {
-    return ScopeEndSym(Kind, RecordOffset);
-  }
   uint32_t RecordOffset;
 };
 
 class CallerSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t Count;
-  };
-
   explicit CallerSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  CallerSym(SymbolRecordKind Kind, uint32_t RecordOffset, const Hdr *Header,
-            ArrayRef<TypeIndex> Indices)
-      : SymbolRecord(Kind), RecordOffset(RecordOffset), Header(*Header),
-        Indices(Indices) {}
-
-  static Expected<CallerSym> deserialize(SymbolRecordKind Kind,
-                                         uint32_t RecordOffset,
-                                         msf::StreamReader &Reader) {
-    const Hdr *Header;
-    ArrayRef<TypeIndex> Indices;
-
-    CV_DESERIALIZE(Reader, Header, CV_ARRAY_FIELD_N(Indices, Header->Count));
-
-    return CallerSym(Kind, RecordOffset, Header, Indices);
-  }
+  CallerSym(SymbolRecordKind Kind, uint32_t RecordOffset)
+      : SymbolRecord(Kind), RecordOffset(RecordOffset) {}
 
+  std::vector<TypeIndex> Indices;
   uint32_t RecordOffset;
-  Hdr Header;
-  ArrayRef<TypeIndex> Indices;
 };
 
 struct BinaryAnnotationIterator {
@@ -447,404 +339,219 @@ private:
 // S_INLINESITE
 class InlineSiteSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t PtrParent;
-    ulittle32_t PtrEnd;
-    TypeIndex Inlinee;
-    // BinaryAnnotations
-  };
-
   explicit InlineSiteSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  InlineSiteSym(uint32_t RecordOffset, const Hdr *H,
-                ArrayRef<uint8_t> Annotations)
+  InlineSiteSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::InlineSiteSym),
-        RecordOffset(RecordOffset), Header(*H), Annotations(Annotations) {}
-
-  static Expected<InlineSiteSym> deserialize(SymbolRecordKind Kind,
-                                             uint32_t RecordOffset,
-                                             msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    ArrayRef<uint8_t> Annotations;
-    CV_DESERIALIZE(Reader, H, CV_ARRAY_FIELD_TAIL(Annotations));
-
-    return InlineSiteSym(RecordOffset, H, Annotations);
-  }
+        RecordOffset(RecordOffset) {}
 
   llvm::iterator_range<BinaryAnnotationIterator> annotations() const {
-    return llvm::make_range(BinaryAnnotationIterator(Annotations),
+    return llvm::make_range(BinaryAnnotationIterator(AnnotationData),
                             BinaryAnnotationIterator());
   }
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  uint32_t Parent;
+  uint32_t End;
+  TypeIndex Inlinee;
+  std::vector<uint8_t> AnnotationData;
 
-private:
-  ArrayRef<uint8_t> Annotations;
+  uint32_t RecordOffset;
 };
 
 // S_PUB32
 class PublicSym32 : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t Index; // Type index, or Metadata token if a managed symbol
-    ulittle32_t Off;
-    ulittle16_t Seg;
-    // Name: The null-terminated name follows.
-  };
-
   explicit PublicSym32(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  PublicSym32(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::PublicSym32), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<PublicSym32> deserialize(SymbolRecordKind Kind,
-                                           uint32_t RecordOffset,
-                                           msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
-
-    return PublicSym32(RecordOffset, H, Name);
-  }
+  explicit PublicSym32(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::PublicSym32),
+        RecordOffset(RecordOffset) {}
+
+  uint32_t Index;
+  uint32_t Offset;
+  uint16_t Segment;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 // S_REGISTER
 class RegisterSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t Index;    // Type index or Metadata token
-    ulittle16_t Register; // RegisterId enumeration
-    // Name: The null-terminated name follows.
-  };
-
   explicit RegisterSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  RegisterSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::RegisterSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<RegisterSym> deserialize(SymbolRecordKind Kind,
-                                           uint32_t RecordOffset,
-                                           msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
+  RegisterSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::RegisterSym),
+        RecordOffset(RecordOffset) {}
 
-    return RegisterSym(RecordOffset, H, Name);
-  }
+  uint32_t Index;
+  RegisterId Register;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 // S_PROCREF, S_LPROCREF
 class ProcRefSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t SumName;   // SUC of the name (?)
-    ulittle32_t SymOffset; // Offset of actual symbol in $$Symbols
-    ulittle16_t Mod;       // Module containing the actual symbol
-                           // Name:  The null-terminated name follows.
-  };
-
   explicit ProcRefSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  ProcRefSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::ProcRefSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<ProcRefSym> deserialize(SymbolRecordKind Kind,
-                                          uint32_t RecordOffset,
-                                          msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
-
-    return ProcRefSym(RecordOffset, H, Name);
+  explicit ProcRefSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::ProcRefSym), RecordOffset(RecordOffset) {
   }
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  uint32_t SumName;
+  uint32_t SymOffset;
+  uint16_t Module;
   StringRef Name;
+
+  uint32_t RecordOffset;
 };
 
 // S_LOCAL
 class LocalSym : public SymbolRecord {
 public:
-  struct Hdr {
-    TypeIndex Type;
-    ulittle16_t Flags; // LocalSymFlags enum
-                       // Name: The null-terminated name follows.
-  };
-
   explicit LocalSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  LocalSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::LocalSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<LocalSym> deserialize(SymbolRecordKind Kind,
-                                        uint32_t RecordOffset,
-                                        msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
+  explicit LocalSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::LocalSym), RecordOffset(RecordOffset) {}
 
-    return LocalSym(RecordOffset, H, Name);
-  }
+  TypeIndex Type;
+  LocalSymFlags Flags;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 struct LocalVariableAddrRange {
-  ulittle32_t OffsetStart;
-  ulittle16_t ISectStart;
-  ulittle16_t Range;
+  uint32_t OffsetStart;
+  uint16_t ISectStart;
+  uint16_t Range;
 };
 
 struct LocalVariableAddrGap {
-  ulittle16_t GapStartOffset;
-  ulittle16_t Range;
+  uint16_t GapStartOffset;
+  uint16_t Range;
 };
 
 enum : uint16_t { MaxDefRange = 0xf000 };
 
 // S_DEFRANGE
 class DefRangeSym : public SymbolRecord {
-public:
-  struct Hdr {
-    ulittle32_t Program;
-    LocalVariableAddrRange Range;
-    // LocalVariableAddrGap Gaps[];
-  };
+  static constexpr uint32_t RelocationOffset = 8;
 
+public:
   explicit DefRangeSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  DefRangeSym(uint32_t RecordOffset, const Hdr *H,
-              ArrayRef<LocalVariableAddrGap> Gaps)
-      : SymbolRecord(SymbolRecordKind::DefRangeSym), RecordOffset(RecordOffset),
-        Header(*H), Gaps(Gaps) {}
-
-  static Expected<DefRangeSym> deserialize(SymbolRecordKind Kind,
-                                           uint32_t RecordOffset,
-                                           msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    ArrayRef<LocalVariableAddrGap> Gaps;
-    CV_DESERIALIZE(Reader, H, CV_ARRAY_FIELD_TAIL(Gaps));
-
-    return DefRangeSym(RecordOffset, H, Gaps);
-  }
+  explicit DefRangeSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::DefRangeSym),
+        RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, Range);
+    return RecordOffset + RelocationOffset;
   }
 
+  uint32_t Program;
+  LocalVariableAddrRange Range;
+  std::vector<LocalVariableAddrGap> Gaps;
+
   uint32_t RecordOffset;
-  Hdr Header;
-  ArrayRef<LocalVariableAddrGap> Gaps;
 };
 
 // S_DEFRANGE_SUBFIELD
 class DefRangeSubfieldSym : public SymbolRecord {
+  static constexpr uint32_t RelocationOffset = 12;
+
 public:
-  struct Hdr {
-    ulittle32_t Program;
-    ulittle16_t OffsetInParent;
-    LocalVariableAddrRange Range;
-    // LocalVariableAddrGap Gaps[];
-  };
   explicit DefRangeSubfieldSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  DefRangeSubfieldSym(uint32_t RecordOffset, const Hdr *H,
-                      ArrayRef<LocalVariableAddrGap> Gaps)
+  DefRangeSubfieldSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::DefRangeSubfieldSym),
-        RecordOffset(RecordOffset), Header(*H), Gaps(Gaps) {}
-
-  static Expected<DefRangeSubfieldSym> deserialize(SymbolRecordKind Kind,
-                                                   uint32_t RecordOffset,
-                                                   msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    ArrayRef<LocalVariableAddrGap> Gaps;
-    CV_DESERIALIZE(Reader, H, CV_ARRAY_FIELD_TAIL(Gaps));
-
-    return DefRangeSubfieldSym(RecordOffset, H, Gaps);
-  }
+        RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, Range);
+    return RecordOffset + RelocationOffset;
   }
 
+  uint32_t Program;
+  uint16_t OffsetInParent;
+  LocalVariableAddrRange Range;
+  std::vector<LocalVariableAddrGap> Gaps;
+
   uint32_t RecordOffset;
-  Hdr Header;
-  ArrayRef<LocalVariableAddrGap> Gaps;
 };
 
 // S_DEFRANGE_REGISTER
 class DefRangeRegisterSym : public SymbolRecord {
 public:
-  struct Hdr {
+  struct Header {
     ulittle16_t Register;
     ulittle16_t MayHaveNoName;
-    LocalVariableAddrRange Range;
-    // LocalVariableAddrGap Gaps[];
   };
-
   explicit DefRangeRegisterSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  DefRangeRegisterSym(uint32_t RecordOffset, const Hdr *H,
-                      ArrayRef<LocalVariableAddrGap> Gaps)
+  DefRangeRegisterSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::DefRangeRegisterSym),
-        RecordOffset(RecordOffset), Header(*H), Gaps(Gaps) {}
+        RecordOffset(RecordOffset) {}
 
-  DefRangeRegisterSym(uint16_t Register, uint16_t MayHaveNoName,
-                      ArrayRef<LocalVariableAddrGap> Gaps)
-      : SymbolRecord(SymbolRecordKind::DefRangeRegisterSym), RecordOffset(0),
-        Gaps(Gaps) {
-    Header.Register = Register;
-    Header.MayHaveNoName = MayHaveNoName;
-    Header.Range = {};
-  }
-
-  static Expected<DefRangeRegisterSym> deserialize(SymbolRecordKind Kind,
-                                                   uint32_t RecordOffset,
-                                                   msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    ArrayRef<LocalVariableAddrGap> Gaps;
-    CV_DESERIALIZE(Reader, H, CV_ARRAY_FIELD_TAIL(Gaps));
+  uint32_t getRelocationOffset() const { return RecordOffset + sizeof(Header); }
 
-    return DefRangeRegisterSym(RecordOffset, H, Gaps);
-  }
-
-  uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, Range);
-  }
+  Header Hdr;
+  LocalVariableAddrRange Range;
+  std::vector<LocalVariableAddrGap> Gaps;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  ArrayRef<LocalVariableAddrGap> Gaps;
 };
 
 // S_DEFRANGE_SUBFIELD_REGISTER
 class DefRangeSubfieldRegisterSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle16_t Register; // Register to which the variable is relative
+  struct Header {
+    ulittle16_t Register;
     ulittle16_t MayHaveNoName;
     ulittle32_t OffsetInParent;
-    LocalVariableAddrRange Range;
-    // LocalVariableAddrGap Gaps[];
   };
-
   explicit DefRangeSubfieldRegisterSym(SymbolRecordKind Kind)
       : SymbolRecord(Kind) {}
-  DefRangeSubfieldRegisterSym(uint32_t RecordOffset, const Hdr *H,
-                              ArrayRef<LocalVariableAddrGap> Gaps)
+  DefRangeSubfieldRegisterSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::DefRangeSubfieldRegisterSym),
-        RecordOffset(RecordOffset), Header(*H), Gaps(Gaps) {}
+        RecordOffset(RecordOffset) {}
 
-  DefRangeSubfieldRegisterSym(uint16_t Register, uint16_t MayHaveNoName,
-                              uint32_t OffsetInParent,
-                              ArrayRef<LocalVariableAddrGap> Gaps)
-      : SymbolRecord(SymbolRecordKind::DefRangeSubfieldRegisterSym),
-        RecordOffset(0), Gaps(Gaps) {
-    Header.Register = Register;
-    Header.MayHaveNoName = MayHaveNoName;
-    Header.OffsetInParent = OffsetInParent;
-    Header.Range = {};
-  }
-
-  static Expected<DefRangeSubfieldRegisterSym>
-  deserialize(SymbolRecordKind Kind, uint32_t RecordOffset,
-              msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    ArrayRef<LocalVariableAddrGap> Gaps;
-    CV_DESERIALIZE(Reader, H, CV_ARRAY_FIELD_TAIL(Gaps));
-
-    return DefRangeSubfieldRegisterSym(RecordOffset, H, Gaps);
-  }
+  uint32_t getRelocationOffset() const { return RecordOffset + sizeof(Header); }
 
-  uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, Range);
-  }
+  Header Hdr;
+  LocalVariableAddrRange Range;
+  std::vector<LocalVariableAddrGap> Gaps;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  ArrayRef<LocalVariableAddrGap> Gaps;
 };
 
 // S_DEFRANGE_FRAMEPOINTER_REL
 class DefRangeFramePointerRelSym : public SymbolRecord {
-public:
-  struct Hdr {
-    little32_t Offset; // Offset from the frame pointer register
-    LocalVariableAddrRange Range;
-    // LocalVariableAddrGap Gaps[];
-  };
+  static constexpr uint32_t RelocationOffset = 8;
 
+public:
   explicit DefRangeFramePointerRelSym(SymbolRecordKind Kind)
       : SymbolRecord(Kind) {}
-  DefRangeFramePointerRelSym(uint32_t RecordOffset, const Hdr *H,
-                             ArrayRef<LocalVariableAddrGap> Gaps)
+  DefRangeFramePointerRelSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::DefRangeFramePointerRelSym),
-        RecordOffset(RecordOffset), Header(*H), Gaps(Gaps) {}
-
-  static Expected<DefRangeFramePointerRelSym>
-  deserialize(SymbolRecordKind Kind, uint32_t RecordOffset,
-              msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    ArrayRef<LocalVariableAddrGap> Gaps;
-    CV_DESERIALIZE(Reader, H, CV_ARRAY_FIELD_TAIL(Gaps));
-
-    return DefRangeFramePointerRelSym(RecordOffset, H, Gaps);
-  }
+        RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, Range);
+    return RecordOffset + RelocationOffset;
   }
 
+  int32_t Offset;
+  LocalVariableAddrRange Range;
+  std::vector<LocalVariableAddrGap> Gaps;
+
   uint32_t RecordOffset;
-  Hdr Header;
-  ArrayRef<LocalVariableAddrGap> Gaps;
 };
 
 // S_DEFRANGE_REGISTER_REL
 class DefRangeRegisterRelSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle16_t BaseRegister;
+  struct Header {
+    ulittle16_t Register;
     ulittle16_t Flags;
     little32_t BasePointerOffset;
-    LocalVariableAddrRange Range;
-    // LocalVariableAddrGap Gaps[];
   };
-
   explicit DefRangeRegisterRelSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  DefRangeRegisterRelSym(uint32_t RecordOffset, const Hdr *H,
-                         ArrayRef<LocalVariableAddrGap> Gaps)
+  explicit DefRangeRegisterRelSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::DefRangeRegisterRelSym),
-        RecordOffset(RecordOffset), Header(*H), Gaps(Gaps) {}
-
-  DefRangeRegisterRelSym(uint16_t BaseRegister, uint16_t Flags,
-                         int32_t BasePointerOffset,
-                         ArrayRef<LocalVariableAddrGap> Gaps)
-      : SymbolRecord(SymbolRecordKind::DefRangeRegisterRelSym), RecordOffset(0),
-        Gaps(Gaps) {
-    Header.BaseRegister = BaseRegister;
-    Header.Flags = Flags;
-    Header.BasePointerOffset = BasePointerOffset;
-    Header.Range = {};
-  }
-
-  static Expected<DefRangeRegisterRelSym>
-  deserialize(SymbolRecordKind Kind, uint32_t RecordOffset,
-              msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    ArrayRef<LocalVariableAddrGap> Gaps;
-    CV_DESERIALIZE(Reader, H, CV_ARRAY_FIELD_TAIL(Gaps));
-
-    return DefRangeRegisterRelSym(RecordOffset, H, Gaps);
-  }
+        RecordOffset(RecordOffset) {}
 
   // The flags implement this notional bitfield:
   //   uint16_t IsSubfield : 1;
@@ -855,642 +562,379 @@ public:
     OffsetInParentShift = 4,
   };
 
-  bool hasSpilledUDTMember() const { return Header.Flags & IsSubfieldFlag; }
-  uint16_t offsetInParent() const { return Header.Flags >> OffsetInParentShift; }
+  bool hasSpilledUDTMember() const { return Hdr.Flags & IsSubfieldFlag; }
+  uint16_t offsetInParent() const { return Hdr.Flags >> OffsetInParentShift; }
 
-  uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, Range);
-  }
+  uint32_t getRelocationOffset() const { return RecordOffset + sizeof(Header); }
+
+  Header Hdr;
+  LocalVariableAddrRange Range;
+  std::vector<LocalVariableAddrGap> Gaps;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  ArrayRef<LocalVariableAddrGap> Gaps;
 };
 
 // S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE
 class DefRangeFramePointerRelFullScopeSym : public SymbolRecord {
 public:
-  struct Hdr {
-    little32_t Offset; // Offset from the frame pointer register
-  };
-
   explicit DefRangeFramePointerRelFullScopeSym(SymbolRecordKind Kind)
       : SymbolRecord(Kind) {}
-  DefRangeFramePointerRelFullScopeSym(uint32_t RecordOffset, const Hdr *H)
+  explicit DefRangeFramePointerRelFullScopeSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::DefRangeFramePointerRelFullScopeSym),
-        RecordOffset(RecordOffset), Header(*H) {}
+        RecordOffset(RecordOffset) {}
 
-  static Expected<DefRangeFramePointerRelFullScopeSym>
-  deserialize(SymbolRecordKind Kind, uint32_t RecordOffset,
-              msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    CV_DESERIALIZE(Reader, H);
-
-    return DefRangeFramePointerRelFullScopeSym(RecordOffset, H);
-  }
+  int32_t Offset;
 
   uint32_t RecordOffset;
-  Hdr Header;
 };
 
 // S_BLOCK32
 class BlockSym : public SymbolRecord {
-public:
-  struct Hdr {
-    ulittle32_t PtrParent;
-    ulittle32_t PtrEnd;
-    ulittle32_t CodeSize;
-    ulittle32_t CodeOffset;
-    ulittle16_t Segment;
-    // Name: The null-terminated name follows.
-  };
+  static constexpr uint32_t RelocationOffset = 16;
 
+public:
   explicit BlockSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  BlockSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::BlockSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<BlockSym> deserialize(SymbolRecordKind Kind,
-                                        uint32_t RecordOffset,
-                                        msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
-
-    return BlockSym(RecordOffset, H, Name);
-  }
+  explicit BlockSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::BlockSym), RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, CodeOffset);
+    return RecordOffset + RelocationOffset;
   }
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  uint32_t Parent;
+  uint32_t End;
+  uint32_t CodeSize;
+  uint32_t CodeOffset;
+  uint16_t Segment;
   StringRef Name;
+
+  uint32_t RecordOffset;
 };
 
 // S_LABEL32
 class LabelSym : public SymbolRecord {
-public:
-  struct Hdr {
-    ulittle32_t CodeOffset;
-    ulittle16_t Segment;
-    uint8_t Flags; // CV_PROCFLAGS
-                   // Name: The null-terminated name follows.
-  };
+  static constexpr uint32_t RelocationOffset = 4;
 
+public:
   explicit LabelSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  LabelSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::LabelSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<LabelSym> deserialize(SymbolRecordKind Kind,
-                                        uint32_t RecordOffset,
-                                        msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
-
-    return LabelSym(RecordOffset, H, Name);
-  }
+  explicit LabelSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::LabelSym), RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, CodeOffset);
+    return RecordOffset + RelocationOffset;
   }
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  uint32_t CodeOffset;
+  uint16_t Segment;
+  ProcSymFlags Flags;
   StringRef Name;
+
+  uint32_t RecordOffset;
 };
 
 // S_OBJNAME
 class ObjNameSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t Signature;
-    // Name: The null-terminated name follows.
-  };
-
   explicit ObjNameSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  ObjNameSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::ObjNameSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<ObjNameSym> deserialize(SymbolRecordKind Kind,
-                                          uint32_t RecordOffset,
-                                          msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
-
-    return ObjNameSym(RecordOffset, H, Name);
+  ObjNameSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::ObjNameSym), RecordOffset(RecordOffset) {
   }
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  uint32_t Signature;
   StringRef Name;
+
+  uint32_t RecordOffset;
 };
 
 // S_ENVBLOCK
 class EnvBlockSym : public SymbolRecord {
 public:
-  struct Hdr {
-    uint8_t Reserved;
-    // Sequence of zero terminated strings.
-  };
-
   explicit EnvBlockSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  EnvBlockSym(uint32_t RecordOffset, const Hdr *H,
-              const std::vector<StringRef> &Fields)
-      : SymbolRecord(SymbolRecordKind::EnvBlockSym), RecordOffset(RecordOffset),
-        Header(*H), Fields(Fields) {}
-
-  static Expected<EnvBlockSym> deserialize(SymbolRecordKind Kind,
-                                           uint32_t RecordOffset,
-                                           msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    std::vector<StringRef> Fields;
-    CV_DESERIALIZE(Reader, H, CV_STRING_ARRAY_NULL_TERM(Fields));
+  EnvBlockSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::EnvBlockSym),
+        RecordOffset(RecordOffset) {}
 
-    return EnvBlockSym(RecordOffset, H, Fields);
-  }
+  std::vector<StringRef> Fields;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  std::vector<StringRef> Fields;
 };
 
 // S_EXPORT
 class ExportSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle16_t Ordinal;
-    ulittle16_t Flags; // ExportFlags
-                       // Name: The null-terminated name follows.
-  };
-
   explicit ExportSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  ExportSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::ExportSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<ExportSym> deserialize(SymbolRecordKind Kind,
-                                         uint32_t RecordOffset,
-                                         msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
+  ExportSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::ExportSym), RecordOffset(RecordOffset) {}
 
-    return ExportSym(RecordOffset, H, Name);
-  }
+  uint16_t Ordinal;
+  ExportFlags Flags;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 // S_FILESTATIC
 class FileStaticSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t Index;             // Type Index
-    ulittle32_t ModFilenameOffset; // Index of mod filename in string table
-    ulittle16_t Flags;             // LocalSymFlags enum
-                                   // Name: The null-terminated name follows.
-  };
-
   explicit FileStaticSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  FileStaticSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
+  FileStaticSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::FileStaticSym),
-        RecordOffset(RecordOffset), Header(*H), Name(Name) {}
-
-  static Expected<FileStaticSym> deserialize(SymbolRecordKind Kind,
-                                             uint32_t RecordOffset,
-                                             msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
+        RecordOffset(RecordOffset) {}
 
-    return FileStaticSym(RecordOffset, H, Name);
-  }
+  uint32_t Index;
+  uint32_t ModFilenameOffset;
+  LocalSymFlags Flags;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 // S_COMPILE2
 class Compile2Sym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t flags; // CompileSym2Flags enum
-    uint8_t getLanguage() const { return flags & 0xFF; }
-    unsigned short Machine; // CPUType enum
-    unsigned short VersionFrontendMajor;
-    unsigned short VersionFrontendMinor;
-    unsigned short VersionFrontendBuild;
-    unsigned short VersionBackendMajor;
-    unsigned short VersionBackendMinor;
-    unsigned short VersionBackendBuild;
-    // Version: The null-terminated version string follows.
-    // Optional block of zero terminated strings terminated with a double zero.
-  };
-
   explicit Compile2Sym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  Compile2Sym(uint32_t RecordOffset, const Hdr *H, StringRef Version)
-      : SymbolRecord(SymbolRecordKind::Compile2Sym), RecordOffset(RecordOffset),
-        Header(*H), Version(Version) {}
-
-  static Expected<Compile2Sym> deserialize(SymbolRecordKind Kind,
-                                           uint32_t RecordOffset,
-                                           msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Version;
-    CV_DESERIALIZE(Reader, H, Version);
+  Compile2Sym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::Compile2Sym),
+        RecordOffset(RecordOffset) {}
+
+  CompileSym2Flags Flags;
+  CPUType Machine;
+  uint16_t VersionFrontendMajor;
+  uint16_t VersionFrontendMinor;
+  uint16_t VersionFrontendBuild;
+  uint16_t VersionBackendMajor;
+  uint16_t VersionBackendMinor;
+  uint16_t VersionBackendBuild;
+  StringRef Version;
+  std::vector<StringRef> ExtraStrings;
 
-    return Compile2Sym(RecordOffset, H, Version);
-  }
+  uint8_t getLanguage() const { return static_cast<uint32_t>(Flags) & 0xFF; }
+  uint32_t getFlags() const { return static_cast<uint32_t>(Flags) & ~0xFF; }
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Version;
 };
 
 // S_COMPILE3
 class Compile3Sym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t flags; // CompileSym3Flags enum
-    uint8_t getLanguage() const { return flags & 0xff; }
-    ulittle16_t Machine; // CPUType enum
-    ulittle16_t VersionFrontendMajor;
-    ulittle16_t VersionFrontendMinor;
-    ulittle16_t VersionFrontendBuild;
-    ulittle16_t VersionFrontendQFE;
-    ulittle16_t VersionBackendMajor;
-    ulittle16_t VersionBackendMinor;
-    ulittle16_t VersionBackendBuild;
-    ulittle16_t VersionBackendQFE;
-    // VersionString: The null-terminated version string follows.
-  };
-
   explicit Compile3Sym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  Compile3Sym(uint32_t RecordOffset, const Hdr *H, StringRef Version)
-      : SymbolRecord(SymbolRecordKind::Compile3Sym), RecordOffset(RecordOffset),
-        Header(*H), Version(Version) {}
-
-  static Expected<Compile3Sym> deserialize(SymbolRecordKind Kind,
-                                           uint32_t RecordOffset,
-                                           msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Version;
-    CV_DESERIALIZE(Reader, H, Version);
+  Compile3Sym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::Compile3Sym),
+        RecordOffset(RecordOffset) {}
+
+  CompileSym3Flags Flags;
+  CPUType Machine;
+  uint16_t VersionFrontendMajor;
+  uint16_t VersionFrontendMinor;
+  uint16_t VersionFrontendBuild;
+  uint16_t VersionFrontendQFE;
+  uint16_t VersionBackendMajor;
+  uint16_t VersionBackendMinor;
+  uint16_t VersionBackendBuild;
+  uint16_t VersionBackendQFE;
+  StringRef Version;
 
-    return Compile3Sym(RecordOffset, H, Version);
-  }
+  uint8_t getLanguage() const { return static_cast<uint32_t>(Flags) & 0xFF; }
+  uint32_t getFlags() const { return static_cast<uint32_t>(Flags) & ~0xFF; }
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Version;
 };
 
 // S_FRAMEPROC
 class FrameProcSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t TotalFrameBytes;
-    ulittle32_t PaddingFrameBytes;
-    ulittle32_t OffsetToPadding;
-    ulittle32_t BytesOfCalleeSavedRegisters;
-    ulittle32_t OffsetOfExceptionHandler;
-    ulittle16_t SectionIdOfExceptionHandler;
-    ulittle32_t Flags;
-  };
-
   explicit FrameProcSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  FrameProcSym(uint32_t RecordOffset, const Hdr *H)
+  explicit FrameProcSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::FrameProcSym),
-        RecordOffset(RecordOffset), Header(*H) {}
-
-  static Expected<FrameProcSym> deserialize(SymbolRecordKind Kind,
-                                            uint32_t RecordOffset,
-                                            msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    CV_DESERIALIZE(Reader, H);
+        RecordOffset(RecordOffset) {}
 
-    return FrameProcSym(RecordOffset, H);
-  }
+  uint32_t TotalFrameBytes;
+  uint32_t PaddingFrameBytes;
+  uint32_t OffsetToPadding;
+  uint32_t BytesOfCalleeSavedRegisters;
+  uint32_t OffsetOfExceptionHandler;
+  uint16_t SectionIdOfExceptionHandler;
+  FrameProcedureOptions Flags;
 
   uint32_t RecordOffset;
-  Hdr Header;
 };
 
 // S_CALLSITEINFO
 class CallSiteInfoSym : public SymbolRecord {
-public:
-  struct Hdr {
-    ulittle32_t CodeOffset;
-    ulittle16_t Segment;
-    ulittle16_t Reserved;
-    TypeIndex Type;
-  };
+  static constexpr uint32_t RelocationOffset = 4;
 
+public:
   explicit CallSiteInfoSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  CallSiteInfoSym(uint32_t RecordOffset, const Hdr *H)
-      : SymbolRecord(SymbolRecordKind::CallSiteInfoSym),
-        RecordOffset(RecordOffset), Header(*H) {}
-
-  static Expected<CallSiteInfoSym> deserialize(SymbolRecordKind Kind,
-                                               uint32_t RecordOffset,
-                                               msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    CV_DESERIALIZE(Reader, H);
-
-    return CallSiteInfoSym(RecordOffset, H);
-  }
+  explicit CallSiteInfoSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::CallSiteInfoSym) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, CodeOffset);
+    return RecordOffset + RelocationOffset;
   }
 
+  uint32_t CodeOffset;
+  uint16_t Segment;
+  TypeIndex Type;
+
   uint32_t RecordOffset;
-  Hdr Header;
 };
 
 // S_HEAPALLOCSITE
 class HeapAllocationSiteSym : public SymbolRecord {
-public:
-  struct Hdr {
-    ulittle32_t CodeOffset;
-    ulittle16_t Segment;
-    ulittle16_t CallInstructionSize;
-    TypeIndex Type;
-  };
+  static constexpr uint32_t RelocationOffset = 4;
 
+public:
   explicit HeapAllocationSiteSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  HeapAllocationSiteSym(uint32_t RecordOffset, const Hdr *H)
+  explicit HeapAllocationSiteSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::HeapAllocationSiteSym),
-        RecordOffset(RecordOffset), Header(*H) {}
-
-  static Expected<HeapAllocationSiteSym>
-  deserialize(SymbolRecordKind Kind, uint32_t RecordOffset,
-              msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    CV_DESERIALIZE(Reader, H);
-
-    return HeapAllocationSiteSym(RecordOffset, H);
-  }
+        RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, CodeOffset);
+    return RecordOffset + RelocationOffset;
   }
 
+  uint32_t CodeOffset;
+  uint16_t Segment;
+  uint16_t CallInstructionSize;
+  TypeIndex Type;
+
   uint32_t RecordOffset;
-  Hdr Header;
 };
 
 // S_FRAMECOOKIE
 class FrameCookieSym : public SymbolRecord {
-public:
-  struct Hdr {
-    ulittle32_t CodeOffset;
-    ulittle16_t Register;
-    uint8_t CookieKind;
-    uint8_t Flags;
-  };
+  static constexpr uint32_t RelocationOffset = 4;
 
+public:
   explicit FrameCookieSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  FrameCookieSym(uint32_t RecordOffset, const Hdr *H)
-      : SymbolRecord(SymbolRecordKind::FrameCookieSym),
-        RecordOffset(RecordOffset), Header(*H) {}
-
-  static Expected<FrameCookieSym> deserialize(SymbolRecordKind Kind,
-                                              uint32_t RecordOffset,
-                                              msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    CV_DESERIALIZE(Reader, H);
-
-    return FrameCookieSym(RecordOffset, H);
-  }
+  explicit FrameCookieSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::FrameCookieSym) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, CodeOffset);
+    return RecordOffset + RelocationOffset;
   }
 
+  uint32_t CodeOffset;
+  uint16_t Register;
+  uint8_t CookieKind;
+  uint8_t Flags;
+
   uint32_t RecordOffset;
-  Hdr Header;
 };
 
 // S_UDT, S_COBOLUDT
 class UDTSym : public SymbolRecord {
 public:
-  struct Hdr {
-    TypeIndex Type; // Type of the UDT
-                    // Name: The null-terminated name follows.
-  };
-
   explicit UDTSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  UDTSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::UDTSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<UDTSym> deserialize(SymbolRecordKind Kind,
-                                      uint32_t RecordOffset,
-                                      msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
+  explicit UDTSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::UDTSym) {}
 
-    return UDTSym(RecordOffset, H, Name);
-  }
+  TypeIndex Type;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 // S_BUILDINFO
 class BuildInfoSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t BuildId;
-  };
-
   explicit BuildInfoSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  BuildInfoSym(uint32_t RecordOffset, const Hdr *H)
+  BuildInfoSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::BuildInfoSym),
-        RecordOffset(RecordOffset), Header(*H) {}
+        RecordOffset(RecordOffset) {}
 
-  static Expected<BuildInfoSym> deserialize(SymbolRecordKind Kind,
-                                            uint32_t RecordOffset,
-                                            msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    CV_DESERIALIZE(Reader, H);
-
-    return BuildInfoSym(RecordOffset, H);
-  }
+  uint32_t BuildId;
 
   uint32_t RecordOffset;
-  Hdr Header;
 };
 
 // S_BPREL32
 class BPRelativeSym : public SymbolRecord {
 public:
-  struct Hdr {
-    little32_t Offset; // Offset from the base pointer register
-    TypeIndex Type;    // Type of the variable
-                       // Name: The null-terminated name follows.
-  };
-
   explicit BPRelativeSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  BPRelativeSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
+  explicit BPRelativeSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::BPRelativeSym),
-        RecordOffset(RecordOffset), Header(*H), Name(Name) {}
-
-  static Expected<BPRelativeSym> deserialize(SymbolRecordKind Kind,
-                                             uint32_t RecordOffset,
-                                             msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
+        RecordOffset(RecordOffset) {}
 
-    return BPRelativeSym(RecordOffset, H, Name);
-  }
+  int32_t Offset;
+  TypeIndex Type;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 // S_REGREL32
 class RegRelativeSym : public SymbolRecord {
 public:
-  struct Hdr {
-    ulittle32_t Offset;   // Offset from the register
-    TypeIndex Type;       // Type of the variable
-    ulittle16_t Register; // Register to which the variable is relative
-                          // Name: The null-terminated name follows.
-  };
-
   explicit RegRelativeSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  RegRelativeSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
+  explicit RegRelativeSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::RegRelativeSym),
-        RecordOffset(RecordOffset), Header(*H), Name(Name) {}
-
-  static Expected<RegRelativeSym> deserialize(SymbolRecordKind Kind,
-                                              uint32_t RecordOffset,
-                                              msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
+        RecordOffset(RecordOffset) {}
 
-    return RegRelativeSym(RecordOffset, H, Name);
-  }
+  uint32_t Offset;
+  TypeIndex Type;
+  uint16_t Register;
+  StringRef Name;
 
   uint32_t RecordOffset;
-  Hdr Header;
-  StringRef Name;
 };
 
 // S_CONSTANT, S_MANCONSTANT
 class ConstantSym : public SymbolRecord {
 public:
-  struct Hdr {
-    TypeIndex Type;
-    // Value: The value of the constant.
-    // Name: The null-terminated name follows.
-  };
-
   explicit ConstantSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  ConstantSym(uint32_t RecordOffset, const Hdr *H, const APSInt &Value,
-              StringRef Name)
-      : SymbolRecord(SymbolRecordKind::ConstantSym), RecordOffset(RecordOffset),
-        Header(*H), Value(Value), Name(Name) {}
-
-  static Expected<ConstantSym> deserialize(SymbolRecordKind Kind,
-                                           uint32_t RecordOffset,
-                                           msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    APSInt Value;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Value, Name);
+  ConstantSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::ConstantSym),
+        RecordOffset(RecordOffset) {}
 
-    return ConstantSym(RecordOffset, H, Value, Name);
-  }
-
-  uint32_t RecordOffset;
-  Hdr Header;
+  TypeIndex Type;
   APSInt Value;
   StringRef Name;
+
+  uint32_t RecordOffset;
 };
 
 // S_LDATA32, S_GDATA32, S_LMANDATA, S_GMANDATA
 class DataSym : public SymbolRecord {
-public:
-  struct Hdr {
-    TypeIndex Type;
-    ulittle32_t DataOffset;
-    ulittle16_t Segment;
-    // Name: The null-terminated name follows.
-  };
+  static constexpr uint32_t RelocationOffset = 8;
 
+public:
   explicit DataSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  DataSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
-      : SymbolRecord(SymbolRecordKind::DataSym), RecordOffset(RecordOffset),
-        Header(*H), Name(Name) {}
-
-  static Expected<DataSym> deserialize(SymbolRecordKind Kind,
-                                       uint32_t RecordOffset,
-                                       msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
-
-    return DataSym(RecordOffset, H, Name);
-  }
+  DataSym(uint32_t RecordOffset)
+      : SymbolRecord(SymbolRecordKind::DataSym), RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, DataOffset);
+    return RecordOffset + RelocationOffset;
   }
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  TypeIndex Type;
+  uint32_t DataOffset;
+  uint16_t Segment;
   StringRef Name;
+
+  uint32_t RecordOffset;
 };
 
 // S_LTHREAD32, S_GTHREAD32
 class ThreadLocalDataSym : public SymbolRecord {
-public:
-  struct Hdr {
-    TypeIndex Type;
-    ulittle32_t DataOffset;
-    ulittle16_t Segment;
-    // Name: The null-terminated name follows.
-  };
+  static constexpr uint32_t RelocationOffset = 8;
 
+public:
   explicit ThreadLocalDataSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
-  ThreadLocalDataSym(uint32_t RecordOffset, const Hdr *H, StringRef Name)
+  explicit ThreadLocalDataSym(uint32_t RecordOffset)
       : SymbolRecord(SymbolRecordKind::ThreadLocalDataSym),
-        RecordOffset(RecordOffset), Header(*H), Name(Name) {}
-
-  static Expected<ThreadLocalDataSym> deserialize(SymbolRecordKind Kind,
-                                                  uint32_t RecordOffset,
-                                                  msf::StreamReader &Reader) {
-    const Hdr *H = nullptr;
-    StringRef Name;
-    CV_DESERIALIZE(Reader, H, Name);
-
-    return ThreadLocalDataSym(RecordOffset, H, Name);
-  }
+        RecordOffset(RecordOffset) {}
 
   uint32_t getRelocationOffset() const {
-    return RecordOffset + offsetof(Hdr, DataOffset);
+    return RecordOffset + RelocationOffset;
   }
 
-  uint32_t RecordOffset;
-  Hdr Header;
+  TypeIndex Type;
+  uint32_t DataOffset;
+  uint16_t Segment;
   StringRef Name;
+
+  uint32_t RecordOffset;
 };
 
 typedef CVRecord<SymbolKind> CVSymbol;

Added: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h?rev=290000&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h (added)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolRecordMapping.h Fri Dec 16 16:48:14 2016
@@ -0,0 +1,44 @@
+//===- SymbolRecordMapping.h ------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_CODEVIEW_SYMBOLRECORDMAPPING_H
+#define LLVM_DEBUGINFO_CODEVIEW_SYMBOLRECORDMAPPING_H
+
+#include "llvm/DebugInfo/CodeView/CodeViewRecordIO.h"
+#include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
+
+namespace llvm {
+namespace msf {
+class StreamReader;
+class StreamWriter;
+}
+
+namespace codeview {
+class SymbolRecordMapping : public SymbolVisitorCallbacks {
+public:
+  explicit SymbolRecordMapping(msf::StreamReader &Reader) : IO(Reader) {}
+  explicit SymbolRecordMapping(msf::StreamWriter &Writer) : IO(Writer) {}
+
+  Error visitSymbolBegin(CVSymbol &Record) override;
+  Error visitSymbolEnd(CVSymbol &Record) override;
+
+#define SYMBOL_RECORD(EnumName, EnumVal, Name)                                 \
+  Error visitKnownRecord(CVSymbol &CVR, Name &Record) override;
+#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
+#include "CVSymbolTypes.def"
+
+private:
+  Optional<SymbolKind> Kind;
+
+  CodeViewRecordIO IO;
+};
+}
+}
+
+#endif

Added: llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h?rev=290000&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h (added)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/SymbolSerializer.h Fri Dec 16 16:48:14 2016
@@ -0,0 +1,96 @@
+//===- symbolSerializer.h ---------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
+#define LLVM_DEBUGINFO_CODEVIEW_SYMBOLSERIALIZER_H
+
+#include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h"
+#include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
+#include "llvm/DebugInfo/MSF/ByteStream.h"
+#include "llvm/DebugInfo/MSF/StreamWriter.h"
+
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace codeview {
+
+class SymbolSerializer : public SymbolVisitorCallbacks {
+  uint32_t RecordStart = 0;
+  msf::StreamWriter &Writer;
+  SymbolRecordMapping Mapping;
+  Optional<SymbolKind> CurrentSymbol;
+
+  Error writeRecordPrefix(SymbolKind Kind) {
+    RecordPrefix Prefix;
+    Prefix.RecordKind = Kind;
+    Prefix.RecordLen = 0;
+    if (auto EC = Writer.writeObject(Prefix))
+      return EC;
+    return Error::success();
+  }
+
+public:
+  explicit SymbolSerializer(msf::StreamWriter &Writer)
+      : Writer(Writer), Mapping(Writer) {}
+
+  virtual Error visitSymbolBegin(CVSymbol &Record) override {
+    assert(!CurrentSymbol.hasValue() && "Already in a symbol mapping!");
+
+    RecordStart = Writer.getOffset();
+    if (auto EC = writeRecordPrefix(Record.kind()))
+      return EC;
+
+    CurrentSymbol = Record.kind();
+    if (auto EC = Mapping.visitSymbolBegin(Record))
+      return EC;
+
+    return Error::success();
+  }
+
+  virtual Error visitSymbolEnd(CVSymbol &Record) override {
+    assert(CurrentSymbol.hasValue() && "Not in a symbol mapping!");
+
+    if (auto EC = Mapping.visitSymbolEnd(Record))
+      return EC;
+
+    uint32_t RecordEnd = Writer.getOffset();
+    Writer.setOffset(RecordStart);
+    uint16_t Length = RecordEnd - Writer.getOffset() - 2;
+    if (auto EC = Writer.writeInteger(Length))
+      return EC;
+
+    Writer.setOffset(RecordEnd);
+    CurrentSymbol.reset();
+
+    return Error::success();
+  }
+
+#define SYMBOL_RECORD(EnumName, EnumVal, Name)                                 \
+  virtual Error visitKnownRecord(CVSymbol &CVR, Name &Record) override {       \
+    return visitKnownRecordImpl(CVR, Record);                                  \
+  }
+#define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
+#include "CVSymbolTypes.def"
+
+private:
+  template <typename RecordKind>
+  Error visitKnownRecordImpl(CVSymbol &CVR, RecordKind &Record) {
+    return Mapping.visitKnownRecord(CVR, Record);
+  }
+};
+}
+}
+
+#endif

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Fri Dec 16 16:48:14 2016
@@ -2072,35 +2072,39 @@ void CodeViewDebug::emitLocalVariable(co
                       (DefRange.StructOffset
                        << DefRangeRegisterRelSym::OffsetInParentShift);
       }
-      DefRangeRegisterRelSym Sym(DefRange.CVRegister, RegRelFlags,
-                                 DefRange.DataOffset, None);
+      DefRangeRegisterRelSym Sym(S_DEFRANGE_REGISTER_REL);
+      Sym.Hdr.Register = DefRange.CVRegister;
+      Sym.Hdr.Flags = RegRelFlags;
+      Sym.Hdr.BasePointerOffset = DefRange.DataOffset;
       ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER_REL);
       BytePrefix +=
           StringRef(reinterpret_cast<const char *>(&SymKind), sizeof(SymKind));
       BytePrefix +=
-          StringRef(reinterpret_cast<const char *>(&Sym.Header),
-                    sizeof(Sym.Header) - sizeof(LocalVariableAddrRange));
+          StringRef(reinterpret_cast<const char *>(&Sym.Hdr), sizeof(Sym.Hdr));
     } else {
       assert(DefRange.DataOffset == 0 && "unexpected offset into register");
       if (DefRange.IsSubfield) {
         // Unclear what matters here.
-        DefRangeSubfieldRegisterSym Sym(DefRange.CVRegister, 0,
-                                        DefRange.StructOffset, None);
+        DefRangeSubfieldRegisterSym Sym(S_DEFRANGE_SUBFIELD_REGISTER);
+        Sym.Hdr.Register = DefRange.CVRegister;
+        Sym.Hdr.MayHaveNoName = 0;
+        Sym.Hdr.OffsetInParent = DefRange.StructOffset;
+
         ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_SUBFIELD_REGISTER);
         BytePrefix += StringRef(reinterpret_cast<const char *>(&SymKind),
                                 sizeof(SymKind));
-        BytePrefix +=
-            StringRef(reinterpret_cast<const char *>(&Sym.Header),
-                      sizeof(Sym.Header) - sizeof(LocalVariableAddrRange));
+        BytePrefix += StringRef(reinterpret_cast<const char *>(&Sym.Hdr),
+                                sizeof(Sym.Hdr));
       } else {
         // Unclear what matters here.
-        DefRangeRegisterSym Sym(DefRange.CVRegister, 0, None);
+        DefRangeRegisterSym Sym(S_DEFRANGE_REGISTER);
+        Sym.Hdr.Register = DefRange.CVRegister;
+        Sym.Hdr.MayHaveNoName = 0;
         ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER);
         BytePrefix += StringRef(reinterpret_cast<const char *>(&SymKind),
                                 sizeof(SymKind));
-        BytePrefix +=
-            StringRef(reinterpret_cast<const char *>(&Sym.Header),
-                      sizeof(Sym.Header) - sizeof(LocalVariableAddrRange));
+        BytePrefix += StringRef(reinterpret_cast<const char *>(&Sym.Hdr),
+                                sizeof(Sym.Hdr));
       }
     }
     OS.EmitCVDefRangeDirective(DefRange.Ranges, BytePrefix);

Modified: llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CMakeLists.txt Fri Dec 16 16:48:14 2016
@@ -8,7 +8,9 @@ add_llvm_library(LLVMDebugInfoCodeView
   ModuleSubstream.cpp
   ModuleSubstreamVisitor.cpp
   RecordSerialization.cpp
+  SymbolRecordMapping.cpp
   SymbolDumper.cpp
+  SymbolSerializer.cpp
   TypeDumper.cpp
   TypeRecord.cpp
   TypeRecordMapping.cpp

Modified: llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp Fri Dec 16 16:48:14 2016
@@ -75,6 +75,16 @@ Error CodeViewRecordIO::mapByteVectorTai
   return Error::success();
 }
 
+Error CodeViewRecordIO::mapByteVectorTail(std::vector<uint8_t> &Bytes) {
+  ArrayRef<uint8_t> BytesRef(Bytes);
+  if (auto EC = mapByteVectorTail(BytesRef))
+    return EC;
+  if (!isWriting())
+    Bytes.assign(BytesRef.begin(), BytesRef.end());
+
+  return Error::success();
+}
+
 Error CodeViewRecordIO::mapInteger(TypeIndex &TypeInd) {
   if (isWriting()) {
     if (auto EC = Writer->writeInteger(TypeInd.getIndex()))
@@ -159,6 +169,27 @@ Error CodeViewRecordIO::mapGuid(StringRe
   }
   return Error::success();
 }
+
+Error CodeViewRecordIO::mapStringZVectorZ(std::vector<StringRef> &Value) {
+  if (isWriting()) {
+    for (auto V : Value) {
+      if (auto EC = mapStringZ(V))
+        return EC;
+    }
+    if (auto EC = Writer->writeInteger(uint8_t(0)))
+      return EC;
+  } else {
+    StringRef S;
+    if (auto EC = mapStringZ(S))
+      return EC;
+    while (!S.empty()) {
+      Value.push_back(S);
+      if (auto EC = mapStringZ(S))
+        return EC;
+    };
+  }
+  return Error::success();
+}
 
 Error CodeViewRecordIO::writeEncodedSignedInteger(const int64_t &Value) {
   assert(Value < 0 && "Encoded integer is not signed!");

Modified: llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/SymbolDumper.cpp Fri Dec 16 16:48:14 2016
@@ -94,14 +94,14 @@ Error CVSymbolDumperImpl::visitKnownReco
   DictScope S(W, "BlockStart");
 
   StringRef LinkageName;
-  W.printHex("PtrParent", Block.Header.PtrParent);
-  W.printHex("PtrEnd", Block.Header.PtrEnd);
-  W.printHex("CodeSize", Block.Header.CodeSize);
+  W.printHex("PtrParent", Block.Parent);
+  W.printHex("PtrEnd", Block.End);
+  W.printHex("CodeSize", Block.CodeSize);
   if (ObjDelegate) {
     ObjDelegate->printRelocatedField("CodeOffset", Block.getRelocationOffset(),
-                                     Block.Header.CodeOffset, &LinkageName);
+                                     Block.CodeOffset, &LinkageName);
   }
-  W.printHex("Segment", Block.Header.Segment);
+  W.printHex("Segment", Block.Segment);
   W.printString("BlockName", Block.Name);
   W.printString("LinkageName", LinkageName);
   return Error::success();
@@ -109,36 +109,35 @@ Error CVSymbolDumperImpl::visitKnownReco
 
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {
   DictScope S(W, "Thunk32");
-  W.printNumber("Parent", Thunk.Header.Parent);
-  W.printNumber("End", Thunk.Header.End);
-  W.printNumber("Next", Thunk.Header.Next);
-  W.printNumber("Off", Thunk.Header.Off);
-  W.printNumber("Seg", Thunk.Header.Seg);
-  W.printNumber("Len", Thunk.Header.Len);
-  W.printEnum("Ordinal", Thunk.Header.Ord, getThunkOrdinalNames());
+  W.printNumber("Parent", Thunk.Parent);
+  W.printNumber("End", Thunk.End);
+  W.printNumber("Next", Thunk.Next);
+  W.printNumber("Off", Thunk.Offset);
+  W.printNumber("Seg", Thunk.Segment);
+  W.printNumber("Len", Thunk.Length);
+  W.printEnum("Ordinal", uint8_t(Thunk.Thunk), getThunkOrdinalNames());
   return Error::success();
 }
 
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
                                            TrampolineSym &Tramp) {
   DictScope S(W, "Trampoline");
-  W.printEnum("Type", Tramp.Header.Type, getTrampolineNames());
-  W.printNumber("Size", Tramp.Header.Size);
-  W.printNumber("ThunkOff", Tramp.Header.ThunkOff);
-  W.printNumber("TargetOff", Tramp.Header.TargetOff);
-  W.printNumber("ThunkSection", Tramp.Header.ThunkSection);
-  W.printNumber("TargetSection", Tramp.Header.TargetSection);
+  W.printEnum("Type", uint16_t(Tramp.Type), getTrampolineNames());
+  W.printNumber("Size", Tramp.Size);
+  W.printNumber("ThunkOff", Tramp.ThunkOffset);
+  W.printNumber("TargetOff", Tramp.TargetOffset);
+  W.printNumber("ThunkSection", Tramp.ThunkSection);
+  W.printNumber("TargetSection", Tramp.TargetSection);
   return Error::success();
 }
 
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, SectionSym &Section) {
   DictScope S(W, "Section");
-  W.printNumber("SectionNumber", Section.Header.SectionNumber);
-  W.printNumber("Alignment", Section.Header.Alignment);
-  W.printNumber("Reserved", Section.Header.Reserved);
-  W.printNumber("Rva", Section.Header.Rva);
-  W.printNumber("Length", Section.Header.Length);
-  W.printFlags("Characteristics", Section.Header.Characteristics,
+  W.printNumber("SectionNumber", Section.SectionNumber);
+  W.printNumber("Alignment", Section.Alignment);
+  W.printNumber("Rva", Section.Rva);
+  W.printNumber("Length", Section.Length);
+  W.printFlags("Characteristics", Section.Characteristics,
                getImageSectionCharacteristicNames(),
                COFF::SectionCharacteristics(0x00F00000));
 
@@ -149,12 +148,12 @@ Error CVSymbolDumperImpl::visitKnownReco
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
                                            CoffGroupSym &CoffGroup) {
   DictScope S(W, "COFF Group");
-  W.printNumber("Size", CoffGroup.Header.Size);
-  W.printFlags("Characteristics", CoffGroup.Header.Characteristics,
+  W.printNumber("Size", CoffGroup.Size);
+  W.printFlags("Characteristics", CoffGroup.Characteristics,
                getImageSectionCharacteristicNames(),
                COFF::SectionCharacteristics(0x00F00000));
-  W.printNumber("Offset", CoffGroup.Header.Offset);
-  W.printNumber("Segment", CoffGroup.Header.Segment);
+  W.printNumber("Offset", CoffGroup.Offset);
+  W.printNumber("Segment", CoffGroup.Segment);
   W.printString("Name", CoffGroup.Name);
   return Error::success();
 }
@@ -163,8 +162,8 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            BPRelativeSym &BPRel) {
   DictScope S(W, "BPRelativeSym");
 
-  W.printNumber("Offset", BPRel.Header.Offset);
-  CVTD.printTypeIndex("Type", BPRel.Header.Type);
+  W.printNumber("Offset", BPRel.Offset);
+  CVTD.printTypeIndex("Type", BPRel.Type);
   W.printString("VarName", BPRel.Name);
   return Error::success();
 }
@@ -173,7 +172,7 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            BuildInfoSym &BuildInfo) {
   DictScope S(W, "BuildInfo");
 
-  W.printNumber("BuildId", BuildInfo.Header.BuildId);
+  W.printNumber("BuildId", BuildInfo.BuildId);
   return Error::success();
 }
 
@@ -183,13 +182,12 @@ Error CVSymbolDumperImpl::visitKnownReco
 
   StringRef LinkageName;
   if (ObjDelegate) {
-    ObjDelegate->printRelocatedField(
-        "CodeOffset", CallSiteInfo.getRelocationOffset(),
-        CallSiteInfo.Header.CodeOffset, &LinkageName);
-  }
-  W.printHex("Segment", CallSiteInfo.Header.Segment);
-  W.printHex("Reserved", CallSiteInfo.Header.Reserved);
-  CVTD.printTypeIndex("Type", CallSiteInfo.Header.Type);
+    ObjDelegate->printRelocatedField("CodeOffset",
+                                     CallSiteInfo.getRelocationOffset(),
+                                     CallSiteInfo.CodeOffset, &LinkageName);
+  }
+  W.printHex("Segment", CallSiteInfo.Segment);
+  CVTD.printTypeIndex("Type", CallSiteInfo.Type);
   if (!LinkageName.empty())
     W.printString("LinkageName", LinkageName);
   return Error::success();
@@ -199,7 +197,6 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            EnvBlockSym &EnvBlock) {
   DictScope S(W, "EnvBlock");
 
-  W.printNumber("Reserved", EnvBlock.Header.Reserved);
   ListScope L(W, "Entries");
   for (auto Entry : EnvBlock.Fields) {
     W.printString(Entry);
@@ -210,17 +207,17 @@ Error CVSymbolDumperImpl::visitKnownReco
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
                                            FileStaticSym &FileStatic) {
   DictScope S(W, "FileStatic");
-  W.printNumber("Index", FileStatic.Header.Index);
-  W.printNumber("ModFilenameOffset", FileStatic.Header.ModFilenameOffset);
-  W.printFlags("Flags", uint16_t(FileStatic.Header.Flags), getLocalFlagNames());
+  W.printNumber("Index", FileStatic.Index);
+  W.printNumber("ModFilenameOffset", FileStatic.ModFilenameOffset);
+  W.printFlags("Flags", uint16_t(FileStatic.Flags), getLocalFlagNames());
   W.printString("Name", FileStatic.Name);
   return Error::success();
 }
 
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {
   DictScope S(W, "Export");
-  W.printNumber("Ordinal", Export.Header.Ordinal);
-  W.printFlags("Flags", Export.Header.Flags, getExportSymFlagNames());
+  W.printNumber("Ordinal", Export.Ordinal);
+  W.printFlags("Flags", uint16_t(Export.Flags), getExportSymFlagNames());
   W.printString("Name", Export.Name);
   return Error::success();
 }
@@ -229,24 +226,20 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            Compile2Sym &Compile2) {
   DictScope S(W, "CompilerFlags2");
 
-  W.printEnum("Language", Compile2.Header.getLanguage(),
-              getSourceLanguageNames());
-  W.printFlags("Flags", Compile2.Header.flags & ~0xff,
-               getCompileSym2FlagNames());
-  W.printEnum("Machine", unsigned(Compile2.Header.Machine), getCPUTypeNames());
+  W.printEnum("Language", Compile2.getLanguage(), getSourceLanguageNames());
+  W.printFlags("Flags", Compile2.getFlags(), getCompileSym2FlagNames());
+  W.printEnum("Machine", unsigned(Compile2.Machine), getCPUTypeNames());
   std::string FrontendVersion;
   {
     raw_string_ostream Out(FrontendVersion);
-    Out << Compile2.Header.VersionFrontendMajor << '.'
-        << Compile2.Header.VersionFrontendMinor << '.'
-        << Compile2.Header.VersionFrontendBuild;
+    Out << Compile2.VersionFrontendMajor << '.' << Compile2.VersionFrontendMinor
+        << '.' << Compile2.VersionFrontendBuild;
   }
   std::string BackendVersion;
   {
     raw_string_ostream Out(BackendVersion);
-    Out << Compile2.Header.VersionBackendMajor << '.'
-        << Compile2.Header.VersionBackendMinor << '.'
-        << Compile2.Header.VersionBackendBuild;
+    Out << Compile2.VersionBackendMajor << '.' << Compile2.VersionBackendMinor
+        << '.' << Compile2.VersionBackendBuild;
   }
   W.printString("FrontendVersion", FrontendVersion);
   W.printString("BackendVersion", BackendVersion);
@@ -258,26 +251,22 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            Compile3Sym &Compile3) {
   DictScope S(W, "CompilerFlags3");
 
-  W.printEnum("Language", Compile3.Header.getLanguage(),
-              getSourceLanguageNames());
-  W.printFlags("Flags", Compile3.Header.flags & ~0xff,
-               getCompileSym3FlagNames());
-  W.printEnum("Machine", unsigned(Compile3.Header.Machine), getCPUTypeNames());
+  W.printEnum("Language", Compile3.getLanguage(), getSourceLanguageNames());
+  W.printFlags("Flags", Compile3.getFlags(), getCompileSym3FlagNames());
+  W.printEnum("Machine", unsigned(Compile3.Machine), getCPUTypeNames());
   std::string FrontendVersion;
   {
     raw_string_ostream Out(FrontendVersion);
-    Out << Compile3.Header.VersionFrontendMajor << '.'
-        << Compile3.Header.VersionFrontendMinor << '.'
-        << Compile3.Header.VersionFrontendBuild << '.'
-        << Compile3.Header.VersionFrontendQFE;
+    Out << Compile3.VersionFrontendMajor << '.' << Compile3.VersionFrontendMinor
+        << '.' << Compile3.VersionFrontendBuild << '.'
+        << Compile3.VersionFrontendQFE;
   }
   std::string BackendVersion;
   {
     raw_string_ostream Out(BackendVersion);
-    Out << Compile3.Header.VersionBackendMajor << '.'
-        << Compile3.Header.VersionBackendMinor << '.'
-        << Compile3.Header.VersionBackendBuild << '.'
-        << Compile3.Header.VersionBackendQFE;
+    Out << Compile3.VersionBackendMajor << '.' << Compile3.VersionBackendMinor
+        << '.' << Compile3.VersionBackendBuild << '.'
+        << Compile3.VersionBackendQFE;
   }
   W.printString("FrontendVersion", FrontendVersion);
   W.printString("BackendVersion", BackendVersion);
@@ -289,7 +278,7 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            ConstantSym &Constant) {
   DictScope S(W, "Constant");
 
-  CVTD.printTypeIndex("Type", Constant.Header.Type);
+  CVTD.printTypeIndex("Type", Constant.Type);
   W.printNumber("Value", Constant.Value);
   W.printString("Name", Constant.Name);
   return Error::success();
@@ -302,9 +291,9 @@ Error CVSymbolDumperImpl::visitKnownReco
   StringRef LinkageName;
   if (ObjDelegate) {
     ObjDelegate->printRelocatedField("DataOffset", Data.getRelocationOffset(),
-                                     Data.Header.DataOffset, &LinkageName);
+                                     Data.DataOffset, &LinkageName);
   }
-  CVTD.printTypeIndex("Type", Data.Header.Type);
+  CVTD.printTypeIndex("Type", Data.Type);
   W.printString("DisplayName", Data.Name);
   if (!LinkageName.empty())
     W.printString("LinkageName", LinkageName);
@@ -315,7 +304,7 @@ Error CVSymbolDumperImpl::visitKnownReco
     CVSymbol &CVR,
     DefRangeFramePointerRelFullScopeSym &DefRangeFramePointerRelFullScope) {
   DictScope S(W, "DefRangeFramePointerRelFullScope");
-  W.printNumber("Offset", DefRangeFramePointerRelFullScope.Header.Offset);
+  W.printNumber("Offset", DefRangeFramePointerRelFullScope.Offset);
   return Error::success();
 }
 
@@ -323,8 +312,8 @@ Error CVSymbolDumperImpl::visitKnownReco
     CVSymbol &CVR, DefRangeFramePointerRelSym &DefRangeFramePointerRel) {
   DictScope S(W, "DefRangeFramePointerRel");
 
-  W.printNumber("Offset", DefRangeFramePointerRel.Header.Offset);
-  printLocalVariableAddrRange(DefRangeFramePointerRel.Header.Range,
+  W.printNumber("Offset", DefRangeFramePointerRel.Offset);
+  printLocalVariableAddrRange(DefRangeFramePointerRel.Range,
                               DefRangeFramePointerRel.getRelocationOffset());
   printLocalVariableAddrGap(DefRangeFramePointerRel.Gaps);
   return Error::success();
@@ -334,13 +323,12 @@ Error CVSymbolDumperImpl::visitKnownReco
     CVSymbol &CVR, DefRangeRegisterRelSym &DefRangeRegisterRel) {
   DictScope S(W, "DefRangeRegisterRel");
 
-  W.printNumber("BaseRegister", DefRangeRegisterRel.Header.BaseRegister);
+  W.printNumber("BaseRegister", DefRangeRegisterRel.Hdr.Register);
   W.printBoolean("HasSpilledUDTMember",
                  DefRangeRegisterRel.hasSpilledUDTMember());
   W.printNumber("OffsetInParent", DefRangeRegisterRel.offsetInParent());
-  W.printNumber("BasePointerOffset",
-                DefRangeRegisterRel.Header.BasePointerOffset);
-  printLocalVariableAddrRange(DefRangeRegisterRel.Header.Range,
+  W.printNumber("BasePointerOffset", DefRangeRegisterRel.Hdr.BasePointerOffset);
+  printLocalVariableAddrRange(DefRangeRegisterRel.Range,
                               DefRangeRegisterRel.getRelocationOffset());
   printLocalVariableAddrGap(DefRangeRegisterRel.Gaps);
   return Error::success();
@@ -350,9 +338,9 @@ Error CVSymbolDumperImpl::visitKnownReco
     CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {
   DictScope S(W, "DefRangeRegister");
 
-  W.printNumber("Register", DefRangeRegister.Header.Register);
-  W.printNumber("MayHaveNoName", DefRangeRegister.Header.MayHaveNoName);
-  printLocalVariableAddrRange(DefRangeRegister.Header.Range,
+  W.printNumber("Register", DefRangeRegister.Hdr.Register);
+  W.printNumber("MayHaveNoName", DefRangeRegister.Hdr.MayHaveNoName);
+  printLocalVariableAddrRange(DefRangeRegister.Range,
                               DefRangeRegister.getRelocationOffset());
   printLocalVariableAddrGap(DefRangeRegister.Gaps);
   return Error::success();
@@ -362,11 +350,10 @@ Error CVSymbolDumperImpl::visitKnownReco
     CVSymbol &CVR, DefRangeSubfieldRegisterSym &DefRangeSubfieldRegister) {
   DictScope S(W, "DefRangeSubfieldRegister");
 
-  W.printNumber("Register", DefRangeSubfieldRegister.Header.Register);
-  W.printNumber("MayHaveNoName", DefRangeSubfieldRegister.Header.MayHaveNoName);
-  W.printNumber("OffsetInParent",
-                DefRangeSubfieldRegister.Header.OffsetInParent);
-  printLocalVariableAddrRange(DefRangeSubfieldRegister.Header.Range,
+  W.printNumber("Register", DefRangeSubfieldRegister.Hdr.Register);
+  W.printNumber("MayHaveNoName", DefRangeSubfieldRegister.Hdr.MayHaveNoName);
+  W.printNumber("OffsetInParent", DefRangeSubfieldRegister.Hdr.OffsetInParent);
+  printLocalVariableAddrRange(DefRangeSubfieldRegister.Range,
                               DefRangeSubfieldRegister.getRelocationOffset());
   printLocalVariableAddrGap(DefRangeSubfieldRegister.Gaps);
   return Error::success();
@@ -378,7 +365,7 @@ Error CVSymbolDumperImpl::visitKnownReco
 
   if (ObjDelegate) {
     StringRef StringTable = ObjDelegate->getStringTable();
-    auto ProgramStringTableOffset = DefRangeSubfield.Header.Program;
+    auto ProgramStringTableOffset = DefRangeSubfield.Program;
     if (ProgramStringTableOffset >= StringTable.size())
       return llvm::make_error<CodeViewError>(
           "String table offset outside of bounds of String Table!");
@@ -386,8 +373,8 @@ Error CVSymbolDumperImpl::visitKnownReco
         StringTable.drop_front(ProgramStringTableOffset).split('\0').first;
     W.printString("Program", Program);
   }
-  W.printNumber("OffsetInParent", DefRangeSubfield.Header.OffsetInParent);
-  printLocalVariableAddrRange(DefRangeSubfield.Header.Range,
+  W.printNumber("OffsetInParent", DefRangeSubfield.OffsetInParent);
+  printLocalVariableAddrRange(DefRangeSubfield.Range,
                               DefRangeSubfield.getRelocationOffset());
   printLocalVariableAddrGap(DefRangeSubfield.Gaps);
   return Error::success();
@@ -399,7 +386,7 @@ Error CVSymbolDumperImpl::visitKnownReco
 
   if (ObjDelegate) {
     StringRef StringTable = ObjDelegate->getStringTable();
-    auto ProgramStringTableOffset = DefRange.Header.Program;
+    auto ProgramStringTableOffset = DefRange.Program;
     if (ProgramStringTableOffset >= StringTable.size())
       return llvm::make_error<CodeViewError>(
           "String table offset outside of bounds of String Table!");
@@ -407,8 +394,7 @@ Error CVSymbolDumperImpl::visitKnownReco
         StringTable.drop_front(ProgramStringTableOffset).split('\0').first;
     W.printString("Program", Program);
   }
-  printLocalVariableAddrRange(DefRange.Header.Range,
-                              DefRange.getRelocationOffset());
+  printLocalVariableAddrRange(DefRange.Range, DefRange.getRelocationOffset());
   printLocalVariableAddrGap(DefRange.Gaps);
   return Error::success();
 }
@@ -419,14 +405,14 @@ Error CVSymbolDumperImpl::visitKnownReco
 
   StringRef LinkageName;
   if (ObjDelegate) {
-    ObjDelegate->printRelocatedField(
-        "CodeOffset", FrameCookie.getRelocationOffset(),
-        FrameCookie.Header.CodeOffset, &LinkageName);
+    ObjDelegate->printRelocatedField("CodeOffset",
+                                     FrameCookie.getRelocationOffset(),
+                                     FrameCookie.CodeOffset, &LinkageName);
   }
-  W.printHex("Register", FrameCookie.Header.Register);
-  W.printEnum("CookieKind", uint16_t(FrameCookie.Header.CookieKind),
+  W.printHex("Register", FrameCookie.Register);
+  W.printEnum("CookieKind", uint16_t(FrameCookie.CookieKind),
               getFrameCookieKindNames());
-  W.printHex("Flags", FrameCookie.Header.Flags);
+  W.printHex("Flags", FrameCookie.Flags);
   return Error::success();
 }
 
@@ -434,16 +420,16 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            FrameProcSym &FrameProc) {
   DictScope S(W, "FrameProc");
 
-  W.printHex("TotalFrameBytes", FrameProc.Header.TotalFrameBytes);
-  W.printHex("PaddingFrameBytes", FrameProc.Header.PaddingFrameBytes);
-  W.printHex("OffsetToPadding", FrameProc.Header.OffsetToPadding);
+  W.printHex("TotalFrameBytes", FrameProc.TotalFrameBytes);
+  W.printHex("PaddingFrameBytes", FrameProc.PaddingFrameBytes);
+  W.printHex("OffsetToPadding", FrameProc.OffsetToPadding);
   W.printHex("BytesOfCalleeSavedRegisters",
-             FrameProc.Header.BytesOfCalleeSavedRegisters);
-  W.printHex("OffsetOfExceptionHandler",
-             FrameProc.Header.OffsetOfExceptionHandler);
+             FrameProc.BytesOfCalleeSavedRegisters);
+  W.printHex("OffsetOfExceptionHandler", FrameProc.OffsetOfExceptionHandler);
   W.printHex("SectionIdOfExceptionHandler",
-             FrameProc.Header.SectionIdOfExceptionHandler);
-  W.printFlags("Flags", FrameProc.Header.Flags, getFrameProcSymFlagNames());
+             FrameProc.SectionIdOfExceptionHandler);
+  W.printFlags("Flags", static_cast<uint32_t>(FrameProc.Flags),
+               getFrameProcSymFlagNames());
   return Error::success();
 }
 
@@ -453,13 +439,13 @@ Error CVSymbolDumperImpl::visitKnownReco
 
   StringRef LinkageName;
   if (ObjDelegate) {
-    ObjDelegate->printRelocatedField(
-        "CodeOffset", HeapAllocSite.getRelocationOffset(),
-        HeapAllocSite.Header.CodeOffset, &LinkageName);
-  }
-  W.printHex("Segment", HeapAllocSite.Header.Segment);
-  W.printHex("CallInstructionSize", HeapAllocSite.Header.CallInstructionSize);
-  CVTD.printTypeIndex("Type", HeapAllocSite.Header.Type);
+    ObjDelegate->printRelocatedField("CodeOffset",
+                                     HeapAllocSite.getRelocationOffset(),
+                                     HeapAllocSite.CodeOffset, &LinkageName);
+  }
+  W.printHex("Segment", HeapAllocSite.Segment);
+  W.printHex("CallInstructionSize", HeapAllocSite.CallInstructionSize);
+  CVTD.printTypeIndex("Type", HeapAllocSite.Type);
   if (!LinkageName.empty())
     W.printString("LinkageName", LinkageName);
   return Error::success();
@@ -469,9 +455,9 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            InlineSiteSym &InlineSite) {
   DictScope S(W, "InlineSite");
 
-  W.printHex("PtrParent", InlineSite.Header.PtrParent);
-  W.printHex("PtrEnd", InlineSite.Header.PtrEnd);
-  CVTD.printTypeIndex("Inlinee", InlineSite.Header.Inlinee);
+  W.printHex("PtrParent", InlineSite.Parent);
+  W.printHex("PtrEnd", InlineSite.End);
+  CVTD.printTypeIndex("Inlinee", InlineSite.Inlinee);
 
   ListScope BinaryAnnotations(W, "BinaryAnnotations");
   for (auto &Annotation : InlineSite.annotations()) {
@@ -525,26 +511,26 @@ Error CVSymbolDumperImpl::visitKnownReco
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR,
                                            RegisterSym &Register) {
   DictScope S(W, "RegisterSym");
-  W.printNumber("Type", Register.Header.Index);
-  W.printEnum("Seg", uint16_t(Register.Header.Register), getRegisterNames());
+  W.printNumber("Type", Register.Index);
+  W.printEnum("Seg", uint16_t(Register.Register), getRegisterNames());
   W.printString("Name", Register.Name);
   return Error::success();
 }
 
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, PublicSym32 &Public) {
   DictScope S(W, "PublicSym");
-  W.printNumber("Type", Public.Header.Index);
-  W.printNumber("Seg", Public.Header.Seg);
-  W.printNumber("Off", Public.Header.Off);
+  W.printNumber("Type", Public.Index);
+  W.printNumber("Seg", Public.Segment);
+  W.printNumber("Off", Public.Offset);
   W.printString("Name", Public.Name);
   return Error::success();
 }
 
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ProcRefSym &ProcRef) {
   DictScope S(W, "ProcRef");
-  W.printNumber("SumName", ProcRef.Header.SumName);
-  W.printNumber("SymOffset", ProcRef.Header.SymOffset);
-  W.printNumber("Mod", ProcRef.Header.Mod);
+  W.printNumber("SumName", ProcRef.SumName);
+  W.printNumber("SymOffset", ProcRef.SymOffset);
+  W.printNumber("Mod", ProcRef.Module);
   W.printString("Name", ProcRef.Name);
   return Error::success();
 }
@@ -555,11 +541,11 @@ Error CVSymbolDumperImpl::visitKnownReco
   StringRef LinkageName;
   if (ObjDelegate) {
     ObjDelegate->printRelocatedField("CodeOffset", Label.getRelocationOffset(),
-                                     Label.Header.CodeOffset, &LinkageName);
+                                     Label.CodeOffset, &LinkageName);
   }
-  W.printHex("Segment", Label.Header.Segment);
-  W.printHex("Flags", Label.Header.Flags);
-  W.printFlags("Flags", Label.Header.Flags, getProcSymFlagNames());
+  W.printHex("Segment", Label.Segment);
+  W.printHex("Flags", uint8_t(Label.Flags));
+  W.printFlags("Flags", uint8_t(Label.Flags), getProcSymFlagNames());
   W.printString("DisplayName", Label.Name);
   if (!LinkageName.empty())
     W.printString("LinkageName", LinkageName);
@@ -569,8 +555,8 @@ Error CVSymbolDumperImpl::visitKnownReco
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
   DictScope S(W, "Local");
 
-  CVTD.printTypeIndex("Type", Local.Header.Type);
-  W.printFlags("Flags", uint16_t(Local.Header.Flags), getLocalFlagNames());
+  CVTD.printTypeIndex("Type", Local.Type);
+  W.printFlags("Flags", uint16_t(Local.Flags), getLocalFlagNames());
   W.printString("VarName", Local.Name);
   return Error::success();
 }
@@ -578,7 +564,7 @@ Error CVSymbolDumperImpl::visitKnownReco
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, ObjNameSym &ObjName) {
   DictScope S(W, "ObjectName");
 
-  W.printHex("Signature", ObjName.Header.Signature);
+  W.printHex("Signature", ObjName.Signature);
   W.printString("ObjectName", ObjName.Name);
   return Error::success();
 }
@@ -594,19 +580,19 @@ Error CVSymbolDumperImpl::visitKnownReco
 
   StringRef LinkageName;
   W.printEnum("Kind", uint16_t(CVR.kind()), getSymbolTypeNames());
-  W.printHex("PtrParent", Proc.Header.PtrParent);
-  W.printHex("PtrEnd", Proc.Header.PtrEnd);
-  W.printHex("PtrNext", Proc.Header.PtrNext);
-  W.printHex("CodeSize", Proc.Header.CodeSize);
-  W.printHex("DbgStart", Proc.Header.DbgStart);
-  W.printHex("DbgEnd", Proc.Header.DbgEnd);
-  CVTD.printTypeIndex("FunctionType", Proc.Header.FunctionType);
+  W.printHex("PtrParent", Proc.Parent);
+  W.printHex("PtrEnd", Proc.End);
+  W.printHex("PtrNext", Proc.Next);
+  W.printHex("CodeSize", Proc.CodeSize);
+  W.printHex("DbgStart", Proc.DbgStart);
+  W.printHex("DbgEnd", Proc.DbgEnd);
+  CVTD.printTypeIndex("FunctionType", Proc.FunctionType);
   if (ObjDelegate) {
     ObjDelegate->printRelocatedField("CodeOffset", Proc.getRelocationOffset(),
-                                     Proc.Header.CodeOffset, &LinkageName);
+                                     Proc.CodeOffset, &LinkageName);
   }
-  W.printHex("Segment", Proc.Header.Segment);
-  W.printFlags("Flags", static_cast<uint8_t>(Proc.Header.Flags),
+  W.printHex("Segment", Proc.Segment);
+  W.printFlags("Flags", static_cast<uint8_t>(Proc.Flags),
                getProcSymFlagNames());
   W.printString("DisplayName", Proc.Name);
   if (!LinkageName.empty())
@@ -638,9 +624,9 @@ Error CVSymbolDumperImpl::visitKnownReco
                                            RegRelativeSym &RegRel) {
   DictScope S(W, "RegRelativeSym");
 
-  W.printHex("Offset", RegRel.Header.Offset);
-  CVTD.printTypeIndex("Type", RegRel.Header.Type);
-  W.printHex("Register", RegRel.Header.Register);
+  W.printHex("Offset", RegRel.Offset);
+  CVTD.printTypeIndex("Type", RegRel.Type);
+  W.printHex("Register", RegRel.Register);
   W.printString("VarName", RegRel.Name);
   return Error::success();
 }
@@ -652,9 +638,9 @@ Error CVSymbolDumperImpl::visitKnownReco
   StringRef LinkageName;
   if (ObjDelegate) {
     ObjDelegate->printRelocatedField("DataOffset", Data.getRelocationOffset(),
-                                     Data.Header.DataOffset, &LinkageName);
+                                     Data.DataOffset, &LinkageName);
   }
-  CVTD.printTypeIndex("Type", Data.Header.Type);
+  CVTD.printTypeIndex("Type", Data.Type);
   W.printString("DisplayName", Data.Name);
   if (!LinkageName.empty())
     W.printString("LinkageName", LinkageName);
@@ -663,7 +649,7 @@ Error CVSymbolDumperImpl::visitKnownReco
 
 Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
   DictScope S(W, "UDT");
-  CVTD.printTypeIndex("Type", UDT.Header.Type);
+  CVTD.printTypeIndex("Type", UDT.Type);
   W.printString("UDTName", UDT.Name);
   return Error::success();
 }

Added: llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp?rev=290000&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp (added)
+++ llvm/trunk/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp Fri Dec 16 16:48:14 2016
@@ -0,0 +1,464 @@
+//===- SymbolRecordMapping.cpp -----------------------------------*- C++-*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h"
+
+using namespace llvm;
+using namespace llvm::codeview;
+
+#define error(X)                                                               \
+  if (auto EC = X)                                                             \
+    return EC;
+
+namespace {
+struct MapGap {
+  Error operator()(CodeViewRecordIO &IO, LocalVariableAddrGap &Gap) const {
+    error(IO.mapInteger(Gap.GapStartOffset));
+    error(IO.mapInteger(Gap.Range));
+    return Error::success();
+  }
+};
+}
+
+static Error mapLocalVariableAddrRange(CodeViewRecordIO &IO,
+                                       LocalVariableAddrRange &Range) {
+  error(IO.mapInteger(Range.OffsetStart));
+  error(IO.mapInteger(Range.ISectStart));
+  error(IO.mapInteger(Range.Range));
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitSymbolBegin(CVSymbol &Record) {
+  error(IO.beginRecord(MaxRecordLength - sizeof(RecordPrefix)));
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitSymbolEnd(CVSymbol &Record) {
+  error(IO.endRecord());
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, BlockSym &Block) {
+
+  error(IO.mapInteger(Block.Parent));
+  error(IO.mapInteger(Block.End));
+  error(IO.mapInteger(Block.CodeSize));
+  error(IO.mapInteger(Block.CodeOffset));
+  error(IO.mapInteger(Block.Segment));
+  error(IO.mapStringZ(Block.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {
+
+  error(IO.mapInteger(Thunk.Parent));
+  error(IO.mapInteger(Thunk.End));
+  error(IO.mapInteger(Thunk.Next));
+  error(IO.mapInteger(Thunk.Offset));
+  error(IO.mapInteger(Thunk.Segment));
+  error(IO.mapInteger(Thunk.Length));
+  error(IO.mapEnum(Thunk.Thunk));
+  error(IO.mapStringZ(Thunk.Name));
+  error(IO.mapByteVectorTail(Thunk.VariantData));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            TrampolineSym &Tramp) {
+
+  error(IO.mapEnum(Tramp.Type));
+  error(IO.mapInteger(Tramp.Size));
+  error(IO.mapInteger(Tramp.ThunkOffset));
+  error(IO.mapInteger(Tramp.TargetOffset));
+  error(IO.mapInteger(Tramp.ThunkSection));
+  error(IO.mapInteger(Tramp.TargetSection));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            SectionSym &Section) {
+  uint8_t Padding = 0;
+
+  error(IO.mapInteger(Section.SectionNumber));
+  error(IO.mapInteger(Section.Alignment));
+  error(IO.mapInteger(Padding));
+  error(IO.mapInteger(Section.Rva));
+  error(IO.mapInteger(Section.Length));
+  error(IO.mapInteger(Section.Characteristics));
+  error(IO.mapStringZ(Section.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            CoffGroupSym &CoffGroup) {
+
+  error(IO.mapInteger(CoffGroup.Size));
+  error(IO.mapInteger(CoffGroup.Characteristics));
+  error(IO.mapInteger(CoffGroup.Offset));
+  error(IO.mapInteger(CoffGroup.Segment));
+  error(IO.mapStringZ(CoffGroup.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            BPRelativeSym &BPRel) {
+
+  error(IO.mapInteger(BPRel.Offset));
+  error(IO.mapInteger(BPRel.Type));
+  error(IO.mapStringZ(BPRel.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            BuildInfoSym &BuildInfo) {
+
+  error(IO.mapInteger(BuildInfo.BuildId));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            CallSiteInfoSym &CallSiteInfo) {
+  uint16_t Padding = 0;
+
+  error(IO.mapInteger(CallSiteInfo.CodeOffset));
+  error(IO.mapInteger(CallSiteInfo.Segment));
+  error(IO.mapInteger(Padding));
+  error(IO.mapInteger(CallSiteInfo.Type));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            EnvBlockSym &EnvBlock) {
+
+  uint8_t Reserved = 0;
+  error(IO.mapInteger(Reserved));
+  error(IO.mapStringZVectorZ(EnvBlock.Fields));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            FileStaticSym &FileStatic) {
+
+  error(IO.mapInteger(FileStatic.Index));
+  error(IO.mapInteger(FileStatic.ModFilenameOffset));
+  error(IO.mapEnum(FileStatic.Flags));
+  error(IO.mapStringZ(FileStatic.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {
+
+  error(IO.mapInteger(Export.Ordinal));
+  error(IO.mapEnum(Export.Flags));
+  error(IO.mapStringZ(Export.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            Compile2Sym &Compile2) {
+
+  error(IO.mapEnum(Compile2.Flags));
+  error(IO.mapEnum(Compile2.Machine));
+  error(IO.mapInteger(Compile2.VersionFrontendMajor));
+  error(IO.mapInteger(Compile2.VersionFrontendMinor));
+  error(IO.mapInteger(Compile2.VersionFrontendBuild));
+  error(IO.mapInteger(Compile2.VersionBackendMajor));
+  error(IO.mapInteger(Compile2.VersionBackendMinor));
+  error(IO.mapInteger(Compile2.VersionBackendBuild));
+  error(IO.mapStringZ(Compile2.Version));
+  error(IO.mapStringZVectorZ(Compile2.ExtraStrings));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            Compile3Sym &Compile3) {
+
+  error(IO.mapEnum(Compile3.Flags));
+  error(IO.mapEnum(Compile3.Machine));
+  error(IO.mapInteger(Compile3.VersionFrontendMajor));
+  error(IO.mapInteger(Compile3.VersionFrontendMinor));
+  error(IO.mapInteger(Compile3.VersionFrontendBuild));
+  error(IO.mapInteger(Compile3.VersionFrontendQFE));
+  error(IO.mapInteger(Compile3.VersionBackendMajor));
+  error(IO.mapInteger(Compile3.VersionBackendMinor));
+  error(IO.mapInteger(Compile3.VersionBackendBuild));
+  error(IO.mapInteger(Compile3.VersionBackendQFE));
+  error(IO.mapStringZ(Compile3.Version));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            ConstantSym &Constant) {
+
+  error(IO.mapInteger(Constant.Type));
+  error(IO.mapEncodedInteger(Constant.Value));
+  error(IO.mapStringZ(Constant.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {
+
+  error(IO.mapInteger(Data.Type));
+  error(IO.mapInteger(Data.DataOffset));
+  error(IO.mapInteger(Data.Segment));
+  error(IO.mapStringZ(Data.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(
+    CVSymbol &CVR, DefRangeFramePointerRelSym &DefRangeFramePointerRel) {
+
+  error(IO.mapInteger(DefRangeFramePointerRel.Offset));
+  error(mapLocalVariableAddrRange(IO, DefRangeFramePointerRel.Range));
+  error(IO.mapVectorTail(DefRangeFramePointerRel.Gaps, MapGap()));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(
+    CVSymbol &CVR,
+    DefRangeFramePointerRelFullScopeSym &DefRangeFramePointerRelFullScope) {
+
+  error(IO.mapInteger(DefRangeFramePointerRelFullScope.Offset));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(
+    CVSymbol &CVR, DefRangeRegisterRelSym &DefRangeRegisterRel) {
+
+  error(IO.mapObject(DefRangeRegisterRel.Hdr.Register));
+  error(IO.mapObject(DefRangeRegisterRel.Hdr.Flags));
+  error(IO.mapObject(DefRangeRegisterRel.Hdr.BasePointerOffset));
+  error(mapLocalVariableAddrRange(IO, DefRangeRegisterRel.Range));
+  error(IO.mapVectorTail(DefRangeRegisterRel.Gaps, MapGap()));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(
+    CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {
+
+  error(IO.mapObject(DefRangeRegister.Hdr.Register));
+  error(IO.mapObject(DefRangeRegister.Hdr.MayHaveNoName));
+  error(mapLocalVariableAddrRange(IO, DefRangeRegister.Range));
+  error(IO.mapVectorTail(DefRangeRegister.Gaps, MapGap()));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(
+    CVSymbol &CVR, DefRangeSubfieldRegisterSym &DefRangeSubfieldRegister) {
+
+  error(IO.mapObject(DefRangeSubfieldRegister.Hdr.Register));
+  error(IO.mapObject(DefRangeSubfieldRegister.Hdr.MayHaveNoName));
+  error(IO.mapObject(DefRangeSubfieldRegister.Hdr.OffsetInParent));
+  error(mapLocalVariableAddrRange(IO, DefRangeSubfieldRegister.Range));
+  error(IO.mapVectorTail(DefRangeSubfieldRegister.Gaps, MapGap()));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(
+    CVSymbol &CVR, DefRangeSubfieldSym &DefRangeSubfield) {
+
+  error(IO.mapInteger(DefRangeSubfield.Program));
+  error(IO.mapInteger(DefRangeSubfield.OffsetInParent));
+  error(mapLocalVariableAddrRange(IO, DefRangeSubfield.Range));
+  error(IO.mapVectorTail(DefRangeSubfield.Gaps, MapGap()));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            DefRangeSym &DefRange) {
+
+  error(IO.mapInteger(DefRange.Program));
+  error(mapLocalVariableAddrRange(IO, DefRange.Range));
+  error(IO.mapVectorTail(DefRange.Gaps, MapGap()));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            FrameCookieSym &FrameCookie) {
+
+  error(IO.mapInteger(FrameCookie.CodeOffset));
+  error(IO.mapInteger(FrameCookie.Register));
+  error(IO.mapInteger(FrameCookie.CookieKind));
+  error(IO.mapInteger(FrameCookie.Flags));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            FrameProcSym &FrameProc) {
+  error(IO.mapInteger(FrameProc.TotalFrameBytes));
+  error(IO.mapInteger(FrameProc.PaddingFrameBytes));
+  error(IO.mapInteger(FrameProc.OffsetToPadding));
+  error(IO.mapInteger(FrameProc.BytesOfCalleeSavedRegisters));
+  error(IO.mapInteger(FrameProc.OffsetOfExceptionHandler));
+  error(IO.mapInteger(FrameProc.SectionIdOfExceptionHandler));
+  error(IO.mapEnum(FrameProc.Flags));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(
+    CVSymbol &CVR, HeapAllocationSiteSym &HeapAllocSite) {
+
+  error(IO.mapInteger(HeapAllocSite.CodeOffset));
+  error(IO.mapInteger(HeapAllocSite.Segment));
+  error(IO.mapInteger(HeapAllocSite.CallInstructionSize));
+  error(IO.mapInteger(HeapAllocSite.Type));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            InlineSiteSym &InlineSite) {
+
+  error(IO.mapInteger(InlineSite.Parent));
+  error(IO.mapInteger(InlineSite.End));
+  error(IO.mapInteger(InlineSite.Inlinee));
+  error(IO.mapByteVectorTail(InlineSite.AnnotationData));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            RegisterSym &Register) {
+
+  error(IO.mapInteger(Register.Index));
+  error(IO.mapEnum(Register.Register));
+  error(IO.mapStringZ(Register.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            PublicSym32 &Public) {
+
+  error(IO.mapInteger(Public.Index));
+  error(IO.mapInteger(Public.Offset));
+  error(IO.mapInteger(Public.Segment));
+  error(IO.mapStringZ(Public.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            ProcRefSym &ProcRef) {
+
+  error(IO.mapInteger(ProcRef.SumName));
+  error(IO.mapInteger(ProcRef.SymOffset));
+  error(IO.mapInteger(ProcRef.Module));
+  error(IO.mapStringZ(ProcRef.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {
+
+  error(IO.mapInteger(Label.CodeOffset));
+  error(IO.mapInteger(Label.Segment));
+  error(IO.mapEnum(Label.Flags));
+  error(IO.mapStringZ(Label.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
+  error(IO.mapInteger(Local.Type));
+  error(IO.mapEnum(Local.Flags));
+  error(IO.mapStringZ(Local.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            ObjNameSym &ObjName) {
+
+  error(IO.mapInteger(ObjName.Signature));
+  error(IO.mapStringZ(ObjName.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {
+  error(IO.mapInteger(Proc.Parent));
+  error(IO.mapInteger(Proc.End));
+  error(IO.mapInteger(Proc.Next));
+  error(IO.mapInteger(Proc.CodeSize));
+  error(IO.mapInteger(Proc.DbgStart));
+  error(IO.mapInteger(Proc.DbgEnd));
+  error(IO.mapInteger(Proc.FunctionType));
+  error(IO.mapInteger(Proc.CodeOffset));
+  error(IO.mapInteger(Proc.Segment));
+  error(IO.mapEnum(Proc.Flags));
+  error(IO.mapStringZ(Proc.Name));
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            ScopeEndSym &ScopeEnd) {
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {
+  error(IO.mapVectorN<uint32_t>(
+      Caller.Indices,
+      [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); }));
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            RegRelativeSym &RegRel) {
+
+  error(IO.mapInteger(RegRel.Offset));
+  error(IO.mapInteger(RegRel.Type));
+  error(IO.mapInteger(RegRel.Register));
+  error(IO.mapStringZ(RegRel.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
+                                            ThreadLocalDataSym &Data) {
+
+  error(IO.mapInteger(Data.Type));
+  error(IO.mapInteger(Data.DataOffset));
+  error(IO.mapInteger(Data.Segment));
+  error(IO.mapStringZ(Data.Name));
+
+  return Error::success();
+}
+
+Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
+
+  error(IO.mapInteger(UDT.Type));
+  error(IO.mapStringZ(UDT.Name));
+
+  return Error::success();
+}

Added: llvm/trunk/lib/DebugInfo/CodeView/SymbolSerializer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/SymbolSerializer.cpp?rev=290000&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/SymbolSerializer.cpp (added)
+++ llvm/trunk/lib/DebugInfo/CodeView/SymbolSerializer.cpp Fri Dec 16 16:48:14 2016
@@ -0,0 +1 @@
+#include "llvm/DebugInfo/CodeView/SymbolSerializer.h"
\ No newline at end of file

Modified: llvm/trunk/lib/MC/MCCodeView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCCodeView.cpp?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCCodeView.cpp (original)
+++ llvm/trunk/lib/MC/MCCodeView.cpp Fri Dec 16 16:48:14 2016
@@ -361,7 +361,9 @@ void CodeViewContext::encodeInlineLineTa
     // Exit early if our line table would produce an oversized InlineSiteSym
     // record. Account for the ChangeCodeLength annotation emitted after the
     // loop ends.
-    size_t MaxBufferSize = MaxRecordLength - sizeof(InlineSiteSym::Hdr) - 8;
+    constexpr uint32_t InlineSiteSize = 12;
+    constexpr uint32_t AnnotationSize = 8;
+    size_t MaxBufferSize = MaxRecordLength - InlineSiteSize - AnnotationSize;
     if (Buffer.size() >= MaxBufferSize)
       break;
 

Modified: llvm/trunk/test/DebugInfo/PDB/pdb-yaml-symbols.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdb-yaml-symbols.test?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdb-yaml-symbols.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdb-yaml-symbols.test Fri Dec 16 16:48:14 2016
@@ -35,8 +35,8 @@ YAML:               Signature:       0
 YAML:               ObjectName:      'd:\src\llvm\test\DebugInfo\PDB\Inputs\empty.obj'
 YAML:           - Kind:            S_COMPILE3
 YAML:             Compile3Sym:
-YAML:               Flags:           8193
-YAML:               Machine:         7
+YAML:               Flags:           [ SecurityChecks ]
+YAML:               Machine:         Pentium3
 YAML:               FrontendMajor:   18
 YAML:               FrontendMinor:   0
 YAML:               FrontendBuild:   31101
@@ -56,7 +56,7 @@ YAML:               DbgStart:        3
 YAML:               DbgEnd:          8
 YAML:               FunctionType:    4097
 YAML:               Segment:         1
-YAML:               Flags:           1
+YAML:               Flags:           [ HasFP ]
 YAML:               DisplayName:     main
 YAML:           - Kind:            S_FRAMEPROC
 YAML:             FrameProcSym:
@@ -66,7 +66,7 @@ YAML:               OffsetToPadding: 0
 YAML:               BytesOfCalleeSavedRegisters: 0
 YAML:               OffsetOfExceptionHandler: 0
 YAML:               SectionIdOfExceptionHandler: 0
-YAML:               Flags:           1212928
+YAML:               Flags:           [ AsynchronousExceptionHandling, OptimizedForSpeed ]
 YAML:           - Kind:            S_END
 YAML:             ScopeEndSym:
 YAML:           - Kind:            S_BUILDINFO
@@ -83,8 +83,8 @@ YAML:               Signature:       0
 YAML:               ObjectName:      '* Linker *'
 YAML:           - Kind:            S_COMPILE3
 YAML:             Compile3Sym:
-YAML:               Flags:           7
-YAML:               Machine:         3
+YAML:               Flags:           [  ]
+YAML:               Machine:         Intel80386
 YAML:               FrontendMajor:   0
 YAML:               FrontendMinor:   0
 YAML:               FrontendBuild:   0
@@ -96,7 +96,6 @@ YAML:               BackendQFE:      0
 YAML:               Version:         'Microsoft (R) LINK'
 YAML:           - Kind:            S_ENVBLOCK
 YAML:             EnvBlockSym:
-YAML:               Reserved:        0
 YAML:               Entries:
 YAML:                 - cwd
 YAML:                 - 'd:\src\llvm\test\DebugInfo\PDB\Inputs'
@@ -106,7 +105,7 @@ YAML:                 - pdb
 YAML:                 - 'd:\src\llvm\test\DebugInfo\PDB\Inputs\empty.pdb'
 YAML:           - Kind:            S_TRAMPOLINE
 YAML:             TrampolineSym:
-YAML:               Type:            0
+YAML:               Type:            TrampIncremental
 YAML:               Size:            5
 YAML:               ThunkOff:        5
 YAML:               TargetOff:       16
@@ -116,7 +115,6 @@ YAML:           - Kind:            S_SEC
 YAML:             SectionSym:
 YAML:               SectionNumber:   1
 YAML:               Alignment:       12
-YAML:               Reserved:        0
 YAML:               Rva:             4096
 YAML:               Length:          4122
 YAML:               Characteristics: 1610612768
@@ -132,7 +130,6 @@ YAML:           - Kind:            S_SEC
 YAML:             SectionSym:
 YAML:               SectionNumber:   2
 YAML:               Alignment:       12
-YAML:               Reserved:        0
 YAML:               Rva:             12288
 YAML:               Length:          690
 YAML:               Characteristics: 1073741888
@@ -162,7 +159,6 @@ YAML:           - Kind:            S_SEC
 YAML:             SectionSym:
 YAML:               SectionNumber:   3
 YAML:               Alignment:       12
-YAML:               Reserved:        0
 YAML:               Rva:             16384
 YAML:               Length:          4
 YAML:               Characteristics: 3221225536
@@ -178,7 +174,6 @@ YAML:           - Kind:            S_SEC
 YAML:             SectionSym:
 YAML:               SectionNumber:   4
 YAML:               Alignment:       12
-YAML:               Reserved:        0
 YAML:               Rva:             20480
 YAML:               Length:          8
 YAML:               Characteristics: 1107296320

Modified: llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdbdump-headers.test Fri Dec 16 16:48:14 2016
@@ -417,7 +417,6 @@
 ; EMPTY-NEXT:         }
 ; EMPTY-NEXT:         {
 ; EMPTY-NEXT:           EnvBlock {
-; EMPTY-NEXT:             Reserved: 0
 ; EMPTY-NEXT:             Entries [
 ; EMPTY-NEXT:               cwd
 ; EMPTY-NEXT:               d:\src\llvm\test\DebugInfo\PDB\Inputs
@@ -458,7 +457,6 @@
 ; EMPTY-NEXT:           Section {
 ; EMPTY-NEXT:             SectionNumber: 1
 ; EMPTY-NEXT:             Alignment: 12
-; EMPTY-NEXT:             Reserved: 0
 ; EMPTY-NEXT:             Rva: 4096
 ; EMPTY-NEXT:             Length: 4122
 ; EMPTY-NEXT:             Characteristics [ (0x60000020)
@@ -494,7 +492,6 @@
 ; EMPTY-NEXT:           Section {
 ; EMPTY-NEXT:             SectionNumber: 2
 ; EMPTY-NEXT:             Alignment: 12
-; EMPTY-NEXT:             Reserved: 0
 ; EMPTY-NEXT:             Rva: 12288
 ; EMPTY-NEXT:             Length: 690
 ; EMPTY-NEXT:             Characteristics [ (0x40000040)
@@ -560,7 +557,6 @@
 ; EMPTY-NEXT:           Section {
 ; EMPTY-NEXT:             SectionNumber: 3
 ; EMPTY-NEXT:             Alignment: 12
-; EMPTY-NEXT:             Reserved: 0
 ; EMPTY-NEXT:             Rva: 16384
 ; EMPTY-NEXT:             Length: 4
 ; EMPTY-NEXT:             Characteristics [ (0xC0000040)
@@ -596,7 +592,6 @@
 ; EMPTY-NEXT:           Section {
 ; EMPTY-NEXT:             SectionNumber: 4
 ; EMPTY-NEXT:             Alignment: 12
-; EMPTY-NEXT:             Reserved: 0
 ; EMPTY-NEXT:             Rva: 20480
 ; EMPTY-NEXT:             Length: 8
 ; EMPTY-NEXT:             Characteristics [ (0x42000040)
@@ -1255,7 +1250,6 @@
 ; ALL:         }
 ; ALL:         {
 ; ALL:           EnvBlock {
-; ALL:             Reserved: 0
 ; ALL:             Entries [
 ; ALL:               cwd
 ; ALL:               d:\src\llvm\test\DebugInfo\PDB\Inputs
@@ -1280,7 +1274,6 @@
 ; ALL:           Section {
 ; ALL:             SectionNumber: 1
 ; ALL:             Alignment: 12
-; ALL:             Reserved: 0
 ; ALL:             Rva: 4096
 ; ALL:             Length: 4122
 ; ALL:             Characteristics [ (0x60000020)
@@ -1308,7 +1301,6 @@
 ; ALL:           Section {
 ; ALL:             SectionNumber: 2
 ; ALL:             Alignment: 12
-; ALL:             Reserved: 0
 ; ALL:             Rva: 12288
 ; ALL:             Length: 690
 ; ALL:             Characteristics [ (0x40000040)
@@ -1358,7 +1350,6 @@
 ; ALL:           Section {
 ; ALL:             SectionNumber: 3
 ; ALL:             Alignment: 12
-; ALL:             Reserved: 0
 ; ALL:             Rva: 16384
 ; ALL:             Length: 4
 ; ALL:             Characteristics [ (0xC0000040)
@@ -1386,7 +1377,6 @@
 ; ALL:           Section {
 ; ALL:             SectionNumber: 4
 ; ALL:             Alignment: 12
-; ALL:             Reserved: 0
 ; ALL:             Rva: 20480
 ; ALL:             Length: 8
 ; ALL:             Characteristics [ (0x42000040)

Modified: llvm/trunk/tools/llvm-pdbdump/YamlSymbolDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/YamlSymbolDumper.cpp?rev=290000&r1=289999&r2=290000&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/YamlSymbolDumper.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/YamlSymbolDumper.cpp Fri Dec 16 16:48:14 2016
@@ -38,105 +38,197 @@ void ScalarEnumerationTraits<SymbolKind>
     io.enumCase(Value, E.Name.str().c_str(), E.Value);
 }
 
+template <> struct ScalarBitSetTraits<CompileSym2Flags> {
+  static void bitset(IO &io, CompileSym2Flags &Flags) {
+    auto FlagNames = getCompileSym2FlagNames();
+    for (const auto &E : FlagNames) {
+      io.bitSetCase(Flags, E.Name.str().c_str(),
+                    static_cast<CompileSym2Flags>(E.Value));
+    }
+  }
+};
+
+template <> struct ScalarBitSetTraits<CompileSym3Flags> {
+  static void bitset(IO &io, CompileSym3Flags &Flags) {
+    auto FlagNames = getCompileSym3FlagNames();
+    for (const auto &E : FlagNames) {
+      io.bitSetCase(Flags, E.Name.str().c_str(),
+                    static_cast<CompileSym3Flags>(E.Value));
+    }
+  }
+};
+
+template <> struct ScalarBitSetTraits<ExportFlags> {
+  static void bitset(IO &io, ExportFlags &Flags) {
+    auto FlagNames = getExportSymFlagNames();
+    for (const auto &E : FlagNames) {
+      io.bitSetCase(Flags, E.Name.str().c_str(),
+                    static_cast<ExportFlags>(E.Value));
+    }
+  }
+};
+
+template <> struct ScalarBitSetTraits<LocalSymFlags> {
+  static void bitset(IO &io, LocalSymFlags &Flags) {
+    auto FlagNames = getLocalFlagNames();
+    for (const auto &E : FlagNames) {
+      io.bitSetCase(Flags, E.Name.str().c_str(),
+                    static_cast<LocalSymFlags>(E.Value));
+    }
+  }
+};
+
+template <> struct ScalarBitSetTraits<ProcSymFlags> {
+  static void bitset(IO &io, ProcSymFlags &Flags) {
+    auto FlagNames = getProcSymFlagNames();
+    for (const auto &E : FlagNames) {
+      io.bitSetCase(Flags, E.Name.str().c_str(),
+                    static_cast<ProcSymFlags>(E.Value));
+    }
+  }
+};
+
+template <> struct ScalarBitSetTraits<FrameProcedureOptions> {
+  static void bitset(IO &io, FrameProcedureOptions &Flags) {
+    auto FlagNames = getFrameProcSymFlagNames();
+    for (const auto &E : FlagNames) {
+      io.bitSetCase(Flags, E.Name.str().c_str(),
+                    static_cast<FrameProcedureOptions>(E.Value));
+    }
+  }
+};
+
+template <> struct ScalarEnumerationTraits<CPUType> {
+  static void enumeration(IO &io, CPUType &Cpu) {
+    auto CpuNames = getCPUTypeNames();
+    for (const auto &E : CpuNames) {
+      io.enumCase(Cpu, E.Name.str().c_str(), static_cast<CPUType>(E.Value));
+    }
+  }
+};
+
+template <> struct ScalarEnumerationTraits<RegisterId> {
+  static void enumeration(IO &io, RegisterId &Reg) {
+    auto RegNames = getRegisterNames();
+    for (const auto &E : RegNames) {
+      io.enumCase(Reg, E.Name.str().c_str(), static_cast<RegisterId>(E.Value));
+    }
+  }
+};
+
+template <> struct ScalarEnumerationTraits<TrampolineType> {
+  static void enumeration(IO &io, TrampolineType &Tramp) {
+    auto TrampNames = getTrampolineNames();
+    for (const auto &E : TrampNames) {
+      io.enumCase(Tramp, E.Name.str().c_str(),
+                  static_cast<TrampolineType>(E.Value));
+    }
+  }
+};
+
 template <> struct ScalarEnumerationTraits<ThunkOrdinal> {
-  void enumeration(IO &io, ThunkOrdinal Ord) {}
+  static void enumeration(IO &io, ThunkOrdinal &Ord) {
+    auto ThunkNames = getThunkOrdinalNames();
+    for (const auto &E : ThunkNames) {
+      io.enumCase(Ord, E.Name.str().c_str(),
+                  static_cast<ThunkOrdinal>(E.Value));
+    }
+  }
 };
 
 void MappingTraits<ScopeEndSym>::mapping(IO &IO, ScopeEndSym &Obj) {}
 
 void MappingTraits<Thunk32Sym>::mapping(IO &IO, Thunk32Sym &Thunk) {
-  IO.mapRequired("Parent", Thunk.Header.Parent);
-  IO.mapRequired("End", Thunk.Header.End);
-  IO.mapRequired("Next", Thunk.Header.Next);
-  IO.mapRequired("Off", Thunk.Header.Off);
-  IO.mapRequired("Seg", Thunk.Header.Seg);
-  IO.mapRequired("Len", Thunk.Header.Len);
-  IO.mapRequired("Ordinal", Thunk.Header.Ord);
+  IO.mapRequired("Parent", Thunk.Parent);
+  IO.mapRequired("End", Thunk.End);
+  IO.mapRequired("Next", Thunk.Next);
+  IO.mapRequired("Off", Thunk.Offset);
+  IO.mapRequired("Seg", Thunk.Segment);
+  IO.mapRequired("Len", Thunk.Length);
+  IO.mapRequired("Ordinal", Thunk.Thunk);
 }
 
 void MappingTraits<TrampolineSym>::mapping(IO &IO, TrampolineSym &Tramp) {
-  IO.mapRequired("Type", Tramp.Header.Type);
-  IO.mapRequired("Size", Tramp.Header.Size);
-  IO.mapRequired("ThunkOff", Tramp.Header.ThunkOff);
-  IO.mapRequired("TargetOff", Tramp.Header.TargetOff);
-  IO.mapRequired("ThunkSection", Tramp.Header.ThunkSection);
-  IO.mapRequired("TargetSection", Tramp.Header.TargetSection);
+  IO.mapRequired("Type", Tramp.Type);
+  IO.mapRequired("Size", Tramp.Size);
+  IO.mapRequired("ThunkOff", Tramp.ThunkOffset);
+  IO.mapRequired("TargetOff", Tramp.TargetOffset);
+  IO.mapRequired("ThunkSection", Tramp.ThunkSection);
+  IO.mapRequired("TargetSection", Tramp.TargetSection);
 }
 
 void MappingTraits<SectionSym>::mapping(IO &IO, SectionSym &Section) {
-  IO.mapRequired("SectionNumber", Section.Header.SectionNumber);
-  IO.mapRequired("Alignment", Section.Header.Alignment);
-  IO.mapRequired("Reserved", Section.Header.Reserved);
-  IO.mapRequired("Rva", Section.Header.Rva);
-  IO.mapRequired("Length", Section.Header.Length);
-  IO.mapRequired("Characteristics", Section.Header.Characteristics);
+  IO.mapRequired("SectionNumber", Section.SectionNumber);
+  IO.mapRequired("Alignment", Section.Alignment);
+  IO.mapRequired("Rva", Section.Rva);
+  IO.mapRequired("Length", Section.Length);
+  IO.mapRequired("Characteristics", Section.Characteristics);
   IO.mapRequired("Name", Section.Name);
 }
 
 void MappingTraits<CoffGroupSym>::mapping(IO &IO, CoffGroupSym &CoffGroup) {
-  IO.mapRequired("Size", CoffGroup.Header.Size);
-  IO.mapRequired("Characteristics", CoffGroup.Header.Characteristics);
-  IO.mapRequired("Offset", CoffGroup.Header.Offset);
-  IO.mapRequired("Segment", CoffGroup.Header.Segment);
+  IO.mapRequired("Size", CoffGroup.Size);
+  IO.mapRequired("Characteristics", CoffGroup.Characteristics);
+  IO.mapRequired("Offset", CoffGroup.Offset);
+  IO.mapRequired("Segment", CoffGroup.Segment);
   IO.mapRequired("Name", CoffGroup.Name);
 }
 
 void MappingTraits<ExportSym>::mapping(IO &IO, ExportSym &Export) {
-  IO.mapRequired("Ordinal", Export.Header.Ordinal);
-  IO.mapRequired("Flags", Export.Header.Flags);
+  IO.mapRequired("Ordinal", Export.Ordinal);
+  IO.mapRequired("Flags", Export.Flags);
   IO.mapRequired("Name", Export.Name);
 }
 
 void MappingTraits<ProcSym>::mapping(IO &IO, ProcSym &Proc) {
   // TODO: Print the linkage name
 
-  IO.mapRequired("PtrParent", Proc.Header.PtrParent);
-  IO.mapRequired("PtrEnd", Proc.Header.PtrEnd);
-  IO.mapRequired("PtrNext", Proc.Header.PtrNext);
-  IO.mapRequired("CodeSize", Proc.Header.CodeSize);
-  IO.mapRequired("DbgStart", Proc.Header.DbgStart);
-  IO.mapRequired("DbgEnd", Proc.Header.DbgEnd);
-  IO.mapRequired("FunctionType", Proc.Header.FunctionType);
-  IO.mapRequired("Segment", Proc.Header.Segment);
-  IO.mapRequired("Flags", Proc.Header.Flags);
+  IO.mapRequired("PtrParent", Proc.Parent);
+  IO.mapRequired("PtrEnd", Proc.End);
+  IO.mapRequired("PtrNext", Proc.Next);
+  IO.mapRequired("CodeSize", Proc.CodeSize);
+  IO.mapRequired("DbgStart", Proc.DbgStart);
+  IO.mapRequired("DbgEnd", Proc.DbgEnd);
+  IO.mapRequired("FunctionType", Proc.FunctionType);
+  IO.mapRequired("Segment", Proc.Segment);
+  IO.mapRequired("Flags", Proc.Flags);
   IO.mapRequired("DisplayName", Proc.Name);
 }
 
 void MappingTraits<RegisterSym>::mapping(IO &IO, RegisterSym &Register) {
-  IO.mapRequired("Type", Register.Header.Index);
-  IO.mapRequired("Seg", Register.Header.Register);
+  IO.mapRequired("Type", Register.Index);
+  IO.mapRequired("Seg", Register.Register);
   IO.mapRequired("Name", Register.Name);
 }
 
 void MappingTraits<PublicSym32>::mapping(IO &IO, PublicSym32 &Public) {
-  IO.mapRequired("Type", Public.Header.Index);
-  IO.mapRequired("Seg", Public.Header.Seg);
-  IO.mapRequired("Off", Public.Header.Off);
+  IO.mapRequired("Type", Public.Index);
+  IO.mapRequired("Seg", Public.Segment);
+  IO.mapRequired("Off", Public.Offset);
   IO.mapRequired("Name", Public.Name);
 }
 
 void MappingTraits<ProcRefSym>::mapping(IO &IO, ProcRefSym &ProcRef) {
-  IO.mapRequired("SumName", ProcRef.Header.SumName);
-  IO.mapRequired("SymOffset", ProcRef.Header.SymOffset);
-  IO.mapRequired("Mod", ProcRef.Header.Mod);
+  IO.mapRequired("SumName", ProcRef.SumName);
+  IO.mapRequired("SymOffset", ProcRef.SymOffset);
+  IO.mapRequired("Mod", ProcRef.Module);
   IO.mapRequired("Name", ProcRef.Name);
 }
 
 void MappingTraits<EnvBlockSym>::mapping(IO &IO, EnvBlockSym &EnvBlock) {
-  IO.mapRequired("Reserved", EnvBlock.Header.Reserved);
   IO.mapRequired("Entries", EnvBlock.Fields);
 }
 
 void MappingTraits<InlineSiteSym>::mapping(IO &IO, InlineSiteSym &InlineSite) {
-  IO.mapRequired("PtrParent", InlineSite.Header.PtrParent);
-  IO.mapRequired("PtrEnd", InlineSite.Header.PtrEnd);
-  IO.mapRequired("Inlinee", InlineSite.Header.Inlinee);
+  IO.mapRequired("PtrParent", InlineSite.Parent);
+  IO.mapRequired("PtrEnd", InlineSite.End);
+  IO.mapRequired("Inlinee", InlineSite.Inlinee);
   // TODO: The binary annotations
 }
 
 void MappingTraits<LocalSym>::mapping(IO &IO, LocalSym &Local) {
-  IO.mapRequired("Type", Local.Header.Type);
-  IO.mapRequired("Flags", Local.Header.Flags);
+  IO.mapRequired("Type", Local.Type);
+  IO.mapRequired("Flags", Local.Flags);
   IO.mapRequired("VarName", Local.Name);
 }
 
@@ -176,95 +268,93 @@ void MappingTraits<DefRangeRegisterRelSy
 
 void MappingTraits<BlockSym>::mapping(IO &IO, BlockSym &Block) {
   // TODO: Print the linkage name
-  IO.mapRequired("PtrParent", Block.Header.PtrParent);
-  IO.mapRequired("PtrEnd", Block.Header.PtrEnd);
-  IO.mapRequired("CodeSize", Block.Header.CodeSize);
-  IO.mapRequired("Segment", Block.Header.Segment);
+  IO.mapRequired("PtrParent", Block.Parent);
+  IO.mapRequired("PtrEnd", Block.End);
+  IO.mapRequired("CodeSize", Block.CodeSize);
+  IO.mapRequired("Segment", Block.Segment);
   IO.mapRequired("BlockName", Block.Name);
 }
 
 void MappingTraits<LabelSym>::mapping(IO &IO, LabelSym &Label) {
   // TODO: Print the linkage name
-  IO.mapRequired("Segment", Label.Header.Segment);
-  IO.mapRequired("Flags", Label.Header.Flags);
-  IO.mapRequired("Flags", Label.Header.Flags);
+  IO.mapRequired("Segment", Label.Segment);
+  IO.mapRequired("Flags", Label.Flags);
+  IO.mapRequired("Flags", Label.Flags);
   IO.mapRequired("DisplayName", Label.Name);
 }
 
 void MappingTraits<ObjNameSym>::mapping(IO &IO, ObjNameSym &ObjName) {
-  IO.mapRequired("Signature", ObjName.Header.Signature);
+  IO.mapRequired("Signature", ObjName.Signature);
   IO.mapRequired("ObjectName", ObjName.Name);
 }
 
 void MappingTraits<Compile2Sym>::mapping(IO &IO, Compile2Sym &Compile2) {
-  IO.mapRequired("Flags", Compile2.Header.flags);
-  IO.mapRequired("Machine", Compile2.Header.Machine);
-  IO.mapRequired("FrontendMajor", Compile2.Header.VersionFrontendMajor);
-  IO.mapRequired("FrontendMinor", Compile2.Header.VersionFrontendMinor);
-  IO.mapRequired("FrontendBuild", Compile2.Header.VersionFrontendBuild);
-  IO.mapRequired("BackendMajor", Compile2.Header.VersionBackendMajor);
-  IO.mapRequired("BackendMinor", Compile2.Header.VersionBackendMinor);
-  IO.mapRequired("BackendBuild", Compile2.Header.VersionBackendBuild);
+  IO.mapRequired("Flags", Compile2.Flags);
+  IO.mapRequired("Machine", Compile2.Machine);
+  IO.mapRequired("FrontendMajor", Compile2.VersionFrontendMajor);
+  IO.mapRequired("FrontendMinor", Compile2.VersionFrontendMinor);
+  IO.mapRequired("FrontendBuild", Compile2.VersionFrontendBuild);
+  IO.mapRequired("BackendMajor", Compile2.VersionBackendMajor);
+  IO.mapRequired("BackendMinor", Compile2.VersionBackendMinor);
+  IO.mapRequired("BackendBuild", Compile2.VersionBackendBuild);
   IO.mapRequired("Version", Compile2.Version);
 }
 
 void MappingTraits<Compile3Sym>::mapping(IO &IO, Compile3Sym &Compile3) {
-  IO.mapRequired("Flags", Compile3.Header.flags);
-  IO.mapRequired("Machine", Compile3.Header.Machine);
-  IO.mapRequired("FrontendMajor", Compile3.Header.VersionFrontendMajor);
-  IO.mapRequired("FrontendMinor", Compile3.Header.VersionFrontendMinor);
-  IO.mapRequired("FrontendBuild", Compile3.Header.VersionFrontendBuild);
-  IO.mapRequired("FrontendQFE", Compile3.Header.VersionFrontendQFE);
-  IO.mapRequired("BackendMajor", Compile3.Header.VersionBackendMajor);
-  IO.mapRequired("BackendMinor", Compile3.Header.VersionBackendMinor);
-  IO.mapRequired("BackendBuild", Compile3.Header.VersionBackendBuild);
-  IO.mapRequired("BackendQFE", Compile3.Header.VersionBackendQFE);
+  IO.mapRequired("Flags", Compile3.Flags);
+  IO.mapRequired("Machine", Compile3.Machine);
+  IO.mapRequired("FrontendMajor", Compile3.VersionFrontendMajor);
+  IO.mapRequired("FrontendMinor", Compile3.VersionFrontendMinor);
+  IO.mapRequired("FrontendBuild", Compile3.VersionFrontendBuild);
+  IO.mapRequired("FrontendQFE", Compile3.VersionFrontendQFE);
+  IO.mapRequired("BackendMajor", Compile3.VersionBackendMajor);
+  IO.mapRequired("BackendMinor", Compile3.VersionBackendMinor);
+  IO.mapRequired("BackendBuild", Compile3.VersionBackendBuild);
+  IO.mapRequired("BackendQFE", Compile3.VersionBackendQFE);
   IO.mapRequired("Version", Compile3.Version);
 }
 
 void MappingTraits<FrameProcSym>::mapping(IO &IO, FrameProcSym &FrameProc) {
-  IO.mapRequired("TotalFrameBytes", FrameProc.Header.TotalFrameBytes);
-  IO.mapRequired("PaddingFrameBytes", FrameProc.Header.PaddingFrameBytes);
-  IO.mapRequired("OffsetToPadding", FrameProc.Header.OffsetToPadding);
+  IO.mapRequired("TotalFrameBytes", FrameProc.TotalFrameBytes);
+  IO.mapRequired("PaddingFrameBytes", FrameProc.PaddingFrameBytes);
+  IO.mapRequired("OffsetToPadding", FrameProc.OffsetToPadding);
   IO.mapRequired("BytesOfCalleeSavedRegisters",
-                 FrameProc.Header.BytesOfCalleeSavedRegisters);
+                 FrameProc.BytesOfCalleeSavedRegisters);
   IO.mapRequired("OffsetOfExceptionHandler",
-                 FrameProc.Header.OffsetOfExceptionHandler);
+                 FrameProc.OffsetOfExceptionHandler);
   IO.mapRequired("SectionIdOfExceptionHandler",
-                 FrameProc.Header.SectionIdOfExceptionHandler);
-  IO.mapRequired("Flags", FrameProc.Header.Flags);
+                 FrameProc.SectionIdOfExceptionHandler);
+  IO.mapRequired("Flags", FrameProc.Flags);
 }
 
 void MappingTraits<CallSiteInfoSym>::mapping(IO &IO,
                                              CallSiteInfoSym &CallSiteInfo) {
   // TODO: Map Linkage Name
-  IO.mapRequired("Segment", CallSiteInfo.Header.Segment);
-  IO.mapRequired("Reserved", CallSiteInfo.Header.Reserved);
-  IO.mapRequired("Type", CallSiteInfo.Header.Type);
+  IO.mapRequired("Segment", CallSiteInfo.Segment);
+  IO.mapRequired("Type", CallSiteInfo.Type);
 }
 
 void MappingTraits<FileStaticSym>::mapping(IO &IO, FileStaticSym &FileStatic) {
-  IO.mapRequired("Index", FileStatic.Header.Index);
-  IO.mapRequired("ModFilenameOffset", FileStatic.Header.ModFilenameOffset);
-  IO.mapRequired("Flags", FileStatic.Header.Flags);
+  IO.mapRequired("Index", FileStatic.Index);
+  IO.mapRequired("ModFilenameOffset", FileStatic.ModFilenameOffset);
+  IO.mapRequired("Flags", FileStatic.Flags);
   IO.mapRequired("Name", FileStatic.Name);
 }
 
 void MappingTraits<HeapAllocationSiteSym>::mapping(
     IO &IO, HeapAllocationSiteSym &HeapAllocSite) {
   // TODO: Map Linkage Name
-  IO.mapRequired("Segment", HeapAllocSite.Header.Segment);
-  IO.mapRequired("CallInstructionSize",
-                 HeapAllocSite.Header.CallInstructionSize);
-  IO.mapRequired("Type", HeapAllocSite.Header.Type);
+  IO.mapRequired("Segment", HeapAllocSite.Segment);
+  IO.mapRequired("CallInstructionSize", HeapAllocSite.CallInstructionSize);
+  IO.mapRequired("Type", HeapAllocSite.Type);
 }
 
 void MappingTraits<FrameCookieSym>::mapping(IO &IO,
                                             FrameCookieSym &FrameCookie) {
   // TODO: Map Linkage Name
-  IO.mapRequired("Register", FrameCookie.Header.Register);
-  IO.mapRequired("CookieKind", FrameCookie.Header.CookieKind);
-  IO.mapRequired("Flags", FrameCookie.Header.Flags);
+  IO.mapRequired("Register", FrameCookie.Register);
+  IO.mapRequired("CookieKind", FrameCookie.CookieKind);
+  IO.mapRequired("Flags", FrameCookie.Flags);
 }
 
 void MappingTraits<CallerSym>::mapping(IO &IO, CallerSym &Caller) {
@@ -274,43 +364,43 @@ void MappingTraits<CallerSym>::mapping(I
 }
 
 void MappingTraits<UDTSym>::mapping(IO &IO, UDTSym &UDT) {
-  IO.mapRequired("Type", UDT.Header.Type);
+  IO.mapRequired("Type", UDT.Type);
   IO.mapRequired("UDTName", UDT.Name);
 }
 
 void MappingTraits<BuildInfoSym>::mapping(IO &IO, BuildInfoSym &BuildInfo) {
-  IO.mapRequired("BuildId", BuildInfo.Header.BuildId);
+  IO.mapRequired("BuildId", BuildInfo.BuildId);
 }
 
 void MappingTraits<BPRelativeSym>::mapping(IO &IO, BPRelativeSym &BPRel) {
-  IO.mapRequired("Offset", BPRel.Header.Offset);
-  IO.mapRequired("Type", BPRel.Header.Type);
+  IO.mapRequired("Offset", BPRel.Offset);
+  IO.mapRequired("Type", BPRel.Type);
   IO.mapRequired("VarName", BPRel.Name);
 }
 
 void MappingTraits<RegRelativeSym>::mapping(IO &IO, RegRelativeSym &RegRel) {
-  IO.mapRequired("Offset", RegRel.Header.Offset);
-  IO.mapRequired("Type", RegRel.Header.Type);
-  IO.mapRequired("Register", RegRel.Header.Register);
+  IO.mapRequired("Offset", RegRel.Offset);
+  IO.mapRequired("Type", RegRel.Type);
+  IO.mapRequired("Register", RegRel.Register);
   IO.mapRequired("VarName", RegRel.Name);
 }
 
 void MappingTraits<ConstantSym>::mapping(IO &IO, ConstantSym &Constant) {
-  IO.mapRequired("Type", Constant.Header.Type);
+  IO.mapRequired("Type", Constant.Type);
   IO.mapRequired("Value", Constant.Value);
   IO.mapRequired("Name", Constant.Name);
 }
 
 void MappingTraits<DataSym>::mapping(IO &IO, DataSym &Data) {
   // TODO: Map linkage name
-  IO.mapRequired("Type", Data.Header.Type);
+  IO.mapRequired("Type", Data.Type);
   IO.mapRequired("DisplayName", Data.Name);
 }
 
 void MappingTraits<ThreadLocalDataSym>::mapping(IO &IO,
                                                 ThreadLocalDataSym &Data) {
   // TODO: Map linkage name
-  IO.mapRequired("Type", Data.Header.Type);
+  IO.mapRequired("Type", Data.Type);
   IO.mapRequired("DisplayName", Data.Name);
 }
 }




More information about the llvm-commits mailing list