blob: 21e2cc56075b70b416aae1cf522fc7fb87dfc701 [file] [log] [blame]
Zachary Turner349c18f2017-06-05 21:40:33 +00001//===- DebugCrossExSubsection.cpp -------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/DebugInfo/CodeView/DebugCrossExSubsection.h"
11
12#include "llvm/DebugInfo/CodeView/CodeViewError.h"
13
14using namespace llvm;
15using namespace llvm::codeview;
16
17Error DebugCrossModuleExportsSubsectionRef::initialize(
18 BinaryStreamReader Reader) {
19 if (Reader.bytesRemaining() % sizeof(CrossModuleExport) != 0)
20 return make_error<CodeViewError>(
21 cv_error_code::corrupt_record,
22 "Cross Scope Exports section is an invalid size!");
23
24 uint32_t Size = Reader.bytesRemaining() / sizeof(CrossModuleExport);
25 return Reader.readArray(References, Size);
26}
27
28Error DebugCrossModuleExportsSubsectionRef::initialize(BinaryStreamRef Stream) {
29 BinaryStreamReader Reader(Stream);
30 return initialize(Reader);
31}
32
33void DebugCrossModuleExportsSubsection::addMapping(uint32_t Local,
34 uint32_t Global) {
35 Mappings[Local] = Global;
36}
37
38uint32_t DebugCrossModuleExportsSubsection::calculateSerializedSize() const {
39 return Mappings.size() * sizeof(CrossModuleExport);
40}
41
42Error DebugCrossModuleExportsSubsection::commit(
43 BinaryStreamWriter &Writer) const {
44 for (const auto &M : Mappings) {
Zachary Turner88101da2017-06-05 22:12:23 +000045 if (auto EC = Writer.writeInteger(M.first))
46 return EC;
47 if (auto EC = Writer.writeInteger(M.second))
Zachary Turner349c18f2017-06-05 21:40:33 +000048 return EC;
49 }
50 return Error::success();
51}