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 | |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame^] | 10 | #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h" |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 11 | |
Zachary Turner | 620961d | 2016-09-14 23:00:02 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/MSF/MSFBuilder.h" |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/MSF/MappedBlockStream.h" |
| 14 | #include "llvm/DebugInfo/MSF/StreamWriter.h" |
Adrian McCarthy | 6b6b8c4 | 2017-01-25 22:38:55 +0000 | [diff] [blame^] | 15 | #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 Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
| 22 | using namespace llvm::codeview; |
Zachary Turner | bac69d3 | 2016-07-22 19:56:05 +0000 | [diff] [blame] | 23 | using namespace llvm::msf; |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 24 | using namespace llvm::pdb; |
| 25 | |
Zachary Turner | 760ad4d | 2017-01-20 22:42:09 +0000 | [diff] [blame] | 26 | InfoStreamBuilder::InfoStreamBuilder(msf::MSFBuilder &Msf, |
| 27 | NamedStreamMap &NamedStreams) |
| 28 | : Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Sig(-1), Age(0), |
| 29 | NamedStreams(NamedStreams) {} |
Zachary Turner | dbeaea7 | 2016-07-11 21:45:26 +0000 | [diff] [blame] | 30 | |
| 31 | void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; } |
| 32 | |
| 33 | void InfoStreamBuilder::setSignature(uint32_t S) { Sig = S; } |
| 34 | |
| 35 | void InfoStreamBuilder::setAge(uint32_t A) { Age = A; } |
| 36 | |
| 37 | void InfoStreamBuilder::setGuid(PDB_UniqueId G) { Guid = G; } |
| 38 | |
Zachary Turner | 620961d | 2016-09-14 23:00:02 +0000 | [diff] [blame] | 39 | Error InfoStreamBuilder::finalizeMsfLayout() { |
Zachary Turner | 60667ca | 2017-01-20 22:41:40 +0000 | [diff] [blame] | 40 | uint32_t Length = sizeof(InfoStreamHeader) + NamedStreams.finalize(); |
Zachary Turner | 620961d | 2016-09-14 23:00:02 +0000 | [diff] [blame] | 41 | if (auto EC = Msf.setStreamSize(StreamPDB, Length)) |
| 42 | return EC; |
| 43 | return Error::success(); |
| 44 | } |
| 45 | |
Zachary Turner | a3225b0 | 2016-07-29 20:56:36 +0000 | [diff] [blame] | 46 | Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout, |
Zachary Turner | d66889c | 2016-07-28 19:12:28 +0000 | [diff] [blame] | 47 | 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 | } |