Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 10 | #include "llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h" |
| 11 | |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/Msf/MappedBlockStream.h" |
| 13 | #include "llvm/DebugInfo/Msf/StreamWriter.h" |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/Raw/RawError.h" |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame^] | 16 | #include "llvm/DebugInfo/PDB/Raw/RawTypes.h" |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace llvm; |
| 19 | using namespace llvm::codeview; |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 20 | using namespace llvm::msf; |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 21 | using namespace llvm::pdb; |
| 22 | |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame^] | 23 | InfoStreamBuilder::InfoStreamBuilder() |
| 24 | : Ver(PdbRaw_ImplVer::PdbImplVC70), Sig(-1), Age(0) {} |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 25 | |
| 26 | void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; } |
| 27 | |
| 28 | void InfoStreamBuilder::setSignature(uint32_t S) { Sig = S; } |
| 29 | |
| 30 | void InfoStreamBuilder::setAge(uint32_t A) { Age = A; } |
| 31 | |
| 32 | void InfoStreamBuilder::setGuid(PDB_UniqueId G) { Guid = G; } |
| 33 | |
Zachary Turner | 5e534c7 | 2016-07-15 22:17:08 +0000 | [diff] [blame] | 34 | NameMapBuilder &InfoStreamBuilder::getNamedStreamsBuilder() { |
| 35 | return NamedStreams; |
| 36 | } |
| 37 | |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 38 | uint32_t InfoStreamBuilder::calculateSerializedLength() const { |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame^] | 39 | return sizeof(InfoStreamHeader) + NamedStreams.calculateSerializedLength(); |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame^] | 42 | Expected<std::unique_ptr<InfoStream>> |
| 43 | InfoStreamBuilder::build(PDBFile &File, const msf::WritableStream &Buffer) { |
| 44 | auto StreamData = MappedBlockStream::createIndexedStream(File.getMsfLayout(), |
| 45 | Buffer, StreamPDB); |
| 46 | auto Info = llvm::make_unique<InfoStream>(std::move(StreamData)); |
| 47 | Info->Version = Ver; |
| 48 | Info->Signature = Sig; |
| 49 | Info->Age = Age; |
| 50 | Info->Guid = Guid; |
Zachary Turner | 5e534c7 | 2016-07-15 22:17:08 +0000 | [diff] [blame] | 51 | auto NS = NamedStreams.build(); |
| 52 | if (!NS) |
| 53 | return NS.takeError(); |
| 54 | Info->NamedStreams = **NS; |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 55 | return std::move(Info); |
| 56 | } |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame^] | 57 | |
| 58 | Error InfoStreamBuilder::commit(const msf::MsfLayout &Layout, |
| 59 | const msf::WritableStream &Buffer) const { |
| 60 | auto InfoS = |
| 61 | WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StreamPDB); |
| 62 | StreamWriter Writer(*InfoS); |
| 63 | |
| 64 | InfoStreamHeader H; |
| 65 | H.Age = Age; |
| 66 | H.Signature = Sig; |
| 67 | H.Version = Ver; |
| 68 | H.Guid = Guid; |
| 69 | if (auto EC = Writer.writeObject(H)) |
| 70 | return EC; |
| 71 | |
| 72 | return NamedStreams.commit(Writer); |
| 73 | } |