blob: d45bd10729f2e82b2d9d162b8bd39a954a960ce9 [file] [log] [blame]
Zachary Turnerdbeaea72016-07-11 21:45:26 +00001//===- InfoStreamBuilder.cpp - PDB Info Stream Creation ---------*- 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
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000010#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
Zachary Turnerdbeaea72016-07-11 21:45:26 +000011
Zachary Turner620961d2016-09-14 23:00:02 +000012#include "llvm/DebugInfo/MSF/MSFBuilder.h"
Zachary Turnera3225b02016-07-29 20:56:36 +000013#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
14#include "llvm/DebugInfo/MSF/StreamWriter.h"
Adrian McCarthy6b6b8c42017-01-25 22:38:55 +000015#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
16#include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h"
17#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
18#include "llvm/DebugInfo/PDB/Native/RawError.h"
19#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
Zachary Turnerdbeaea72016-07-11 21:45:26 +000020
21using namespace llvm;
22using namespace llvm::codeview;
Zachary Turnerbac69d32016-07-22 19:56:05 +000023using namespace llvm::msf;
Zachary Turnerdbeaea72016-07-11 21:45:26 +000024using namespace llvm::pdb;
25
Zachary Turner760ad4d2017-01-20 22:42:09 +000026InfoStreamBuilder::InfoStreamBuilder(msf::MSFBuilder &Msf,
27 NamedStreamMap &NamedStreams)
28 : Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Sig(-1), Age(0),
29 NamedStreams(NamedStreams) {}
Zachary Turnerdbeaea72016-07-11 21:45:26 +000030
31void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; }
32
33void InfoStreamBuilder::setSignature(uint32_t S) { Sig = S; }
34
35void InfoStreamBuilder::setAge(uint32_t A) { Age = A; }
36
37void InfoStreamBuilder::setGuid(PDB_UniqueId G) { Guid = G; }
38
Zachary Turner620961d2016-09-14 23:00:02 +000039Error InfoStreamBuilder::finalizeMsfLayout() {
Zachary Turner60667ca2017-01-20 22:41:40 +000040 uint32_t Length = sizeof(InfoStreamHeader) + NamedStreams.finalize();
Zachary Turner620961d2016-09-14 23:00:02 +000041 if (auto EC = Msf.setStreamSize(StreamPDB, Length))
42 return EC;
43 return Error::success();
44}
45
Zachary Turnera3225b02016-07-29 20:56:36 +000046Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout,
Zachary Turnerd66889c2016-07-28 19:12:28 +000047 const msf::WritableStream &Buffer) const {
48 auto InfoS =
49 WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StreamPDB);
50 StreamWriter Writer(*InfoS);
51
52 InfoStreamHeader H;
53 H.Age = Age;
54 H.Signature = Sig;
55 H.Version = Ver;
56 H.Guid = Guid;
57 if (auto EC = Writer.writeObject(H))
58 return EC;
59
60 return NamedStreams.commit(Writer);
61}