summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2017-05-03 07:29:25 +0000
committerDaniel Jasper <djasper@google.com>2017-05-03 07:29:25 +0000
commitdff096f217542fc12a69c228536d5b555cb23912 (patch)
treee47fed572e4212072a742d6d684a07f0ef038e45 /llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
parent726701b0ed67c400bc41fe08feb8a19668b59cbf (diff)
downloadbcm5719-llvm-dff096f217542fc12a69c228536d5b555cb23912.tar.gz
bcm5719-llvm-dff096f217542fc12a69c228536d5b555cb23912.zip
Revert r301986 (and subsequent r301987).
The patch is failing to add StringTableStreamBuilder.h, but that isn't even discovered because the corresponding StringTableStreamBuilder.cpp isn't added to any CMakeLists.txt file and thus never built. I think this patch is just incomplete. llvm-svn: 302002
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp')
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp101
1 files changed, 38 insertions, 63 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
index a472181a489..4add6ead212 100644
--- a/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/PDBStringTableBuilder.cpp
@@ -8,23 +8,31 @@
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/PDB/Native/PDBStringTableBuilder.h"
-
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/Native/Hash.h"
-#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
#include "llvm/Support/BinaryStreamWriter.h"
#include "llvm/Support/Endian.h"
using namespace llvm;
-using namespace llvm::msf;
using namespace llvm::support;
using namespace llvm::support::endian;
using namespace llvm::pdb;
uint32_t PDBStringTableBuilder::insert(StringRef S) {
- return Strings.insert(S);
+ auto P = Strings.insert({S, StringSize});
+
+ // If a given string didn't exist in the string table, we want to increment
+ // the string table size.
+ if (P.second)
+ StringSize += S.size() + 1; // +1 for '\0'
+ return P.first->second;
+}
+
+uint32_t PDBStringTableBuilder::getStringIndex(StringRef S) {
+ auto Iter = Strings.find(S);
+ assert(Iter != Strings.end());
+ return Iter->second;
}
static uint32_t computeBucketCount(uint32_t NumStrings) {
@@ -36,52 +44,49 @@ static uint32_t computeBucketCount(uint32_t NumStrings) {
return (NumStrings + 1) * 1.25;
}
-uint32_t PDBStringTableBuilder::calculateHashTableSize() const {
- uint32_t Size = sizeof(uint32_t); // Hash table begins with 4-byte size field.
- Size += sizeof(uint32_t) * computeBucketCount(Strings.size());
-
- return Size;
-}
-
-uint32_t PDBStringTableBuilder::calculateSerializedSize() const {
+uint32_t PDBStringTableBuilder::finalize() {
uint32_t Size = 0;
Size += sizeof(PDBStringTableHeader);
- Size += Strings.calculateSerializedSize();
- Size += calculateHashTableSize();
- Size += sizeof(uint32_t); // The /names stream ends with the string count.
+ Size += StringSize;
+ Size += sizeof(uint32_t); // Hash table begins with 4-byte size field.
+
+ uint32_t BucketCount = computeBucketCount(Strings.size());
+ Size += BucketCount * sizeof(uint32_t);
+
+ Size +=
+ sizeof(uint32_t); // The /names stream ends with the number of strings.
return Size;
}
-Error PDBStringTableBuilder::writeHeader(BinaryStreamWriter &Writer) const {
+Error PDBStringTableBuilder::commit(BinaryStreamWriter &Writer) const {
// Write a header
PDBStringTableHeader H;
H.Signature = PDBStringTableSignature;
H.HashVersion = 1;
- H.ByteSize = Strings.calculateSerializedSize();
+ H.ByteSize = StringSize;
if (auto EC = Writer.writeObject(H))
return EC;
- assert(Writer.bytesRemaining() == 0);
- return Error::success();
-}
-Error PDBStringTableBuilder::writeStrings(BinaryStreamWriter &Writer) const {
- if (auto EC = Strings.commit(Writer))
- return EC;
-
- assert(Writer.bytesRemaining() == 0);
- return Error::success();
-}
+ // Write a string table.
+ uint32_t StringStart = Writer.getOffset();
+ for (auto Pair : Strings) {
+ StringRef S = Pair.first;
+ uint32_t Offset = Pair.second;
+ Writer.setOffset(StringStart + Offset);
+ if (auto EC = Writer.writeCString(S))
+ return EC;
+ }
+ Writer.setOffset(StringStart + StringSize);
-Error PDBStringTableBuilder::writeHashTable(BinaryStreamWriter &Writer) const {
// Write a hash table.
uint32_t BucketCount = computeBucketCount(Strings.size());
if (auto EC = Writer.writeInteger(BucketCount))
return EC;
std::vector<ulittle32_t> Buckets(BucketCount);
- for (auto &Pair : Strings) {
- StringRef S = Pair.getKey();
- uint32_t Offset = Pair.getValue();
+ for (auto Pair : Strings) {
+ StringRef S = Pair.first;
+ uint32_t Offset = Pair.second;
uint32_t Hash = hashStringV1(S);
for (uint32_t I = 0; I != BucketCount; ++I) {
@@ -97,37 +102,7 @@ Error PDBStringTableBuilder::writeHashTable(BinaryStreamWriter &Writer) const {
if (auto EC = Writer.writeArray(ArrayRef<ulittle32_t>(Buckets)))
return EC;
-
- assert(Writer.bytesRemaining() == 0);
- return Error::success();
-}
-
-Error PDBStringTableBuilder::writeEpilogue(BinaryStreamWriter &Writer) const {
- if (auto EC = Writer.writeInteger<uint32_t>(Strings.size()))
- return EC;
- assert(Writer.bytesRemaining() == 0);
- return Error::success();
-}
-
-Error PDBStringTableBuilder::commit(BinaryStreamWriter &Writer) const {
- BinaryStreamWriter SectionWriter;
-
- std::tie(SectionWriter, Writer) = Writer.split(sizeof(PDBStringTableHeader));
- if (auto EC = writeHeader(SectionWriter))
- return EC;
-
- std::tie(SectionWriter, Writer) =
- Writer.split(Strings.calculateSerializedSize());
- if (auto EC = writeStrings(SectionWriter))
+ if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size())))
return EC;
-
- std::tie(SectionWriter, Writer) = Writer.split(calculateHashTableSize());
- if (auto EC = writeHashTable(SectionWriter))
- return EC;
-
- std::tie(SectionWriter, Writer) = Writer.split(sizeof(uint32_t));
- if (auto EC = writeEpilogue(SectionWriter))
- return EC;
-
return Error::success();
}
OpenPOWER on IntegriCloud