[llvm] [cmake] Add possibility to use ChooseMSVCCRT.cmake when include LLVM library
[llvm-core.git] / include / llvm / DebugInfo / CodeView / StringsAndChecksums.h
blob22a283e785e1fb2fb671445939fa9fc4a87fb0ae
1 //===- StringsAndChecksums.h ------------------------------------*- 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_STRINGSANDCHECKSUMS_H
10 #define LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H
12 #include "llvm/DebugInfo/CodeView/CodeView.h"
13 #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
14 #include "llvm/DebugInfo/CodeView/DebugStringTableSubsection.h"
15 #include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
16 #include <memory>
18 namespace llvm {
19 namespace codeview {
21 class StringsAndChecksumsRef {
22 public:
23 // If no subsections are known about initially, we find as much as we can.
24 StringsAndChecksumsRef();
26 // If only a string table subsection is given, we find a checksums subsection.
27 explicit StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings);
29 // If both subsections are given, we don't need to find anything.
30 StringsAndChecksumsRef(const DebugStringTableSubsectionRef &Strings,
31 const DebugChecksumsSubsectionRef &Checksums);
33 void setStrings(const DebugStringTableSubsectionRef &Strings);
34 void setChecksums(const DebugChecksumsSubsectionRef &CS);
36 void reset();
37 void resetStrings();
38 void resetChecksums();
40 template <typename T> void initialize(T &&FragmentRange) {
41 for (const DebugSubsectionRecord &R : FragmentRange) {
42 if (Strings && Checksums)
43 return;
44 if (R.kind() == DebugSubsectionKind::FileChecksums) {
45 initializeChecksums(R);
46 continue;
48 if (R.kind() == DebugSubsectionKind::StringTable && !Strings) {
49 // While in practice we should never encounter a string table even
50 // though the string table is already initialized, in theory it's
51 // possible. PDBs are supposed to have one global string table and
52 // then this subsection should not appear. Whereas object files are
53 // supposed to have this subsection appear exactly once. However,
54 // for testing purposes it's nice to be able to test this subsection
55 // independently of one format or the other, so for some tests we
56 // manually construct a PDB that contains this subsection in addition
57 // to a global string table.
58 initializeStrings(R);
59 continue;
64 const DebugStringTableSubsectionRef &strings() const { return *Strings; }
65 const DebugChecksumsSubsectionRef &checksums() const { return *Checksums; }
67 bool hasStrings() const { return Strings != nullptr; }
68 bool hasChecksums() const { return Checksums != nullptr; }
70 private:
71 void initializeStrings(const DebugSubsectionRecord &SR);
72 void initializeChecksums(const DebugSubsectionRecord &FCR);
74 std::shared_ptr<DebugStringTableSubsectionRef> OwnedStrings;
75 std::shared_ptr<DebugChecksumsSubsectionRef> OwnedChecksums;
77 const DebugStringTableSubsectionRef *Strings = nullptr;
78 const DebugChecksumsSubsectionRef *Checksums = nullptr;
81 class StringsAndChecksums {
82 public:
83 using StringsPtr = std::shared_ptr<DebugStringTableSubsection>;
84 using ChecksumsPtr = std::shared_ptr<DebugChecksumsSubsection>;
86 // If no subsections are known about initially, we find as much as we can.
87 StringsAndChecksums() = default;
89 void setStrings(const StringsPtr &SP) { Strings = SP; }
90 void setChecksums(const ChecksumsPtr &CP) { Checksums = CP; }
92 const StringsPtr &strings() const { return Strings; }
93 const ChecksumsPtr &checksums() const { return Checksums; }
95 bool hasStrings() const { return Strings != nullptr; }
96 bool hasChecksums() const { return Checksums != nullptr; }
98 private:
99 StringsPtr Strings;
100 ChecksumsPtr Checksums;
103 } // end namespace codeview
104 } // end namespace llvm
106 #endif // LLVM_DEBUGINFO_CODEVIEW_STRINGSANDCHECKSUMS_H