clang  6.0.0svn
PCHContainerOperations.h
Go to the documentation of this file.
1 //===--- Frontend/PCHContainerOperations.h - 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 #ifndef LLVM_CLANG_PCH_CONTAINER_OPERATIONS_H
11 #define LLVM_CLANG_PCH_CONTAINER_OPERATIONS_H
12 
13 #include "clang/Basic/Module.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringMap.h"
16 #include "llvm/Support/MemoryBuffer.h"
17 #include <memory>
18 
19 namespace llvm {
20 class raw_pwrite_stream;
21 }
22 
23 using llvm::StringRef;
24 
25 namespace clang {
26 
27 class ASTConsumer;
28 class CodeGenOptions;
29 class DiagnosticsEngine;
30 class CompilerInstance;
31 
32 struct PCHBuffer {
35  bool IsComplete;
36 };
37 
38 /// This abstract interface provides operations for creating
39 /// containers for serialized ASTs (precompiled headers and clang
40 /// modules).
42 public:
43  virtual ~PCHContainerWriter() = 0;
44  virtual StringRef getFormat() const = 0;
45 
46  /// Return an ASTConsumer that can be chained with a
47  /// PCHGenerator that produces a wrapper file format containing a
48  /// serialized AST bitstream.
49  virtual std::unique_ptr<ASTConsumer>
50  CreatePCHContainerGenerator(CompilerInstance &CI,
51  const std::string &MainFileName,
52  const std::string &OutputFileName,
53  std::unique_ptr<llvm::raw_pwrite_stream> OS,
54  std::shared_ptr<PCHBuffer> Buffer) const = 0;
55 };
56 
57 /// This abstract interface provides operations for unwrapping
58 /// containers for serialized ASTs (precompiled headers and clang
59 /// modules).
61 public:
62  virtual ~PCHContainerReader() = 0;
63  /// Equivalent to the format passed to -fmodule-format=
64  virtual StringRef getFormat() const = 0;
65 
66  /// Returns the serialized AST inside the PCH container Buffer.
67  virtual StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const = 0;
68 };
69 
70 /// Implements write operations for a raw pass-through PCH container.
72  StringRef getFormat() const override { return "raw"; }
73 
74  /// Return an ASTConsumer that can be chained with a
75  /// PCHGenerator that writes the module to a flat file.
76  std::unique_ptr<ASTConsumer>
77  CreatePCHContainerGenerator(CompilerInstance &CI,
78  const std::string &MainFileName,
79  const std::string &OutputFileName,
80  std::unique_ptr<llvm::raw_pwrite_stream> OS,
81  std::shared_ptr<PCHBuffer> Buffer) const override;
82 };
83 
84 /// Implements read operations for a raw pass-through PCH container.
86  StringRef getFormat() const override { return "raw"; }
87 
88  /// Simply returns the buffer contained in Buffer.
89  StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
90 };
91 
92 /// A registry of PCHContainerWriter and -Reader objects for different formats.
94  llvm::StringMap<std::unique_ptr<PCHContainerWriter>> Writers;
95  llvm::StringMap<std::unique_ptr<PCHContainerReader>> Readers;
96 public:
97  /// Automatically registers a RawPCHContainerWriter and
98  /// RawPCHContainerReader.
100  void registerWriter(std::unique_ptr<PCHContainerWriter> Writer) {
101  Writers[Writer->getFormat()] = std::move(Writer);
102  }
103  void registerReader(std::unique_ptr<PCHContainerReader> Reader) {
104  Readers[Reader->getFormat()] = std::move(Reader);
105  }
106  const PCHContainerWriter *getWriterOrNull(StringRef Format) {
107  return Writers[Format].get();
108  }
109  const PCHContainerReader *getReaderOrNull(StringRef Format) {
110  return Readers[Format].get();
111  }
113  return *getReaderOrNull("raw");
114  }
115 };
116 
117 }
118 
119 #endif
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
Defines the clang::Module class, which describes a module in the source code.
A registry of PCHContainerWriter and -Reader objects for different formats.
The signature of a module, which is a hash of the AST content.
Definition: Module.h:47
This abstract interface provides operations for creating containers for serialized ASTs (precompiled ...
const PCHContainerWriter * getWriterOrNull(StringRef Format)
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
void registerReader(std::unique_ptr< PCHContainerReader > Reader)
const PCHContainerReader & getRawReader()
ASTFileSignature Signature
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
const PCHContainerReader * getReaderOrNull(StringRef Format)
Dataflow Directional Tag Classes.
Implements read operations for a raw pass-through PCH container.
llvm::SmallVector< char, 0 > Data
void registerWriter(std::unique_ptr< PCHContainerWriter > Writer)
Implements write operations for a raw pass-through PCH container.