blob: 1329f8cc8f61731d614ae52b6004b86c7b3bc311 [file] [log] [blame]
Zachary Turner67c56012017-04-27 16:11:19 +00001//===- 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
15using namespace llvm;
16using namespace llvm::codeview;
17
18ModuleDebugFragment::ModuleDebugFragment()
19 : Kind(ModuleDebugFragmentKind::None) {}
20
21ModuleDebugFragment::ModuleDebugFragment(ModuleDebugFragmentKind Kind,
22 BinaryStreamRef Data)
23 : Kind(Kind), Data(Data) {}
24
25Error 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
40uint32_t ModuleDebugFragment::getRecordLength() const {
41 return sizeof(ModuleDebugFragmentHeader) + Data.getLength();
42}
43
44ModuleDebugFragmentKind ModuleDebugFragment::kind() const { return Kind; }
45
46BinaryStreamRef ModuleDebugFragment::getRecordData() const { return Data; }