[llvm] [cmake] Add possibility to use ChooseMSVCCRT.cmake when include LLVM library
[llvm-core.git] / include / llvm / DebugInfo / CodeView / DebugStringTableSubsection.h
blob6e5b8adddd4aef430c8e459458d7ae35cbc4b0ea
1 //===- DebugStringTableSubsection.h - CodeView String Table -----*- 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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
10 #define LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/DebugInfo/CodeView/CodeView.h"
16 #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
17 #include "llvm/Support/BinaryStreamRef.h"
18 #include "llvm/Support/Error.h"
19 #include <cstdint>
21 namespace llvm {
23 class BinaryStreamReader;
25 namespace codeview {
27 /// Represents a read-only view of a CodeView string table. This is a very
28 /// simple flat buffer consisting of null-terminated strings, where strings
29 /// are retrieved by their offset in the buffer. DebugStringTableSubsectionRef
30 /// does not own the underlying storage for the buffer.
31 class DebugStringTableSubsectionRef : public DebugSubsectionRef {
32 public:
33 DebugStringTableSubsectionRef();
35 static bool classof(const DebugSubsectionRef *S) {
36 return S->kind() == DebugSubsectionKind::StringTable;
39 Error initialize(BinaryStreamRef Contents);
40 Error initialize(BinaryStreamReader &Reader);
42 Expected<StringRef> getString(uint32_t Offset) const;
44 bool valid() const { return Stream.valid(); }
46 BinaryStreamRef getBuffer() const { return Stream; }
48 private:
49 BinaryStreamRef Stream;
52 /// Represents a read-write view of a CodeView string table.
53 /// DebugStringTableSubsection owns the underlying storage for the table, and is
54 /// capable of serializing the string table into a format understood by
55 /// DebugStringTableSubsectionRef.
56 class DebugStringTableSubsection : public DebugSubsection {
57 public:
58 DebugStringTableSubsection();
60 static bool classof(const DebugSubsection *S) {
61 return S->kind() == DebugSubsectionKind::StringTable;
64 // If string S does not exist in the string table, insert it.
65 // Returns the ID for S.
66 uint32_t insert(StringRef S);
68 // Return the ID for string S. Assumes S exists in the table.
69 uint32_t getIdForString(StringRef S) const;
71 StringRef getStringForId(uint32_t Id) const;
73 uint32_t calculateSerializedSize() const override;
74 Error commit(BinaryStreamWriter &Writer) const override;
76 uint32_t size() const;
78 StringMap<uint32_t>::const_iterator begin() const {
79 return StringToId.begin();
82 StringMap<uint32_t>::const_iterator end() const { return StringToId.end(); }
84 std::vector<uint32_t> sortedIds() const;
86 private:
87 DenseMap<uint32_t, StringRef> IdToString;
88 StringMap<uint32_t> StringToId;
89 uint32_t StringSize = 1;
92 } // end namespace codeview
94 } // end namespace llvm
96 #endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGSTRINGTABLESUBSECTION_H