Zachary Turner | 67c5601 | 2017-04-27 16:11:19 +0000 | [diff] [blame^] | 1 | //===- ModuleDebugFragment.cpp --------------------------------------*- C++ |
| 2 | //-*-===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #include "llvm/DebugInfo/CodeView/ModuleDebugFragment.h" |
| 12 | |
| 13 | #include "llvm/Support/BinaryStreamReader.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | using namespace llvm::codeview; |
| 17 | |
| 18 | ModuleDebugFragment::ModuleDebugFragment() |
| 19 | : Kind(ModuleDebugFragmentKind::None) {} |
| 20 | |
| 21 | ModuleDebugFragment::ModuleDebugFragment(ModuleDebugFragmentKind Kind, |
| 22 | BinaryStreamRef Data) |
| 23 | : Kind(Kind), Data(Data) {} |
| 24 | |
| 25 | Error ModuleDebugFragment::initialize(BinaryStreamRef Stream, |
| 26 | ModuleDebugFragment &Info) { |
| 27 | const ModuleDebugFragmentHeader *Header; |
| 28 | BinaryStreamReader Reader(Stream); |
| 29 | if (auto EC = Reader.readObject(Header)) |
| 30 | return EC; |
| 31 | |
| 32 | ModuleDebugFragmentKind Kind = |
| 33 | static_cast<ModuleDebugFragmentKind>(uint32_t(Header->Kind)); |
| 34 | if (auto EC = Reader.readStreamRef(Info.Data, Header->Length)) |
| 35 | return EC; |
| 36 | Info.Kind = Kind; |
| 37 | return Error::success(); |
| 38 | } |
| 39 | |
| 40 | uint32_t ModuleDebugFragment::getRecordLength() const { |
| 41 | return sizeof(ModuleDebugFragmentHeader) + Data.getLength(); |
| 42 | } |
| 43 | |
| 44 | ModuleDebugFragmentKind ModuleDebugFragment::kind() const { return Kind; } |
| 45 | |
| 46 | BinaryStreamRef ModuleDebugFragment::getRecordData() const { return Data; } |