blob: b23410409f8821645847747dde6bb696e8c70c67 [file] [log] [blame]
Eugene Zelenko8456b162017-06-29 00:05:44 +00001//===- DebugCrossExSubsection.cpp -----------------------------------------===//
Zachary Turner349c18f2017-06-05 21:40:33 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Zachary Turner349c18f2017-06-05 21:40:33 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
Zachary Turner349c18f2017-06-05 21:40:33 +000010#include "llvm/DebugInfo/CodeView/CodeViewError.h"
Eugene Zelenko8456b162017-06-29 00:05:44 +000011#include "llvm/Support/BinaryStreamWriter.h"
12#include "llvm/Support/Error.h"
13#include <cstdint>
Zachary Turner349c18f2017-06-05 21:40:33 +000014
15using namespace llvm;
16using namespace llvm::codeview;
17
18Error 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!");
24
25 uint32_t Size = Reader.bytesRemaining() / sizeof(CrossModuleExport);
26 return Reader.readArray(References, Size);
27}
28
29Error DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream) {
30 BinaryStreamReader Reader(Stream);
31 return initialize(Reader);
32}
33
34void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local,
35 uint32_t Global) {
36 Mappings[Local] = Global;
37}
38
39uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const {
40 return Mappings.size() * sizeof(CrossModuleExport);
41}
42
43Error DebugCrossModuleExportsSubsection::commit(
44 BinaryStreamWriter &Writer) const {
45 for (const auto &M : Mappings) {
Zachary Turner88101da2017-06-05 22:12:23 +000046 if (auto EC = Writer.writeInteger(M.first))
47 return EC;
48 if (auto EC = Writer.writeInteger(M.second))
Zachary Turner349c18f2017-06-05 21:40:33 +000049 return EC;
50 }
51 return Error::success();
52}