blob: e7683cb2a9c4a020769d7d58f0c05bdb10df321a [file] [log] [blame]
Andrew Walbran16937d02019-10-22 13:54:20 +01001//===- DebugCrossImpSubsection.h --------------------------------*- C++ -*-===//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01002//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H
10#define LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H
11
12#include "llvm/ADT/StringMap.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/DebugInfo/CodeView/CodeView.h"
15#include "llvm/DebugInfo/CodeView/DebugSubsection.h"
16#include "llvm/Support/BinaryStreamArray.h"
17#include "llvm/Support/BinaryStreamReader.h"
18#include "llvm/Support/BinaryStreamRef.h"
19#include "llvm/Support/Endian.h"
20#include "llvm/Support/Error.h"
21#include <cstdint>
22#include <vector>
23
24namespace llvm {
25
26namespace codeview {
27
28struct CrossModuleImportItem {
29 const CrossModuleImport *Header = nullptr;
30 FixedStreamArray<support::ulittle32_t> Imports;
31};
32
33} // end namespace codeview
34
35template <> struct VarStreamArrayExtractor<codeview::CrossModuleImportItem> {
36public:
37 using ContextType = void;
38
39 Error operator()(BinaryStreamRef Stream, uint32_t &Len,
40 codeview::CrossModuleImportItem &Item);
41};
42
43namespace codeview {
44
45class DebugStringTableSubsection;
46
47class DebugCrossModuleImportsSubsectionRef final : public DebugSubsectionRef {
48 using ReferenceArray = VarStreamArray<CrossModuleImportItem>;
49 using Iterator = ReferenceArray::Iterator;
50
51public:
52 DebugCrossModuleImportsSubsectionRef()
53 : DebugSubsectionRef(DebugSubsectionKind::CrossScopeImports) {}
54
55 static bool classof(const DebugSubsectionRef *S) {
56 return S->kind() == DebugSubsectionKind::CrossScopeImports;
57 }
58
59 Error initialize(BinaryStreamReader Reader);
60 Error initialize(BinaryStreamRef Stream);
61
62 Iterator begin() const { return References.begin(); }
63 Iterator end() const { return References.end(); }
64
65private:
66 ReferenceArray References;
67};
68
69class DebugCrossModuleImportsSubsection final : public DebugSubsection {
70public:
71 explicit DebugCrossModuleImportsSubsection(
72 DebugStringTableSubsection &Strings)
73 : DebugSubsection(DebugSubsectionKind::CrossScopeImports),
74 Strings(Strings) {}
75
76 static bool classof(const DebugSubsection *S) {
77 return S->kind() == DebugSubsectionKind::CrossScopeImports;
78 }
79
80 void addImport(StringRef Module, uint32_t ImportId);
81
82 uint32_t calculateSerializedSize() const override;
83 Error commit(BinaryStreamWriter &Writer) const override;
84
85private:
86 DebugStringTableSubsection &Strings;
87 StringMap<std::vector<support::ulittle32_t>> Mappings;
88};
89
90} // end namespace codeview
91
92} // end namespace llvm
93
94#endif // LLVM_DEBUGINFO_CODEVIEW_DEBUGCROSSIMPSUBSECTION_H