Deleted Added
full compact
GeneratePCH.cpp (212904) GeneratePCH.cpp (218893)
1//===--- GeneratePCH.cpp - AST Consumer for PCH Generation ------*- 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//===----------------------------------------------------------------------===//

--- 5 unchanged lines hidden (view full) ---

14
15#include "clang/Frontend/ASTConsumers.h"
16#include "clang/Serialization/ASTWriter.h"
17#include "clang/Sema/SemaConsumer.h"
18#include "clang/AST/ASTContext.h"
19#include "clang/AST/ASTConsumer.h"
20#include "clang/Lex/Preprocessor.h"
21#include "clang/Basic/FileManager.h"
1//===--- GeneratePCH.cpp - AST Consumer for PCH Generation ------*- 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//===----------------------------------------------------------------------===//

--- 5 unchanged lines hidden (view full) ---

14
15#include "clang/Frontend/ASTConsumers.h"
16#include "clang/Serialization/ASTWriter.h"
17#include "clang/Sema/SemaConsumer.h"
18#include "clang/AST/ASTContext.h"
19#include "clang/AST/ASTConsumer.h"
20#include "clang/Lex/Preprocessor.h"
21#include "clang/Basic/FileManager.h"
22#include "clang/Basic/FileSystemStatCache.h"
22#include "llvm/Bitcode/BitstreamWriter.h"
23#include "llvm/Support/raw_ostream.h"
24#include <string>
25
26using namespace clang;
27
28PCHGenerator::PCHGenerator(const Preprocessor &PP,
23#include "llvm/Bitcode/BitstreamWriter.h"
24#include "llvm/Support/raw_ostream.h"
25#include <string>
26
27using namespace clang;
28
29PCHGenerator::PCHGenerator(const Preprocessor &PP,
30 const std::string &OutputFile,
29 bool Chaining,
30 const char *isysroot,
31 llvm::raw_ostream *OS)
31 bool Chaining,
32 const char *isysroot,
33 llvm::raw_ostream *OS)
32 : PP(PP), isysroot(isysroot), Out(OS), SemaPtr(0),
33 StatCalls(0), Stream(Buffer), Writer(Stream) {
34
34 : PP(PP), OutputFile(OutputFile), isysroot(isysroot), Out(OS), SemaPtr(0),
35 StatCalls(0), Stream(Buffer), Writer(Stream), Chaining(Chaining) {
35 // Install a stat() listener to keep track of all of the stat()
36 // calls.
36 // Install a stat() listener to keep track of all of the stat()
37 // calls.
37 StatCalls = new MemorizeStatCalls;
38 StatCalls = new MemorizeStatCalls();
38 // If we have a chain, we want new stat calls only, so install the memorizer
39 // *after* the already installed ASTReader's stat cache.
40 PP.getFileManager().addStatCache(StatCalls,
41 /*AtBeginning=*/!Chaining);
42}
43
44void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
45 if (PP.getDiagnostics().hasErrorOccurred())
46 return;
47
39 // If we have a chain, we want new stat calls only, so install the memorizer
40 // *after* the already installed ASTReader's stat cache.
41 PP.getFileManager().addStatCache(StatCalls,
42 /*AtBeginning=*/!Chaining);
43}
44
45void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
46 if (PP.getDiagnostics().hasErrorOccurred())
47 return;
48
49 // Set up the serialization listener.
50 Writer.SetSerializationListener(GetASTSerializationListener());
51
48 // Emit the PCH file
49 assert(SemaPtr && "No Sema?");
52 // Emit the PCH file
53 assert(SemaPtr && "No Sema?");
50 Writer.WriteAST(*SemaPtr, StatCalls, isysroot);
54 Writer.WriteAST(*SemaPtr, StatCalls, OutputFile, isysroot);
51
52 // Write the generated bitstream to "Out".
53 Out->write((char *)&Buffer.front(), Buffer.size());
54
55 // Make sure it hits disk now.
56 Out->flush();
57
58 // Free up some memory, in case the process is kept alive.
59 Buffer.clear();
60}
61
55
56 // Write the generated bitstream to "Out".
57 Out->write((char *)&Buffer.front(), Buffer.size());
58
59 // Make sure it hits disk now.
60 Out->flush();
61
62 // Free up some memory, in case the process is kept alive.
63 Buffer.clear();
64}
65
66ASTMutationListener *PCHGenerator::GetASTMutationListener() {
67 if (Chaining)
68 return &Writer;
69 return 0;
70}
71
72ASTSerializationListener *PCHGenerator::GetASTSerializationListener() {
73 return 0;
74}
75
62ASTDeserializationListener *PCHGenerator::GetASTDeserializationListener() {
63 return &Writer;
64}
76ASTDeserializationListener *PCHGenerator::GetASTDeserializationListener() {
77 return &Writer;
78}