xref: /aosp_15_r20/external/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- InfoStreamBuilder.cpp - PDB Info Stream Creation ---------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker 
10*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h"
11*9880d681SAndroid Build Coastguard Worker 
12*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/CodeView/StreamWriter.h"
13*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
14*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/DebugInfo/PDB/Raw/RawError.h"
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker using namespace llvm;
18*9880d681SAndroid Build Coastguard Worker using namespace llvm::codeview;
19*9880d681SAndroid Build Coastguard Worker using namespace llvm::pdb;
20*9880d681SAndroid Build Coastguard Worker 
InfoStreamBuilder(IPDBFile & File)21*9880d681SAndroid Build Coastguard Worker InfoStreamBuilder::InfoStreamBuilder(IPDBFile &File) : File(File) {}
22*9880d681SAndroid Build Coastguard Worker 
setVersion(PdbRaw_ImplVer V)23*9880d681SAndroid Build Coastguard Worker void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; }
24*9880d681SAndroid Build Coastguard Worker 
setSignature(uint32_t S)25*9880d681SAndroid Build Coastguard Worker void InfoStreamBuilder::setSignature(uint32_t S) { Sig = S; }
26*9880d681SAndroid Build Coastguard Worker 
setAge(uint32_t A)27*9880d681SAndroid Build Coastguard Worker void InfoStreamBuilder::setAge(uint32_t A) { Age = A; }
28*9880d681SAndroid Build Coastguard Worker 
setGuid(PDB_UniqueId G)29*9880d681SAndroid Build Coastguard Worker void InfoStreamBuilder::setGuid(PDB_UniqueId G) { Guid = G; }
30*9880d681SAndroid Build Coastguard Worker 
build()31*9880d681SAndroid Build Coastguard Worker Expected<std::unique_ptr<InfoStream>> InfoStreamBuilder::build() {
32*9880d681SAndroid Build Coastguard Worker   if (!Ver.hasValue())
33*9880d681SAndroid Build Coastguard Worker     return make_error<RawError>(raw_error_code::unspecified,
34*9880d681SAndroid Build Coastguard Worker                                 "Missing PDB Stream Version");
35*9880d681SAndroid Build Coastguard Worker   if (!Sig.hasValue())
36*9880d681SAndroid Build Coastguard Worker     return make_error<RawError>(raw_error_code::unspecified,
37*9880d681SAndroid Build Coastguard Worker                                 "Missing PDB Stream Signature");
38*9880d681SAndroid Build Coastguard Worker   if (!Age.hasValue())
39*9880d681SAndroid Build Coastguard Worker     return make_error<RawError>(raw_error_code::unspecified,
40*9880d681SAndroid Build Coastguard Worker                                 "Missing PDB Stream Age");
41*9880d681SAndroid Build Coastguard Worker   if (!Guid.hasValue())
42*9880d681SAndroid Build Coastguard Worker     return make_error<RawError>(raw_error_code::unspecified,
43*9880d681SAndroid Build Coastguard Worker                                 "Missing PDB Stream Guid");
44*9880d681SAndroid Build Coastguard Worker 
45*9880d681SAndroid Build Coastguard Worker   auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, File);
46*9880d681SAndroid Build Coastguard Worker   if (!InfoS)
47*9880d681SAndroid Build Coastguard Worker     return InfoS.takeError();
48*9880d681SAndroid Build Coastguard Worker   auto Info = llvm::make_unique<InfoStream>(std::move(*InfoS));
49*9880d681SAndroid Build Coastguard Worker   Info->Version = *Ver;
50*9880d681SAndroid Build Coastguard Worker   Info->Signature = *Sig;
51*9880d681SAndroid Build Coastguard Worker   Info->Age = *Age;
52*9880d681SAndroid Build Coastguard Worker   Info->Guid = *Guid;
53*9880d681SAndroid Build Coastguard Worker   return std::move(Info);
54*9880d681SAndroid Build Coastguard Worker }
55