Files
archived-llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
Zachary Turner 1efbd52b3e [pdb] Add HashTable data structure.
This was being parsed / serialized ad-hoc inside the code
for a specific PDB stream.  But this data structure is used
in multiple ways / places within the PDB format.  To be able
to re-use it we need to raise this code out and make it more
generic.  In doing so, a number of bugs are fixed in the
original implementation, and support is added for growing
the hash table and deleting items from the hash table,
which had either been omitted or incorrect implemented in
the initial version.

Differential Revision: https://reviews.llvm.org/D28715

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292535 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-19 23:31:24 +00:00

61 lines
1.7 KiB
C++

//===- NameMapBuilder.cpp - PDB Name Map Builder ----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/MSF/StreamWriter.h"
#include "llvm/DebugInfo/PDB/Raw/NameMap.h"
#include "llvm/DebugInfo/PDB/Raw/NameMapBuilder.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include <algorithm>
#include <cstdint>
using namespace llvm;
using namespace llvm::pdb;
NameMapBuilder::NameMapBuilder() = default;
void NameMapBuilder::addMapping(StringRef Name, uint32_t Mapping) {
Strings.push_back(Name);
Map.set(Offset, Mapping);
Offset += Name.size() + 1;
}
uint32_t NameMapBuilder::calculateSerializedLength() const {
uint32_t TotalLength = 0;
// Number of bytes of string data.
TotalLength += sizeof(support::ulittle32_t);
// Followed by that many actual bytes of string data.
TotalLength += Offset;
// Followed by the mapping from Name to Index.
TotalLength += Map.calculateSerializedLength();
return TotalLength;
}
Error NameMapBuilder::commit(msf::StreamWriter &Writer) const {
// The first field is the number of bytes of string data. We've already been
// keeping a running total of this in `Offset`.
if (auto EC = Writer.writeInteger(Offset)) // Number of bytes of string data
return EC;
// Now all of the string data itself.
for (auto S : Strings) {
if (auto EC = Writer.writeZeroString(S))
return EC;
}
// And finally the Linear Map.
if (auto EC = Map.commit(Writer))
return EC;
return Error::success();
}