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