Home | History | Annotate | Download | only in Raw
      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 
     21 InfoStreamBuilder::InfoStreamBuilder(IPDBFile &File) : File(File) {}
     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 
     31 Expected<std::unique_ptr<InfoStream>> InfoStreamBuilder::build() {
     32   if (!Ver.hasValue())
     33     return make_error<RawError>(raw_error_code::unspecified,
     34                                 "Missing PDB Stream Version");
     35   if (!Sig.hasValue())
     36     return make_error<RawError>(raw_error_code::unspecified,
     37                                 "Missing PDB Stream Signature");
     38   if (!Age.hasValue())
     39     return make_error<RawError>(raw_error_code::unspecified,
     40                                 "Missing PDB Stream Age");
     41   if (!Guid.hasValue())
     42     return make_error<RawError>(raw_error_code::unspecified,
     43                                 "Missing PDB Stream Guid");
     44 
     45   auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, File);
     46   if (!InfoS)
     47     return InfoS.takeError();
     48   auto Info = llvm::make_unique<InfoStream>(std::move(*InfoS));
     49   Info->Version = *Ver;
     50   Info->Signature = *Sig;
     51   Info->Age = *Age;
     52   Info->Guid = *Guid;
     53   return std::move(Info);
     54 }
     55