diff options
Diffstat (limited to 'clang/lib/Serialization/GeneratePCH.cpp')
-rw-r--r-- | clang/lib/Serialization/GeneratePCH.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp index 0cd01dc6f3e..b5031fdf92a 100644 --- a/clang/lib/Serialization/GeneratePCH.cpp +++ b/clang/lib/Serialization/GeneratePCH.cpp @@ -19,6 +19,7 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Sema/SemaConsumer.h" #include "llvm/Bitcode/BitstreamWriter.h" +#include "llvm/Support/raw_ostream.h" #include <string> using namespace clang; @@ -27,11 +28,10 @@ PCHGenerator::PCHGenerator(const Preprocessor &PP, StringRef OutputFile, clang::Module *Module, StringRef isysroot, - bool AllowASTWithErrors) + raw_ostream *OS, bool AllowASTWithErrors) : PP(PP), OutputFile(OutputFile), Module(Module), - isysroot(isysroot.str()), - SemaPtr(nullptr), Stream(Buffer), - Writer(Stream), + isysroot(isysroot.str()), Out(OS), + SemaPtr(nullptr), Stream(Buffer), Writer(Stream), AllowASTWithErrors(AllowASTWithErrors), HasEmittedPCH(false) { } @@ -52,8 +52,14 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) { assert(SemaPtr && "No Sema?"); Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, hasErrors); - if (SerializationFinishedCallback) - SerializationFinishedCallback(&Buffer); + // Write the generated bitstream to "Out". + Out->write((char *)&Buffer.front(), Buffer.size()); + + // Make sure it hits disk now. + Out->flush(); + + // Free up some memory, in case the process is kept alive. + Buffer.clear(); HasEmittedPCH = true; } |