blob: 28c4a8fc35d9219b087450914bf2db8f876cccc8 [file] [log] [blame]
Zachary Turner7eaf1d92017-07-10 22:40:20 +00001//===- DbiStreamBuilder.cpp - PDB Dbi 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
10#include "llvm/DebugInfo/PDB/Native/PublicsStreamBuilder.h"
11
12#include "llvm/DebugInfo/MSF/MSFBuilder.h"
13#include "llvm/DebugInfo/MSF/MSFCommon.h"
14#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
15
16#include "GSI.h"
17
18using namespace llvm;
19using namespace llvm::msf;
20using namespace llvm::pdb;
21
22PublicsStreamBuilder::PublicsStreamBuilder(msf::MSFBuilder &Msf) : Msf(Msf) {}
23
24PublicsStreamBuilder::~PublicsStreamBuilder() {}
25
26uint32_t PublicsStreamBuilder::calculateSerializedLength() const {
27 uint32_t Size = 0;
28 Size += sizeof(PublicsStreamHeader);
29 Size += sizeof(GSIHashHeader);
30 Size += HashRecords.size() * sizeof(PSHashRecord);
31 size_t BitmapSizeInBits = alignTo(IPHR_HASH + 1, 32);
32 uint32_t NumBitmapEntries = BitmapSizeInBits / 8;
33 Size += NumBitmapEntries;
34
35 // FIXME: Account for hash buckets. For now since we we write a zero-bitmap
36 // indicating that no hash buckets are valid, we also write zero byets of hash
37 // bucket data.
38 Size += 0;
39 return Size;
40}
41
42Error PublicsStreamBuilder::finalizeMsfLayout() {
43 Expected<uint32_t> Idx = Msf.addStream(calculateSerializedLength());
44 if (!Idx)
45 return Idx.takeError();
46 StreamIdx = *Idx;
47
48 Expected<uint32_t> RecordIdx = Msf.addStream(0);
49 if (!RecordIdx)
50 return RecordIdx.takeError();
51 RecordStreamIdx = *RecordIdx;
52 return Error::success();
53}
54
55Error PublicsStreamBuilder::commit(BinaryStreamWriter &PublicsWriter) {
56 PublicsStreamHeader PSH;
57 GSIHashHeader GSH;
58
59 // FIXME: Figure out what to put for these values.
60 PSH.AddrMap = 0;
61 PSH.ISectThunkTable = 0;
62 PSH.NumSections = 0;
63 PSH.NumThunks = 0;
64 PSH.OffThunkTable = 0;
65 PSH.SizeOfThunk = 0;
66 PSH.SymHash = 0;
67
68 GSH.VerSignature = GSIHashHeader::HdrSignature;
69 GSH.VerHdr = GSIHashHeader::HdrVersion;
70 GSH.HrSize = 0;
71 GSH.NumBuckets = 0;
72
73 if (auto EC = PublicsWriter.writeObject(PSH))
74 return EC;
75 if (auto EC = PublicsWriter.writeObject(GSH))
76 return EC;
77 if (auto EC = PublicsWriter.writeArray(makeArrayRef(HashRecords)))
78 return EC;
79
80 size_t BitmapSizeInBits = alignTo(IPHR_HASH + 1, 32);
81 uint32_t NumBitmapEntries = BitmapSizeInBits / 8;
82 std::vector<uint8_t> BitmapData(NumBitmapEntries);
83 // FIXME: Build an actual bitmap
84 if (auto EC = PublicsWriter.writeBytes(makeArrayRef(BitmapData)))
85 return EC;
86
87 // FIXME: Write actual hash buckets.
88 return Error::success();
89}