1//===- NamedStreamMap.h - PDB Named Stream Map ------------------*- 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#ifndef LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H
10#define LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H
11
12#include "llvm/ADT/Optional.h"
13#include "llvm/ADT/StringMap.h"
14#include "llvm/ADT/StringRef.h"
15#include "llvm/ADT/iterator_range.h"
16#include "llvm/DebugInfo/PDB/Native/HashTable.h"
17#include "llvm/Support/Error.h"
18#include <cstdint>
19
20namespace llvm {
21
22class BinaryStreamReader;
23class BinaryStreamWriter;
24
25namespace pdb {
26
27class NamedStreamMap;
28
29struct NamedStreamMapTraits {
30  NamedStreamMap *NS;
31
32  explicit NamedStreamMapTraits(NamedStreamMap &NS);
33  uint16_t hashLookupKey(StringRef S) const;
34  StringRef storageKeyToLookupKey(uint32_t Offset) const;
35  uint32_t lookupKeyToStorageKey(StringRef S);
36};
37
38class NamedStreamMap {
39  friend class NamedStreamMapBuilder;
40
41public:
42  NamedStreamMap();
43
44  Error load(BinaryStreamReader &Stream);
45  Error commit(BinaryStreamWriter &Writer) const;
46  uint32_t calculateSerializedLength() const;
47
48  uint32_t size() const;
49  bool get(StringRef Stream, uint32_t &StreamNo) const;
50  void set(StringRef Stream, uint32_t StreamNo);
51
52  uint32_t appendStringData(StringRef S);
53  StringRef getString(uint32_t Offset) const;
54  uint32_t hashString(uint32_t Offset) const;
55
56  StringMap<uint32_t> entries() const;
57
58private:
59  NamedStreamMapTraits HashTraits;
60  /// Closed hash table from Offset -> StreamNumber, where Offset is the offset
61  /// of the stream name in NamesBuffer.
62  HashTable<support::ulittle32_t> OffsetIndexMap;
63
64  /// Buffer of string data.
65  std::vector<char> NamesBuffer;
66};
67
68} // end namespace pdb
69
70} // end namespace llvm
71
72#endif // LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H
73