1317760Sdim//===- PDBStringTableBuilder.h - PDB String Table Builder -------*- C++ -*-===//
2317760Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6317760Sdim//
7317760Sdim//===----------------------------------------------------------------------===//
8317760Sdim//
9317760Sdim// This file creates the "/names" stream.
10317760Sdim//
11317760Sdim//===----------------------------------------------------------------------===//
12317760Sdim
13317760Sdim#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H
14317760Sdim#define LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H
15317760Sdim
16317760Sdim#include "llvm/ADT/DenseMap.h"
17317760Sdim#include "llvm/ADT/StringRef.h"
18319250Sdim#include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
19317760Sdim#include "llvm/Support/Error.h"
20317760Sdim#include <vector>
21317760Sdim
22317760Sdimnamespace llvm {
23317760Sdimclass BinaryStreamWriter;
24317760Sdimclass WritableBinaryStreamRef;
25317760Sdim
26317760Sdimnamespace msf {
27317760Sdimstruct MSFLayout;
28317760Sdim}
29317760Sdim
30317760Sdimnamespace pdb {
31317760Sdim
32317760Sdimclass PDBFileBuilder;
33341825Sdimclass PDBStringTableBuilder;
34317760Sdim
35341825Sdimstruct StringTableHashTraits {
36341825Sdim  PDBStringTableBuilder *Table;
37341825Sdim
38341825Sdim  explicit StringTableHashTraits(PDBStringTableBuilder &Table);
39341825Sdim  uint32_t hashLookupKey(StringRef S) const;
40341825Sdim  StringRef storageKeyToLookupKey(uint32_t Offset) const;
41341825Sdim  uint32_t lookupKeyToStorageKey(StringRef S);
42341825Sdim};
43341825Sdim
44317760Sdimclass PDBStringTableBuilder {
45317760Sdimpublic:
46317760Sdim  // If string S does not exist in the string table, insert it.
47317760Sdim  // Returns the ID for S.
48317760Sdim  uint32_t insert(StringRef S);
49317760Sdim
50341825Sdim  uint32_t getIdForString(StringRef S) const;
51341825Sdim  StringRef getStringForId(uint32_t Id) const;
52341825Sdim
53317760Sdim  uint32_t calculateSerializedSize() const;
54317760Sdim  Error commit(BinaryStreamWriter &Writer) const;
55317760Sdim
56320041Sdim  void setStrings(const codeview::DebugStringTableSubsection &Strings);
57317760Sdim
58317760Sdimprivate:
59317760Sdim  uint32_t calculateHashTableSize() const;
60317760Sdim  Error writeHeader(BinaryStreamWriter &Writer) const;
61317760Sdim  Error writeStrings(BinaryStreamWriter &Writer) const;
62317760Sdim  Error writeHashTable(BinaryStreamWriter &Writer) const;
63317760Sdim  Error writeEpilogue(BinaryStreamWriter &Writer) const;
64317760Sdim
65319250Sdim  codeview::DebugStringTableSubsection Strings;
66317760Sdim};
67317760Sdim
68317760Sdim} // end namespace pdb
69317760Sdim} // end namespace llvm
70317760Sdim
71317760Sdim#endif // LLVM_DEBUGINFO_PDB_RAW_PDBSTRINGTABLEBUILDER_H
72