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

source code of llvm/lib/DebugInfo/CodeView/DebugCrossExSubsection.cpp