clang  3.7.0
PCHContainerOperations.cpp
Go to the documentation of this file.
1 //===--- Frontend/PCHContainerOperations.cpp - PCH Containers ---*- 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 // This file defines PCHContainerOperations and RawPCHContainerOperation.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "clang/AST/ASTConsumer.h"
16 #include "llvm/Bitcode/BitstreamReader.h"
17 #include "llvm/Support/raw_ostream.h"
18 #include "clang/Lex/ModuleLoader.h"
19 using namespace clang;
20 
21 namespace {
22 
23 /// \brief A PCHContainerGenerator that writes out the PCH to a flat file.
24 class RawPCHContainerGenerator : public ASTConsumer {
25  std::shared_ptr<PCHBuffer> Buffer;
26  raw_pwrite_stream *OS;
27 
28 public:
29  RawPCHContainerGenerator(DiagnosticsEngine &Diags,
30  const HeaderSearchOptions &HSO,
31  const PreprocessorOptions &PPO,
32  const TargetOptions &TO, const LangOptions &LO,
33  const std::string &MainFileName,
34  const std::string &OutputFileName,
35  llvm::raw_pwrite_stream *OS,
36  std::shared_ptr<PCHBuffer> Buffer)
37  : Buffer(Buffer), OS(OS) {}
38 
39  virtual ~RawPCHContainerGenerator() {}
40 
41  void HandleTranslationUnit(ASTContext &Ctx) override {
42  if (Buffer->IsComplete) {
43  // Make sure it hits disk now.
44  *OS << Buffer->Data;
45  OS->flush();
46  }
47  // Free the space of the temporary buffer.
49  Buffer->Data = std::move(Empty);
50  }
51 };
52 }
53 
54 std::unique_ptr<ASTConsumer> RawPCHContainerWriter::CreatePCHContainerGenerator(
55  DiagnosticsEngine &Diags, const HeaderSearchOptions &HSO,
56  const PreprocessorOptions &PPO, const TargetOptions &TO,
57  const LangOptions &LO, const std::string &MainFileName,
58  const std::string &OutputFileName, llvm::raw_pwrite_stream *OS,
59  std::shared_ptr<PCHBuffer> Buffer) const {
60  return llvm::make_unique<RawPCHContainerGenerator>(
61  Diags, HSO, PPO, TO, LO, MainFileName, OutputFileName, OS, Buffer);
62 }
63 
64 void RawPCHContainerReader::ExtractPCH(
65  llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const {
66  StreamFile.init((const unsigned char *)Buffer.getBufferStart(),
67  (const unsigned char *)Buffer.getBufferEnd());
68 }
69 
71  registerWriter(llvm::make_unique<RawPCHContainerWriter>());
72  registerReader(llvm::make_unique<RawPCHContainerReader>());
73 }
Options for controlling the target.
Definition: TargetOptions.h:24
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
void registerReader(std::unique_ptr< PCHContainerReader > Reader)
void registerWriter(std::unique_ptr< PCHContainerWriter > Writer)