[llvm] r292663 - [PDB] Rename some files to be more intuitive.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 14:41:16 PST 2017
Author: zturner
Date: Fri Jan 20 16:41:15 2017
New Revision: 292663
URL: http://llvm.org/viewvc/llvm-project?rev=292663&view=rev
Log:
[PDB] Rename some files to be more intuitive.
Added:
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMap.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMapBuilder.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTable.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTableBuilder.h
llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMap.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMapBuilder.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/StringTable.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/StringTableBuilder.cpp
llvm/trunk/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp
Removed:
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTableBuilder.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h
llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTableBuilder.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
llvm/trunk/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp
Modified:
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawTypes.h
llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt
llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
llvm/trunk/unittests/DebugInfo/PDB/CMakeLists.txt
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/DbiStream.h Fri Jan 20 16:41:15 2017
@@ -16,9 +16,9 @@
#include "llvm/DebugInfo/MSF/StreamRef.h"
#include "llvm/DebugInfo/PDB/PDBTypes.h"
#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
-#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
+#include "llvm/DebugInfo/PDB/Raw/StringTable.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
@@ -89,7 +89,7 @@ private:
std::unique_ptr<msf::MappedBlockStream> Stream;
std::vector<ModuleInfoEx> ModuleInfos;
- NameHashTable ECNames;
+ StringTable ECNames;
msf::ReadableStreamRef ModInfoSubstream;
msf::ReadableStreamRef SecContrSubstream;
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStream.h Fri Jan 20 16:41:15 2017
@@ -13,7 +13,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/PDB/PDBTypes.h"
-#include "llvm/DebugInfo/PDB/Raw/NameMap.h"
+#include "llvm/DebugInfo/PDB/Raw/NamedStreamMap.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/Support/Endian.h"
@@ -61,7 +61,7 @@ private:
// universally unique.
PDB_UniqueId Guid;
- NameMap NamedStreams;
+ NamedStreamMap NamedStreams;
};
}
}
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h Fri Jan 20 16:41:15 2017
@@ -14,7 +14,7 @@
#include "llvm/Support/Error.h"
#include "llvm/DebugInfo/PDB/PDBTypes.h"
-#include "llvm/DebugInfo/PDB/Raw/NameMapBuilder.h"
+#include "llvm/DebugInfo/PDB/Raw/NamedStreamMapBuilder.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
@@ -37,7 +37,7 @@ public:
void setAge(uint32_t A);
void setGuid(PDB_UniqueId G);
- NameMapBuilder &getNamedStreamsBuilder();
+ NamedStreamMapBuilder &getNamedStreamsBuilder();
uint32_t calculateSerializedLength() const;
@@ -54,7 +54,7 @@ private:
uint32_t Age;
PDB_UniqueId Guid;
- NameMapBuilder NamedStreams;
+ NamedStreamMapBuilder NamedStreams;
};
}
}
Removed: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h?rev=292662&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTable.h (removed)
@@ -1,54 +0,0 @@
-//===- NameHashTable.h - PDB Name Hash Table --------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_PDB_RAW_NAMEHASHTABLE_H
-#define LLVM_DEBUGINFO_PDB_RAW_NAMEHASHTABLE_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/DebugInfo/MSF/StreamArray.h"
-#include "llvm/DebugInfo/MSF/StreamRef.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/Error.h"
-#include <cstdint>
-#include <vector>
-
-namespace llvm {
-namespace msf {
-class StreamReader;
-}
-namespace pdb {
-
-class NameHashTable {
-public:
- NameHashTable();
-
- Error load(msf::StreamReader &Stream);
-
- uint32_t getNameCount() const { return NameCount; }
- uint32_t getHashVersion() const { return HashVersion; }
- uint32_t getSignature() const { return Signature; }
-
- StringRef getStringForID(uint32_t ID) const;
- uint32_t getIDForString(StringRef Str) const;
-
- msf::FixedStreamArray<support::ulittle32_t> name_ids() const;
-
-private:
- msf::ReadableStreamRef NamesBuffer;
- msf::FixedStreamArray<support::ulittle32_t> IDs;
- uint32_t Signature;
- uint32_t HashVersion;
- uint32_t NameCount;
-};
-
-} // end namespace pdb
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_PDB_RAW_NAMEHASHTABLE_H
Removed: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTableBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTableBuilder.h?rev=292662&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTableBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameHashTableBuilder.h (removed)
@@ -1,45 +0,0 @@
-//===- NameHashTableBuilder.h - PDB Name Hash Table Builder -----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file creates the "/names" stream.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_PDB_RAW_NAMEHASHTABLEBUILDER_H
-#define LLVM_DEBUGINFO_PDB_RAW_NAMEHASHTABLEBUILDER_H
-
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Error.h"
-#include <vector>
-
-namespace llvm {
-namespace msf {
-class StreamWriter;
-}
-namespace pdb {
-
-class NameHashTableBuilder {
-public:
- // If string S does not exist in the string table, insert it.
- // Returns the ID for S.
- uint32_t insert(StringRef S);
-
- uint32_t calculateSerializedLength() const;
- Error commit(msf::StreamWriter &Writer) const;
-
-private:
- DenseMap<StringRef, uint32_t> Strings;
- uint32_t StringSize = 1;
-};
-
-} // end namespace pdb
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_PDB_RAW_NAMEHASHTABLEBUILDER_H
Removed: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h?rev=292662&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h (removed)
@@ -1,44 +0,0 @@
-//===- NameMap.h - 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.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAP_H
-#define LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAP_H
-
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Error.h"
-#include <cstdint>
-
-namespace llvm {
-namespace msf {
-class StreamReader;
-class StreamWriter;
-}
-namespace pdb {
-class NameMapBuilder;
-class NameMap {
- friend NameMapBuilder;
-
-public:
- NameMap();
-
- Error load(msf::StreamReader &Stream);
-
- bool tryGetValue(StringRef Name, uint32_t &Value) const;
-
- iterator_range<StringMapConstIterator<uint32_t>> entries() const;
-
-private:
- StringMap<uint32_t> Mapping;
-};
-
-} // end namespace pdb
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAP_H
Removed: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h?rev=292662&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h (removed)
@@ -1,46 +0,0 @@
-//===- NameMapBuilder.h - 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.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAPBUILDER_H
-#define LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAPBUILDER_H
-
-#include "llvm/DebugInfo/PDB/Raw/HashTable.h"
-#include "llvm/Support/Error.h"
-
-#include <cstdint>
-#include <memory>
-#include <vector>
-
-namespace llvm {
-namespace msf {
-class StreamWriter;
-}
-namespace pdb {
-class NameMap;
-
-class NameMapBuilder {
-public:
- NameMapBuilder();
-
- void addMapping(StringRef Name, uint32_t Mapping);
-
- Error commit(msf::StreamWriter &Writer) const;
-
- uint32_t calculateSerializedLength() const;
-
-private:
- std::vector<StringRef> Strings;
- HashTable Map;
- uint32_t Offset = 0;
-};
-
-} // end namespace pdb
-} // end namespace llvm
-
-#endif // LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAPBUILDER_H
Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMap.h?rev=292663&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMap.h (added)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMap.h Fri Jan 20 16:41:15 2017
@@ -0,0 +1,44 @@
+//===- NamedStreamMap.h - PDB Named Stream Map ------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBNAMEDSTREAMMAP_H
+#define LLVM_DEBUGINFO_PDB_RAW_PDBNAMEDSTREAMMAP_H
+
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include <cstdint>
+
+namespace llvm {
+namespace msf {
+class StreamReader;
+class StreamWriter;
+}
+namespace pdb {
+class NamedStreamMapBuilder;
+class NamedStreamMap {
+ friend NamedStreamMapBuilder;
+
+public:
+ NamedStreamMap();
+
+ Error load(msf::StreamReader &Stream);
+
+ bool tryGetValue(StringRef Name, uint32_t &Value) const;
+
+ iterator_range<StringMapConstIterator<uint32_t>> entries() const;
+
+private:
+ StringMap<uint32_t> Mapping;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_PDBNAMEDSTREAMMAP_H
Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMapBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMapBuilder.h?rev=292663&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMapBuilder.h (added)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NamedStreamMapBuilder.h Fri Jan 20 16:41:15 2017
@@ -0,0 +1,45 @@
+//===- NamedStreamMapBuilder.h - PDB Named Stream Map Builder ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBNAMEDSTREAMMAPBUILDER_H
+#define LLVM_DEBUGINFO_PDB_RAW_PDBNAMEDSTREAMMAPBUILDER_H
+
+#include "llvm/DebugInfo/PDB/Raw/HashTable.h"
+#include "llvm/Support/Error.h"
+
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+namespace llvm {
+namespace msf {
+class StreamWriter;
+}
+namespace pdb {
+
+class NamedStreamMapBuilder {
+public:
+ NamedStreamMapBuilder();
+
+ void addMapping(StringRef Name, uint32_t Mapping);
+
+ Error commit(msf::StreamWriter &Writer) const;
+
+ uint32_t calculateSerializedLength() const;
+
+private:
+ std::vector<StringRef> Strings;
+ HashTable Map;
+ uint32_t Offset = 0;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAPBUILDER_H
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h Fri Jan 20 16:41:15 2017
@@ -32,7 +32,7 @@ namespace pdb {
class DbiStream;
class GlobalsStream;
class InfoStream;
-class NameHashTable;
+class StringTable;
class PDBFileBuilder;
class PublicsStream;
class SymbolStream;
@@ -91,7 +91,7 @@ public:
Expected<TpiStream &> getPDBIpiStream();
Expected<PublicsStream &> getPDBPublicsStream();
Expected<SymbolStream &> getPDBSymbolStream();
- Expected<NameHashTable &> getStringTable();
+ Expected<StringTable &> getStringTable();
BumpPtrAllocator &getAllocator() { return Allocator; }
@@ -125,7 +125,7 @@ public:
std::unique_ptr<SymbolStream> Symbols;
std::unique_ptr<msf::MappedBlockStream> DirectoryStream;
std::unique_ptr<msf::MappedBlockStream> StringTableStream;
- std::unique_ptr<NameHashTable> StringTable;
+ std::unique_ptr<StringTable> Strings;
};
}
}
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawTypes.h?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawTypes.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/RawTypes.h Fri Jan 20 16:41:15 2017
@@ -303,13 +303,13 @@ struct InfoStreamHeader {
};
/// The header preceeding the /names stream.
-struct NameHashTableHeader {
+struct StringTableHeader {
support::ulittle32_t Signature;
support::ulittle32_t HashVersion;
support::ulittle32_t ByteSize;
};
-const uint32_t NameHashTableSignature = 0xEFFEEFFE;
+const uint32_t StringTableSignature = 0xEFFEEFFE;
} // namespace pdb
} // namespace llvm
Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTable.h?rev=292663&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTable.h (added)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTable.h Fri Jan 20 16:41:15 2017
@@ -0,0 +1,54 @@
+//===- StringTable.h - PDB String Table -------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_STRINGTABLE_H
+#define LLVM_DEBUGINFO_PDB_RAW_STRINGTABLE_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/MSF/StreamArray.h"
+#include "llvm/DebugInfo/MSF/StreamRef.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
+#include <cstdint>
+#include <vector>
+
+namespace llvm {
+namespace msf {
+class StreamReader;
+}
+namespace pdb {
+
+class StringTable {
+public:
+ StringTable();
+
+ Error load(msf::StreamReader &Stream);
+
+ uint32_t getNameCount() const { return NameCount; }
+ uint32_t getHashVersion() const { return HashVersion; }
+ uint32_t getSignature() const { return Signature; }
+
+ StringRef getStringForID(uint32_t ID) const;
+ uint32_t getIDForString(StringRef Str) const;
+
+ msf::FixedStreamArray<support::ulittle32_t> name_ids() const;
+
+private:
+ msf::ReadableStreamRef NamesBuffer;
+ msf::FixedStreamArray<support::ulittle32_t> IDs;
+ uint32_t Signature;
+ uint32_t HashVersion;
+ uint32_t NameCount;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_STRINGTABLE_H
Added: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTableBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTableBuilder.h?rev=292663&view=auto
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTableBuilder.h (added)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/StringTableBuilder.h Fri Jan 20 16:41:15 2017
@@ -0,0 +1,45 @@
+//===- StringTableBuilder.h - PDB String Table Builder ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file creates the "/names" stream.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_DEBUGINFO_PDB_RAW_STRINGTABLEBUILDER_H
+#define LLVM_DEBUGINFO_PDB_RAW_STRINGTABLEBUILDER_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include <vector>
+
+namespace llvm {
+namespace msf {
+class StreamWriter;
+}
+namespace pdb {
+
+class StringTableBuilder {
+public:
+ // If string S does not exist in the string table, insert it.
+ // Returns the ID for S.
+ uint32_t insert(StringRef S);
+
+ uint32_t calculateSerializedLength() const;
+ Error commit(msf::StreamWriter &Writer) const;
+
+private:
+ DenseMap<StringRef, uint32_t> Strings;
+ uint32_t StringSize = 1;
+};
+
+} // end namespace pdb
+} // end namespace llvm
+
+#endif // LLVM_DEBUGINFO_PDB_RAW_STRINGTABLEBUILDER_H
Modified: llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt (original)
+++ llvm/trunk/lib/DebugInfo/PDB/CMakeLists.txt Fri Jan 20 16:41:15 2017
@@ -39,15 +39,15 @@ add_pdb_impl_folder(Raw
Raw/InfoStreamBuilder.cpp
Raw/ModInfo.cpp
Raw/ModStream.cpp
- Raw/NameHashTable.cpp
- Raw/NameHashTableBuilder.cpp
- Raw/NameMap.cpp
- Raw/NameMapBuilder.cpp
+ Raw/NamedStreamMap.cpp
+ Raw/NamedStreamMapBuilder.cpp
Raw/PDBFile.cpp
Raw/PDBFileBuilder.cpp
Raw/PublicsStream.cpp
Raw/RawError.cpp
Raw/RawSession.cpp
+ Raw/StringTable.cpp
+ Raw/StringTableBuilder.cpp
Raw/SymbolStream.cpp
Raw/TpiHashing.cpp
Raw/TpiStream.cpp
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/DbiStream.cpp Fri Jan 20 16:41:15 2017
@@ -16,7 +16,6 @@
#include "llvm/DebugInfo/PDB/Raw/ISectionContribVisitor.h"
#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
-#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp Fri Jan 20 16:41:15 2017
@@ -32,7 +32,7 @@ void InfoStreamBuilder::setAge(uint32_t
void InfoStreamBuilder::setGuid(PDB_UniqueId G) { Guid = G; }
-NameMapBuilder &InfoStreamBuilder::getNamedStreamsBuilder() {
+NamedStreamMapBuilder &InfoStreamBuilder::getNamedStreamsBuilder() {
return NamedStreams;
}
Removed: llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp?rev=292662&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTable.cpp (removed)
@@ -1,99 +0,0 @@
-//===- NameHashTable.cpp - PDB Name Hash Table ------------------*- 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/NameHashTable.h"
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/DebugInfo/MSF/StreamReader.h"
-#include "llvm/DebugInfo/PDB/Raw/Hash.h"
-#include "llvm/DebugInfo/PDB/Raw/RawError.h"
-#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
-#include "llvm/Support/Endian.h"
-
-using namespace llvm;
-using namespace llvm::msf;
-using namespace llvm::support;
-using namespace llvm::pdb;
-
-NameHashTable::NameHashTable() : Signature(0), HashVersion(0), NameCount(0) {}
-
-Error NameHashTable::load(StreamReader &Stream) {
- const NameHashTableHeader *H;
- if (auto EC = Stream.readObject(H))
- return EC;
-
- if (H->Signature != NameHashTableSignature)
- return make_error<RawError>(raw_error_code::corrupt_file,
- "Invalid hash table signature");
- if (H->HashVersion != 1 && H->HashVersion != 2)
- return make_error<RawError>(raw_error_code::corrupt_file,
- "Unsupported hash version");
-
- Signature = H->Signature;
- HashVersion = H->HashVersion;
- if (auto EC = Stream.readStreamRef(NamesBuffer, H->ByteSize))
- return joinErrors(std::move(EC),
- make_error<RawError>(raw_error_code::corrupt_file,
- "Invalid hash table byte length"));
-
- const support::ulittle32_t *HashCount;
- if (auto EC = Stream.readObject(HashCount))
- return EC;
-
- if (auto EC = Stream.readArray(IDs, *HashCount))
- return joinErrors(std::move(EC),
- make_error<RawError>(raw_error_code::corrupt_file,
- "Could not read bucket array"));
-
- if (Stream.bytesRemaining() < sizeof(support::ulittle32_t))
- return make_error<RawError>(raw_error_code::corrupt_file,
- "Missing name count");
-
- if (auto EC = Stream.readInteger(NameCount))
- return EC;
- return Error::success();
-}
-
-StringRef NameHashTable::getStringForID(uint32_t ID) const {
- if (ID == IDs[0])
- return StringRef();
-
- // NamesBuffer is a buffer of null terminated strings back to back. ID is
- // the starting offset of the string we're looking for. So just seek into
- // the desired offset and a read a null terminated stream from that offset.
- StringRef Result;
- StreamReader NameReader(NamesBuffer);
- NameReader.setOffset(ID);
- if (auto EC = NameReader.readZeroString(Result))
- consumeError(std::move(EC));
- return Result;
-}
-
-uint32_t NameHashTable::getIDForString(StringRef Str) const {
- uint32_t Hash = (HashVersion == 1) ? hashStringV1(Str) : hashStringV2(Str);
- size_t Count = IDs.size();
- uint32_t Start = Hash % Count;
- for (size_t I = 0; I < Count; ++I) {
- // The hash is just a starting point for the search, but if it
- // doesn't work we should find the string no matter what, because
- // we iterate the entire array.
- uint32_t Index = (Start + I) % Count;
-
- uint32_t ID = IDs[Index];
- StringRef S = getStringForID(ID);
- if (S == Str)
- return ID;
- }
- // IDs[0] contains the ID of the "invalid" entry.
- return IDs[0];
-}
-
-FixedStreamArray<support::ulittle32_t> NameHashTable::name_ids() const {
- return IDs;
-}
Removed: llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTableBuilder.cpp?rev=292662&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTableBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NameHashTableBuilder.cpp (removed)
@@ -1,101 +0,0 @@
-//===- NameHashTable.cpp - PDB Name Hash Table ------------------*- 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/NameHashTableBuilder.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/DebugInfo/MSF/StreamWriter.h"
-#include "llvm/DebugInfo/PDB/Raw/Hash.h"
-#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
-#include "llvm/Support/Endian.h"
-
-using namespace llvm;
-using namespace llvm::support;
-using namespace llvm::support::endian;
-using namespace llvm::pdb;
-
-uint32_t NameHashTableBuilder::insert(StringRef 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;
-}
-
-static uint32_t computeBucketCount(uint32_t NumStrings) {
- // The /names stream is basically an on-disk open-addressing hash table.
- // Hash collisions are resolved by linear probing. We cannot make
- // utilization 100% because it will make the linear probing extremely
- // slow. But lower utilization wastes disk space. As a reasonable
- // load factor, we choose 80%. We need +1 because slot 0 is reserved.
- return (NumStrings + 1) * 1.25;
-}
-
-uint32_t NameHashTableBuilder::calculateSerializedLength() const {
- uint32_t Size = 0;
- Size += sizeof(NameHashTableHeader);
- Size += StringSize;
- Size += 4; // Hash table begins with 4-byte size field.
-
- uint32_t BucketCount = computeBucketCount(Strings.size());
- Size += BucketCount * 4;
-
- Size += 4; // The /names stream ends with the number of strings.
- return Size;
-}
-
-Error NameHashTableBuilder::commit(msf::StreamWriter &Writer) const {
- // Write a header
- NameHashTableHeader H;
- H.Signature = NameHashTableSignature;
- H.HashVersion = 1;
- H.ByteSize = StringSize;
- if (auto EC = Writer.writeObject(H))
- return EC;
-
- // 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.writeZeroString(S))
- return EC;
- }
- Writer.setOffset(StringStart + StringSize);
-
- // 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.first;
- uint32_t Offset = Pair.second;
- uint32_t Hash = hashStringV1(S);
-
- for (uint32_t I = 0; I != BucketCount; ++I) {
- uint32_t Slot = (Hash + I) % BucketCount;
- if (Slot == 0)
- continue; // Skip reserved slot
- if (Buckets[Slot] != 0)
- continue;
- Buckets[Slot] = Offset;
- break;
- }
- }
-
- if (auto EC = Writer.writeArray(ArrayRef<ulittle32_t>(Buckets)))
- return EC;
- if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size())))
- return EC;
- return Error::success();
-}
Removed: llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp?rev=292662&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp (removed)
@@ -1,77 +0,0 @@
-//===- 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;
-}
Removed: llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp?rev=292662&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp (removed)
@@ -1,60 +0,0 @@
-//===- 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();
-}
Added: llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMap.cpp?rev=292663&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMap.cpp (added)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMap.cpp Fri Jan 20 16:41:15 2017
@@ -0,0 +1,78 @@
+//===- NamedStreamMap.cpp - PDB Named Stream 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/NamedStreamMap.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;
+
+NamedStreamMap::NamedStreamMap() = default;
+
+Error NamedStreamMap::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>>
+NamedStreamMap::entries() const {
+ return make_range<StringMapConstIterator<uint32_t>>(Mapping.begin(),
+ Mapping.end());
+}
+
+bool NamedStreamMap::tryGetValue(StringRef Name, uint32_t &Value) const {
+ auto Iter = Mapping.find(Name);
+ if (Iter == Mapping.end())
+ return false;
+ Value = Iter->second;
+ return true;
+}
Added: llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMapBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMapBuilder.cpp?rev=292663&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMapBuilder.cpp (added)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NamedStreamMapBuilder.cpp Fri Jan 20 16:41:15 2017
@@ -0,0 +1,60 @@
+//===- NamedStreamMapBuilder.cpp - PDB Named Stream 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/DebugInfo/PDB/Raw/NamedStreamMapBuilder.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/DebugInfo/MSF/StreamWriter.h"
+#include "llvm/DebugInfo/PDB/Raw/NamedStreamMap.h"
+#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
+#include <algorithm>
+#include <cstdint>
+
+using namespace llvm;
+using namespace llvm::pdb;
+
+NamedStreamMapBuilder::NamedStreamMapBuilder() = default;
+
+void NamedStreamMapBuilder::addMapping(StringRef Name, uint32_t Mapping) {
+ Strings.push_back(Name);
+ Map.set(Offset, Mapping);
+ Offset += Name.size() + 1;
+}
+
+uint32_t NamedStreamMapBuilder::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 NamedStreamMapBuilder::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();
+}
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp Fri Jan 20 16:41:15 2017
@@ -7,20 +7,20 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/MSF/MSFCommon.h"
+#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/MSF/StreamArray.h"
#include "llvm/DebugInfo/MSF/StreamInterface.h"
#include "llvm/DebugInfo/MSF/StreamReader.h"
#include "llvm/DebugInfo/PDB/Raw/DbiStream.h"
#include "llvm/DebugInfo/PDB/Raw/GlobalsStream.h"
#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
-#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
-#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/DebugInfo/PDB/Raw/PublicsStream.h"
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
+#include "llvm/DebugInfo/PDB/Raw/StringTable.h"
#include "llvm/DebugInfo/PDB/Raw/SymbolStream.h"
#include "llvm/DebugInfo/PDB/Raw/TpiStream.h"
#include "llvm/Support/Endian.h"
@@ -323,8 +323,8 @@ Expected<SymbolStream &> PDBFile::getPDB
return *Symbols;
}
-Expected<NameHashTable &> PDBFile::getStringTable() {
- if (!StringTable || !StringTableStream) {
+Expected<StringTable &> PDBFile::getStringTable() {
+ if (!Strings || !StringTableStream) {
auto IS = getPDBInfoStream();
if (!IS)
return IS.takeError();
@@ -336,13 +336,13 @@ Expected<NameHashTable &> PDBFile::getSt
if (!NS) return NS.takeError();
StreamReader Reader(**NS);
- auto N = llvm::make_unique<NameHashTable>();
+ auto N = llvm::make_unique<StringTable>();
if (auto EC = N->load(Reader))
return std::move(EC);
- StringTable = std::move(N);
+ Strings = std::move(N);
StringTableStream = std::move(*NS);
}
- return *StringTable;
+ return *Strings;
}
bool PDBFile::hasPDBDbiStream() const { return StreamDBI < getNumStreams(); }
Added: llvm/trunk/lib/DebugInfo/PDB/Raw/StringTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/StringTable.cpp?rev=292663&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/StringTable.cpp (added)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/StringTable.cpp Fri Jan 20 16:41:15 2017
@@ -0,0 +1,99 @@
+//===- StringTable.cpp - PDB String Table -----------------------*- 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/StringTable.h"
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/DebugInfo/MSF/StreamReader.h"
+#include "llvm/DebugInfo/PDB/Raw/Hash.h"
+#include "llvm/DebugInfo/PDB/Raw/RawError.h"
+#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
+#include "llvm/Support/Endian.h"
+
+using namespace llvm;
+using namespace llvm::msf;
+using namespace llvm::support;
+using namespace llvm::pdb;
+
+StringTable::StringTable() : Signature(0), HashVersion(0), NameCount(0) {}
+
+Error StringTable::load(StreamReader &Stream) {
+ const StringTableHeader *H;
+ if (auto EC = Stream.readObject(H))
+ return EC;
+
+ if (H->Signature != StringTableSignature)
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Invalid hash table signature");
+ if (H->HashVersion != 1 && H->HashVersion != 2)
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Unsupported hash version");
+
+ Signature = H->Signature;
+ HashVersion = H->HashVersion;
+ if (auto EC = Stream.readStreamRef(NamesBuffer, H->ByteSize))
+ return joinErrors(std::move(EC),
+ make_error<RawError>(raw_error_code::corrupt_file,
+ "Invalid hash table byte length"));
+
+ const support::ulittle32_t *HashCount;
+ if (auto EC = Stream.readObject(HashCount))
+ return EC;
+
+ if (auto EC = Stream.readArray(IDs, *HashCount))
+ return joinErrors(std::move(EC),
+ make_error<RawError>(raw_error_code::corrupt_file,
+ "Could not read bucket array"));
+
+ if (Stream.bytesRemaining() < sizeof(support::ulittle32_t))
+ return make_error<RawError>(raw_error_code::corrupt_file,
+ "Missing name count");
+
+ if (auto EC = Stream.readInteger(NameCount))
+ return EC;
+ return Error::success();
+}
+
+StringRef StringTable::getStringForID(uint32_t ID) const {
+ if (ID == IDs[0])
+ return StringRef();
+
+ // NamesBuffer is a buffer of null terminated strings back to back. ID is
+ // the starting offset of the string we're looking for. So just seek into
+ // the desired offset and a read a null terminated stream from that offset.
+ StringRef Result;
+ StreamReader NameReader(NamesBuffer);
+ NameReader.setOffset(ID);
+ if (auto EC = NameReader.readZeroString(Result))
+ consumeError(std::move(EC));
+ return Result;
+}
+
+uint32_t StringTable::getIDForString(StringRef Str) const {
+ uint32_t Hash = (HashVersion == 1) ? hashStringV1(Str) : hashStringV2(Str);
+ size_t Count = IDs.size();
+ uint32_t Start = Hash % Count;
+ for (size_t I = 0; I < Count; ++I) {
+ // The hash is just a starting point for the search, but if it
+ // doesn't work we should find the string no matter what, because
+ // we iterate the entire array.
+ uint32_t Index = (Start + I) % Count;
+
+ uint32_t ID = IDs[Index];
+ StringRef S = getStringForID(ID);
+ if (S == Str)
+ return ID;
+ }
+ // IDs[0] contains the ID of the "invalid" entry.
+ return IDs[0];
+}
+
+FixedStreamArray<support::ulittle32_t> StringTable::name_ids() const {
+ return IDs;
+}
Added: llvm/trunk/lib/DebugInfo/PDB/Raw/StringTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/StringTableBuilder.cpp?rev=292663&view=auto
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/StringTableBuilder.cpp (added)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/StringTableBuilder.cpp Fri Jan 20 16:41:15 2017
@@ -0,0 +1,101 @@
+//===- StringTableBuilder.cpp - PDB String Table ----------------*- 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/StringTableBuilder.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/DebugInfo/MSF/StreamWriter.h"
+#include "llvm/DebugInfo/PDB/Raw/Hash.h"
+#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
+#include "llvm/Support/Endian.h"
+
+using namespace llvm;
+using namespace llvm::support;
+using namespace llvm::support::endian;
+using namespace llvm::pdb;
+
+uint32_t StringTableBuilder::insert(StringRef 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;
+}
+
+static uint32_t computeBucketCount(uint32_t NumStrings) {
+ // The /names stream is basically an on-disk open-addressing hash table.
+ // Hash collisions are resolved by linear probing. We cannot make
+ // utilization 100% because it will make the linear probing extremely
+ // slow. But lower utilization wastes disk space. As a reasonable
+ // load factor, we choose 80%. We need +1 because slot 0 is reserved.
+ return (NumStrings + 1) * 1.25;
+}
+
+uint32_t StringTableBuilder::calculateSerializedLength() const {
+ uint32_t Size = 0;
+ Size += sizeof(StringTableHeader);
+ Size += StringSize;
+ Size += 4; // Hash table begins with 4-byte size field.
+
+ uint32_t BucketCount = computeBucketCount(Strings.size());
+ Size += BucketCount * 4;
+
+ Size += 4; // The /names stream ends with the number of strings.
+ return Size;
+}
+
+Error StringTableBuilder::commit(msf::StreamWriter &Writer) const {
+ // Write a header
+ StringTableHeader H;
+ H.Signature = StringTableSignature;
+ H.HashVersion = 1;
+ H.ByteSize = StringSize;
+ if (auto EC = Writer.writeObject(H))
+ return EC;
+
+ // 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.writeZeroString(S))
+ return EC;
+ }
+ Writer.setOffset(StringStart + StringSize);
+
+ // 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.first;
+ uint32_t Offset = Pair.second;
+ uint32_t Hash = hashStringV1(S);
+
+ for (uint32_t I = 0; I != BucketCount; ++I) {
+ uint32_t Slot = (Hash + I) % BucketCount;
+ if (Slot == 0)
+ continue; // Skip reserved slot
+ if (Buckets[Slot] != 0)
+ continue;
+ Buckets[Slot] = Offset;
+ break;
+ }
+ }
+
+ if (auto EC = Writer.writeArray(ArrayRef<ulittle32_t>(Buckets)))
+ return EC;
+ if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size())))
+ return EC;
+ return Error::success();
+}
Modified: llvm/trunk/unittests/DebugInfo/PDB/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/PDB/CMakeLists.txt?rev=292663&r1=292662&r2=292663&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/PDB/CMakeLists.txt (original)
+++ llvm/trunk/unittests/DebugInfo/PDB/CMakeLists.txt Fri Jan 20 16:41:15 2017
@@ -7,7 +7,7 @@ set(LLVM_LINK_COMPONENTS
set(DebugInfoPDBSources
HashTableTest.cpp
MappedBlockStreamTest.cpp
- NameHashTableBuilderTest.cpp
+ StringTableBuilderTest.cpp
MSFBuilderTest.cpp
PDBApiTest.cpp
)
Removed: llvm/trunk/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp?rev=292662&view=auto
==============================================================================
--- llvm/trunk/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp (original)
+++ llvm/trunk/unittests/DebugInfo/PDB/NameHashTableBuilderTest.cpp (removed)
@@ -1,54 +0,0 @@
-//===- NameHashTableBuilderTest.cpp ---------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ErrorChecking.h"
-
-#include "llvm/DebugInfo/MSF/ByteStream.h"
-#include "llvm/DebugInfo/MSF/StreamReader.h"
-#include "llvm/DebugInfo/MSF/StreamWriter.h"
-#include "llvm/DebugInfo/PDB/Raw/NameHashTable.h"
-#include "llvm/DebugInfo/PDB/Raw/NameHashTableBuilder.h"
-
-#include "gtest/gtest.h"
-
-using namespace llvm;
-using namespace llvm::pdb;
-
-namespace {
-class NameHashTableBuilderTest : public ::testing::Test {};
-}
-
-TEST_F(NameHashTableBuilderTest, Simple) {
- // Create /names table contents.
- NameHashTableBuilder Builder;
- EXPECT_EQ(1U, Builder.insert("foo"));
- EXPECT_EQ(5U, Builder.insert("bar"));
- EXPECT_EQ(1U, Builder.insert("foo"));
- EXPECT_EQ(9U, Builder.insert("baz"));
-
- std::vector<uint8_t> Buffer(Builder.calculateSerializedLength());
- msf::MutableByteStream OutStream(Buffer);
- msf::StreamWriter Writer(OutStream);
- EXPECT_NO_ERROR(Builder.commit(Writer));
-
- // Reads the contents back.
- msf::ByteStream InStream(Buffer);
- msf::StreamReader Reader(InStream);
- NameHashTable Table;
- EXPECT_NO_ERROR(Table.load(Reader));
-
- EXPECT_EQ(3U, Table.getNameCount());
- EXPECT_EQ(1U, Table.getHashVersion());
- EXPECT_EQ("foo", Table.getStringForID(1));
- EXPECT_EQ("bar", Table.getStringForID(5));
- EXPECT_EQ("baz", Table.getStringForID(9));
- EXPECT_EQ(1U, Table.getIDForString("foo"));
- EXPECT_EQ(5U, Table.getIDForString("bar"));
- EXPECT_EQ(9U, Table.getIDForString("baz"));
-}
Added: llvm/trunk/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp?rev=292663&view=auto
==============================================================================
--- llvm/trunk/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp (added)
+++ llvm/trunk/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp Fri Jan 20 16:41:15 2017
@@ -0,0 +1,54 @@
+//===- StringTableBuilderTest.cpp -----------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ErrorChecking.h"
+
+#include "llvm/DebugInfo/MSF/ByteStream.h"
+#include "llvm/DebugInfo/MSF/StreamReader.h"
+#include "llvm/DebugInfo/MSF/StreamWriter.h"
+#include "llvm/DebugInfo/PDB/Raw/StringTable.h"
+#include "llvm/DebugInfo/PDB/Raw/StringTableBuilder.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace llvm::pdb;
+
+namespace {
+class StringTableBuilderTest : public ::testing::Test {};
+}
+
+TEST_F(StringTableBuilderTest, Simple) {
+ // Create /names table contents.
+ StringTableBuilder Builder;
+ EXPECT_EQ(1U, Builder.insert("foo"));
+ EXPECT_EQ(5U, Builder.insert("bar"));
+ EXPECT_EQ(1U, Builder.insert("foo"));
+ EXPECT_EQ(9U, Builder.insert("baz"));
+
+ std::vector<uint8_t> Buffer(Builder.calculateSerializedLength());
+ msf::MutableByteStream OutStream(Buffer);
+ msf::StreamWriter Writer(OutStream);
+ EXPECT_NO_ERROR(Builder.commit(Writer));
+
+ // Reads the contents back.
+ msf::ByteStream InStream(Buffer);
+ msf::StreamReader Reader(InStream);
+ StringTable Table;
+ EXPECT_NO_ERROR(Table.load(Reader));
+
+ EXPECT_EQ(3U, Table.getNameCount());
+ EXPECT_EQ(1U, Table.getHashVersion());
+ EXPECT_EQ("foo", Table.getStringForID(1));
+ EXPECT_EQ("bar", Table.getStringForID(5));
+ EXPECT_EQ("baz", Table.getStringForID(9));
+ EXPECT_EQ(1U, Table.getIDForString("foo"));
+ EXPECT_EQ(5U, Table.getIDForString("bar"));
+ EXPECT_EQ(9U, Table.getIDForString("baz"));
+}
More information about the llvm-commits
mailing list