mirror of
https://github.com/RPCS3/llvm.git
synced 2026-01-31 01:25:19 +01:00
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
78 lines
2.5 KiB
C++
78 lines
2.5 KiB
C++
//===- NameMap.cpp - PDB Name Map -------------------------------*- 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/PDB/Raw/NameMap.h"
|
|
|
|
#include "llvm/ADT/SparseBitVector.h"
|
|
#include "llvm/ADT/StringMap.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/ADT/iterator_range.h"
|
|
#include "llvm/DebugInfo/MSF/StreamReader.h"
|
|
#include "llvm/DebugInfo/PDB/Raw/HashTable.h"
|
|
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::msf;
|
|
using namespace llvm::pdb;
|
|
|
|
NameMap::NameMap() = default;
|
|
|
|
Error NameMap::load(StreamReader &Stream) {
|
|
uint32_t StringBufferSize;
|
|
if (auto EC = Stream.readInteger(StringBufferSize))
|
|
return joinErrors(std::move(EC),
|
|
make_error<RawError>(raw_error_code::corrupt_file,
|
|
"Expected string buffer size"));
|
|
|
|
msf::ReadableStreamRef StringsBuffer;
|
|
if (auto EC = Stream.readStreamRef(StringsBuffer, StringBufferSize))
|
|
return EC;
|
|
|
|
HashTable OffsetIndexMap;
|
|
if (auto EC = OffsetIndexMap.load(Stream))
|
|
return EC;
|
|
|
|
uint32_t NameOffset;
|
|
uint32_t NameIndex;
|
|
for (const auto &Entry : OffsetIndexMap) {
|
|
std::tie(NameOffset, NameIndex) = Entry;
|
|
|
|
// Compute the offset of the start of the string relative to the stream.
|
|
msf::StreamReader NameReader(StringsBuffer);
|
|
NameReader.setOffset(NameOffset);
|
|
// Pump out our c-string from the stream.
|
|
StringRef Str;
|
|
if (auto EC = NameReader.readZeroString(Str))
|
|
return joinErrors(std::move(EC),
|
|
make_error<RawError>(raw_error_code::corrupt_file,
|
|
"Expected name map name"));
|
|
|
|
// Add this to a string-map from name to stream number.
|
|
Mapping.insert({Str, NameIndex});
|
|
}
|
|
|
|
return Error::success();
|
|
}
|
|
|
|
iterator_range<StringMapConstIterator<uint32_t>> NameMap::entries() const {
|
|
return make_range<StringMapConstIterator<uint32_t>>(Mapping.begin(),
|
|
Mapping.end());
|
|
}
|
|
|
|
bool NameMap::tryGetValue(StringRef Name, uint32_t &Value) const {
|
|
auto Iter = Mapping.find(Name);
|
|
if (Iter == Mapping.end())
|
|
return false;
|
|
Value = Iter->second;
|
|
return true;
|
|
}
|