1 //===- DebugCrossExSubsection.cpp -----------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
10 #include "llvm/DebugInfo/CodeView/CodeViewError.h"
11 #include "llvm/Support/BinaryStreamWriter.h"
12 #include "llvm/Support/Error.h"
16 using namespace llvm::codeview
;
18 Error
DebugCrossModuleExportsSubsectionRef::initialize(
19 BinaryStreamReader Reader
) {
20 if (Reader
.bytesRemaining() % sizeof(CrossModuleExport
) != 0)
21 return make_error
<CodeViewError
>(
22 cv_error_code::corrupt_record
,
23 "Cross Scope Exports section is an invalid size!");
25 uint32_t Size
= Reader
.bytesRemaining() / sizeof(CrossModuleExport
);
26 return Reader
.readArray(References
, Size
);
29 Error
DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream
) {
30 BinaryStreamReader
Reader(Stream
);
31 return initialize(Reader
);
34 void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local
,
36 Mappings
[Local
] = Global
;
39 uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const {
40 return Mappings
.size() * sizeof(CrossModuleExport
);
43 Error
DebugCrossModuleExportsSubsection::commit(
44 BinaryStreamWriter
&Writer
) const {
45 for (const auto &M
: Mappings
) {
46 if (auto EC
= Writer
.writeInteger(M
.first
))
48 if (auto EC
= Writer
.writeInteger(M
.second
))
51 return Error::success();