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