NamedStreamMap.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- NamedStreamMap.h - PDB Named Stream Map ------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H
  14. #define LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H
  15. #include "llvm/ADT/StringMap.h"
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/ADT/iterator_range.h"
  18. #include "llvm/DebugInfo/PDB/Native/HashTable.h"
  19. #include "llvm/Support/Error.h"
  20. #include <cstdint>
  21. namespace llvm {
  22. class BinaryStreamReader;
  23. class BinaryStreamWriter;
  24. namespace pdb {
  25. class NamedStreamMap;
  26. struct NamedStreamMapTraits {
  27. NamedStreamMap *NS;
  28. explicit NamedStreamMapTraits(NamedStreamMap &NS);
  29. uint16_t hashLookupKey(StringRef S) const;
  30. StringRef storageKeyToLookupKey(uint32_t Offset) const;
  31. uint32_t lookupKeyToStorageKey(StringRef S);
  32. };
  33. class NamedStreamMap {
  34. friend class NamedStreamMapBuilder;
  35. public:
  36. NamedStreamMap();
  37. Error load(BinaryStreamReader &Stream);
  38. Error commit(BinaryStreamWriter &Writer) const;
  39. uint32_t calculateSerializedLength() const;
  40. uint32_t size() const;
  41. bool get(StringRef Stream, uint32_t &StreamNo) const;
  42. void set(StringRef Stream, uint32_t StreamNo);
  43. uint32_t appendStringData(StringRef S);
  44. StringRef getString(uint32_t Offset) const;
  45. uint32_t hashString(uint32_t Offset) const;
  46. StringMap<uint32_t> entries() const;
  47. private:
  48. NamedStreamMapTraits HashTraits;
  49. /// Closed hash table from Offset -> StreamNumber, where Offset is the offset
  50. /// of the stream name in NamesBuffer.
  51. HashTable<support::ulittle32_t> OffsetIndexMap;
  52. /// Buffer of string data.
  53. std::vector<char> NamesBuffer;
  54. };
  55. } // end namespace pdb
  56. } // end namespace llvm
  57. #endif // LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H
  58. #ifdef __GNUC__
  59. #pragma GCC diagnostic pop
  60. #endif