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 | |
| 12 | #include "llvm/DebugInfo/CodeView/StreamWriter.h" |
| 13 | #include "llvm/DebugInfo/PDB/Raw/InfoStream.h" |
| 14 | #include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h" |
| 15 | #include "llvm/DebugInfo/PDB/Raw/RawError.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | using namespace llvm::codeview; |
| 19 | using namespace llvm::pdb; |
| 20 | |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame^] | 21 | InfoStreamBuilder::InfoStreamBuilder() {} |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 22 | |
| 23 | void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; } |
| 24 | |
| 25 | void InfoStreamBuilder::setSignature(uint32_t S) { Sig = S; } |
| 26 | |
| 27 | void InfoStreamBuilder::setAge(uint32_t A) { Age = A; } |
| 28 | |
| 29 | void InfoStreamBuilder::setGuid(PDB_UniqueId G) { Guid = G; } |
| 30 | |
Zachary Turner | faa554b | 2016-07-15 22:16:56 +0000 | [diff] [blame^] | 31 | uint32_t InfoStreamBuilder::calculateSerializedLength() const { |
| 32 | return sizeof(InfoStream::HeaderInfo) + |
| 33 | NamedStreams.calculateSerializedLength(); |
| 34 | } |
| 35 | |
| 36 | Expected<std::unique_ptr<InfoStream>> InfoStreamBuilder::build(PDBFile &File) { |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 37 | if (!Ver.hasValue()) |
| 38 | return make_error<RawError>(raw_error_code::unspecified, |
| 39 | "Missing PDB Stream Version"); |
| 40 | if (!Sig.hasValue()) |
| 41 | return make_error<RawError>(raw_error_code::unspecified, |
| 42 | "Missing PDB Stream Signature"); |
| 43 | if (!Age.hasValue()) |
| 44 | return make_error<RawError>(raw_error_code::unspecified, |
| 45 | "Missing PDB Stream Age"); |
| 46 | if (!Guid.hasValue()) |
| 47 | return make_error<RawError>(raw_error_code::unspecified, |
| 48 | "Missing PDB Stream Guid"); |
| 49 | |
| 50 | auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, File); |
| 51 | if (!InfoS) |
| 52 | return InfoS.takeError(); |
| 53 | auto Info = llvm::make_unique<InfoStream>(std::move(*InfoS)); |
| 54 | Info->Version = *Ver; |
| 55 | Info->Signature = *Sig; |
| 56 | Info->Age = *Age; |
| 57 | Info->Guid = *Guid; |
| 58 | return std::move(Info); |
| 59 | } |