[PDB] Emit TPI and IPI hashes

llvm-svn: 308497
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index 89462da..96f688c 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -34,6 +34,7 @@
 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
 #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
 #include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
+#include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
 #include "llvm/DebugInfo/PDB/Native/TpiStreamBuilder.h"
 #include "llvm/DebugInfo/PDB/PDB.h"
@@ -163,10 +164,15 @@
   // Start the TPI or IPI stream header.
   TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
 
-  // Flatten the in memory type table.
+  // Flatten the in memory type table and hash each type.
   TypeTable.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Rec) {
-    // FIXME: Hash types.
-    TpiBuilder.addTypeRecord(Rec, None);
+    assert(Rec.size() >= sizeof(RecordPrefix));
+    const RecordPrefix *P = reinterpret_cast<const RecordPrefix *>(Rec.data());
+    CVType Type(static_cast<TypeLeafKind>(unsigned(P->RecordKind)), Rec);
+    auto Hash = pdb::hashTypeRecord(Type);
+    if (auto E = Hash.takeError())
+      fatal("type hashing error");
+    TpiBuilder.addTypeRecord(Rec, *Hash);
   });
 }