NamedStreamMap.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/DebugInfo/PDB/Native/HashTable.h"
  18. #include "llvm/Support/Error.h"
  19. #include <cstdint>
  20. namespace llvm {
  21. class BinaryStreamReader;
  22. class BinaryStreamWriter;
  23. namespace pdb {
  24. class NamedStreamMap;
  25. struct NamedStreamMapTraits {
  26. NamedStreamMap *NS;
  27. explicit NamedStreamMapTraits(NamedStreamMap &NS);
  28. uint16_t hashLookupKey(StringRef S) const;
  29. StringRef storageKeyToLookupKey(uint32_t Offset) const;
  30. uint32_t lookupKeyToStorageKey(StringRef S);
  31. };
  32. class NamedStreamMap {
  33. friend class NamedStreamMapBuilder;
  34. public:
  35. NamedStreamMap();
  36. Error load(BinaryStreamReader &Stream);
  37. Error commit(BinaryStreamWriter &Writer) const;
  38. uint32_t calculateSerializedLength() const;
  39. uint32_t size() const;
  40. bool get(StringRef Stream, uint32_t &StreamNo) const;
  41. void set(StringRef Stream, uint32_t StreamNo);
  42. uint32_t appendStringData(StringRef S);
  43. StringRef getString(uint32_t Offset) const;
  44. uint32_t hashString(uint32_t Offset) const;
  45. StringMap<uint32_t> entries() const;
  46. private:
  47. NamedStreamMapTraits HashTraits;
  48. /// Closed hash table from Offset -> StreamNumber, where Offset is the offset
  49. /// of the stream name in NamesBuffer.
  50. HashTable<support::ulittle32_t> OffsetIndexMap;
  51. /// Buffer of string data.
  52. std::vector<char> NamesBuffer;
  53. };
  54. } // end namespace pdb
  55. } // end namespace llvm
  56. #endif // LLVM_DEBUGINFO_PDB_NATIVE_NAMEDSTREAMMAP_H
  57. #ifdef __GNUC__
  58. #pragma GCC diagnostic pop
  59. #endif