1 //===- InfoStreamBuilder.cpp - PDB Info Stream Creation ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
12 #include "llvm/DebugInfo/MSF/MSFBuilder.h"
13 #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
14 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
15 #include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h"
16 #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
17 #include "llvm/DebugInfo/PDB/Native/RawError.h"
18 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
19 #include "llvm/Support/BinaryStreamWriter.h"
22 using namespace llvm::codeview;
23 using namespace llvm::msf;
24 using namespace llvm::pdb;
26 InfoStreamBuilder::InfoStreamBuilder(msf::MSFBuilder &Msf,
27 NamedStreamMap &NamedStreams)
28 : Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Sig(-1), Age(0),
29 NamedStreams(NamedStreams) {}
31 void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; }
33 void InfoStreamBuilder::setSignature(uint32_t S) { Sig = S; }
35 void InfoStreamBuilder::setAge(uint32_t A) { Age = A; }
37 void InfoStreamBuilder::setGuid(GUID G) { Guid = G; }
39 void InfoStreamBuilder::addFeature(PdbRaw_FeatureSig Sig) {
40 Features.push_back(Sig);
43 Error InfoStreamBuilder::finalizeMsfLayout() {
44 uint32_t Length = sizeof(InfoStreamHeader) + NamedStreams.finalize() +
45 (Features.size() + 1) * sizeof(uint32_t);
46 if (auto EC = Msf.setStreamSize(StreamPDB, Length))
48 return Error::success();
51 Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout,
52 WritableBinaryStreamRef Buffer) const {
53 auto InfoS = WritableMappedBlockStream::createIndexedStream(
54 Layout, Buffer, StreamPDB, Msf.getAllocator());
55 BinaryStreamWriter Writer(*InfoS);
62 if (auto EC = Writer.writeObject(H))
65 if (auto EC = NamedStreams.commit(Writer))
67 if (auto EC = Writer.writeInteger(0))
69 for (auto E : Features) {
70 if (auto EC = Writer.writeEnum(E))
73 return Error::success();