aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-07-28 19:12:28 +0000
committerZachary Turner <zturner@google.com>2016-07-28 19:12:28 +0000
commitd66889cbae749ceffca88f094274e2d64c2cb8f8 (patch)
tree81e34f9af216751ced0d50609d558d2f15277b46 /llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
parent199f48a5f0d5aee8737880a78d81216d60cf785d (diff)
downloadllvm-d66889cbae749ceffca88f094274e2d64c2cb8f8.zip
llvm-d66889cbae749ceffca88f094274e2d64c2cb8f8.tar.gz
llvm-d66889cbae749ceffca88f094274e2d64c2cb8f8.tar.bz2
[pdb] Refactor library to more clearly separate reading/writing
Reviewed By: amccarth, ruiu Differential Revision: https://reviews.llvm.org/D22693 llvm-svn: 277019
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp')
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
index 41c6c2c..3bb4503 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
@@ -9,6 +9,7 @@
#include "llvm/DebugInfo/PDB/Raw/NameMapBuilder.h"
+#include "llvm/DebugInfo/Msf/StreamWriter.h"
#include "llvm/DebugInfo/PDB/Raw/NameMap.h"
#include "llvm/Support/Endian.h"
@@ -48,3 +49,57 @@ uint32_t NameMapBuilder::calculateSerializedLength() const {
return TotalLength;
}
+
+Error NameMapBuilder::commit(msf::StreamWriter &Writer) const {
+ // The first field is the number of bytes of string data. So add
+ // up the length of all strings plus a null terminator for each
+ // one.
+ uint32_t NumBytes = 0;
+ for (auto B = Map.begin(), E = Map.end(); B != E; ++B) {
+ NumBytes += B->getKeyLength() + 1;
+ }
+
+ if (auto EC = Writer.writeInteger(NumBytes)) // Number of bytes of string data
+ return EC;
+ // Now all of the string data itself.
+ for (auto B = Map.begin(), E = Map.end(); B != E; ++B) {
+ if (auto EC = Writer.writeZeroString(B->getKey()))
+ return EC;
+ }
+
+ if (auto EC = Writer.writeInteger(Map.size())) // Hash Size
+ return EC;
+
+ if (auto EC = Writer.writeInteger(Map.size())) // Max Number of Strings
+ return EC;
+
+ if (auto EC = Writer.writeInteger(Map.size())) // Num Present Words
+ return EC;
+
+ // For each entry in the mapping, write a bit mask which represents a bucket
+ // to store it in. We don't use this, so the value we write isn't important
+ // to us, it just has to be there.
+ for (auto B = Map.begin(), E = Map.end(); B != E; ++B) {
+ if (auto EC = Writer.writeInteger(1U))
+ return EC;
+ }
+
+ if (auto EC = Writer.writeInteger(0U)) // Num Deleted Words
+ return EC;
+
+ // Mappings of each word.
+ uint32_t OffsetSoFar = 0;
+ for (auto B = Map.begin(), E = Map.end(); B != E; ++B) {
+ // This is a list of key value pairs where the key is the offset into the
+ // strings buffer, and the value is a stream number. Write each pair.
+ if (auto EC = Writer.writeInteger(OffsetSoFar))
+ return EC;
+
+ if (auto EC = Writer.writeInteger(B->second))
+ return EC;
+
+ OffsetSoFar += B->getKeyLength() + 1;
+ }
+
+ return Error::success();
+}