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