1//===- PDBStringTableBuilder.h - PDB String Table Builder -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file creates the "/names" stream.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H
14#define LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H
15
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
19#include "llvm/Support/Error.h"
20#include <vector>
21
22namespace llvm {
23class BinaryStreamWriter;
24class WritableBinaryStreamRef;
25
26namespace msf {
27struct MSFLayout;
28}
29
30namespace pdb {
31
32class PDBFileBuilder;
33class PDBStringTableBuilder;
34
35struct StringTableHashTraits {
36  PDBStringTableBuilder *Table;
37
38  explicit StringTableHashTraits(PDBStringTableBuilder &Table);
39  uint32_t hashLookupKey(StringRef S) const;
40  StringRef storageKeyToLookupKey(uint32_t Offset) const;
41  uint32_t lookupKeyToStorageKey(StringRef S);
42};
43
44class PDBStringTableBuilder {
45public:
46  // If string S does not exist in the string table, insert it.
47  // Returns the ID for S.
48  uint32_t insert(StringRef S);
49
50  uint32_t getIdForString(StringRef S) const;
51  StringRef getStringForId(uint32_t Id) const;
52
53  uint32_t calculateSerializedSize() const;
54  Error commit(BinaryStreamWriter &Writer) const;
55
56  void setStrings(const codeview::DebugStringTableSubsection &Strings);
57
58private:
59  uint32_t calculateHashTableSize() const;
60  Error writeHeader(BinaryStreamWriter &Writer) const;
61  Error writeStrings(BinaryStreamWriter &Writer) const;
62  Error writeHashTable(BinaryStreamWriter &Writer) const;
63  Error writeEpilogue(BinaryStreamWriter &Writer) const;
64
65  codeview::DebugStringTableSubsection Strings;
66};
67
68} // end namespace pdb
69} // end namespace llvm
70
71#endif // LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H
72