Move PCHContainerOperations from Frontend to Serialization
authorRichard Trieu <rtrieu@google.com>
Wed, 12 Dec 2018 02:53:59 +0000 (02:53 +0000)
committerRichard Trieu <rtrieu@google.com>
Wed, 12 Dec 2018 02:53:59 +0000 (02:53 +0000)
Fix a layering violation.  Frontend depends on Serialization, so anything used
by both should be in Serialization.

llvm-svn: 348907

clang/include/clang/Frontend/PCHContainerOperations.h
clang/include/clang/Serialization/ASTWriter.h
clang/include/clang/Serialization/PCHContainerOperations.h [new file with mode: 0644]
clang/include/clang/module.modulemap
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Frontend/CMakeLists.txt
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/CMakeLists.txt
clang/lib/Serialization/GlobalModuleIndex.cpp
clang/lib/Serialization/ModuleManager.cpp
clang/lib/Serialization/PCHContainerOperations.cpp [moved from clang/lib/Frontend/PCHContainerOperations.cpp with 94% similarity]

index 63d35e1..675efba 100644 (file)
 #ifndef LLVM_CLANG_PCH_CONTAINER_OPERATIONS_H
 #define LLVM_CLANG_PCH_CONTAINER_OPERATIONS_H
 
-#include "clang/Basic/Module.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include <memory>
-
-namespace llvm {
-class raw_pwrite_stream;
-}
-
-namespace clang {
-
-class ASTConsumer;
-class CodeGenOptions;
-class DiagnosticsEngine;
-class CompilerInstance;
-
-struct PCHBuffer {
-  ASTFileSignature Signature;
-  llvm::SmallVector<char, 0> Data;
-  bool IsComplete;
-};
-
-/// This abstract interface provides operations for creating
-/// containers for serialized ASTs (precompiled headers and clang
-/// modules).
-class PCHContainerWriter {
-public:
-  virtual ~PCHContainerWriter() = 0;
-  virtual llvm::StringRef getFormat() const = 0;
-
-  /// Return an ASTConsumer that can be chained with a
-  /// PCHGenerator that produces a wrapper file format containing a
-  /// serialized AST bitstream.
-  virtual std::unique_ptr<ASTConsumer>
-  CreatePCHContainerGenerator(CompilerInstance &CI,
-                              const std::string &MainFileName,
-                              const std::string &OutputFileName,
-                              std::unique_ptr<llvm::raw_pwrite_stream> OS,
-                              std::shared_ptr<PCHBuffer> Buffer) const = 0;
-};
-
-/// This abstract interface provides operations for unwrapping
-/// containers for serialized ASTs (precompiled headers and clang
-/// modules).
-class PCHContainerReader {
-public:
-  virtual ~PCHContainerReader() = 0;
-  /// Equivalent to the format passed to -fmodule-format=
-  virtual llvm::StringRef getFormat() const = 0;
-
-  /// Returns the serialized AST inside the PCH container Buffer.
-  virtual llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const = 0;
-};
-
-/// Implements write operations for a raw pass-through PCH container.
-class RawPCHContainerWriter : public PCHContainerWriter {
-  llvm::StringRef getFormat() const override { return "raw"; }
-
-  /// Return an ASTConsumer that can be chained with a
-  /// PCHGenerator that writes the module to a flat file.
-  std::unique_ptr<ASTConsumer>
-  CreatePCHContainerGenerator(CompilerInstance &CI,
-                              const std::string &MainFileName,
-                              const std::string &OutputFileName,
-                              std::unique_ptr<llvm::raw_pwrite_stream> OS,
-                              std::shared_ptr<PCHBuffer> Buffer) const override;
-};
-
-/// Implements read operations for a raw pass-through PCH container.
-class RawPCHContainerReader : public PCHContainerReader {
-  llvm::StringRef getFormat() const override { return "raw"; }
-
-  /// Simply returns the buffer contained in Buffer.
-  llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
-};
-
-/// A registry of PCHContainerWriter and -Reader objects for different formats.
-class PCHContainerOperations {
-  llvm::StringMap<std::unique_ptr<PCHContainerWriter>> Writers;
-  llvm::StringMap<std::unique_ptr<PCHContainerReader>> Readers;
-public:
-  /// Automatically registers a RawPCHContainerWriter and
-  /// RawPCHContainerReader.
-  PCHContainerOperations();
-  void registerWriter(std::unique_ptr<PCHContainerWriter> Writer) {
-    Writers[Writer->getFormat()] = std::move(Writer);
-  }
-  void registerReader(std::unique_ptr<PCHContainerReader> Reader) {
-    Readers[Reader->getFormat()] = std::move(Reader);
-  }
-  const PCHContainerWriter *getWriterOrNull(llvm::StringRef Format) {
-    return Writers[Format].get();
-  }
-  const PCHContainerReader *getReaderOrNull(llvm::StringRef Format) {
-    return Readers[Format].get();
-  }
-  const PCHContainerReader &getRawReader() {
-    return *getReaderOrNull("raw");
-  }
-};
-
-}
+#include "clang/Serialization/PCHContainerOperations.h"
 
 #endif
index da8b10a..11af30a 100644 (file)
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Sema/SemaConsumer.h"
 #include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTDeserializationListener.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
diff --git a/clang/include/clang/Serialization/PCHContainerOperations.h b/clang/include/clang/Serialization/PCHContainerOperations.h
new file mode 100644 (file)
index 0000000..2a91d98
--- /dev/null
@@ -0,0 +1,117 @@
+//===--- Serialization/PCHContainerOperations.h - PCH Containers --*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SERIALIZATION_PCHCONTAINEROPERATIONS_H
+#define LLVM_CLANG_SERIALIZATION_PCHCONTAINEROPERATIONS_H
+
+#include "clang/Basic/Module.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include <memory>
+
+namespace llvm {
+class raw_pwrite_stream;
+}
+
+namespace clang {
+
+class ASTConsumer;
+class CodeGenOptions;
+class DiagnosticsEngine;
+class CompilerInstance;
+
+struct PCHBuffer {
+  ASTFileSignature Signature;
+  llvm::SmallVector<char, 0> Data;
+  bool IsComplete;
+};
+
+/// This abstract interface provides operations for creating
+/// containers for serialized ASTs (precompiled headers and clang
+/// modules).
+class PCHContainerWriter {
+public:
+  virtual ~PCHContainerWriter() = 0;
+  virtual llvm::StringRef getFormat() const = 0;
+
+  /// Return an ASTConsumer that can be chained with a
+  /// PCHGenerator that produces a wrapper file format containing a
+  /// serialized AST bitstream.
+  virtual std::unique_ptr<ASTConsumer>
+  CreatePCHContainerGenerator(CompilerInstance &CI,
+                              const std::string &MainFileName,
+                              const std::string &OutputFileName,
+                              std::unique_ptr<llvm::raw_pwrite_stream> OS,
+                              std::shared_ptr<PCHBuffer> Buffer) const = 0;
+};
+
+/// This abstract interface provides operations for unwrapping
+/// containers for serialized ASTs (precompiled headers and clang
+/// modules).
+class PCHContainerReader {
+public:
+  virtual ~PCHContainerReader() = 0;
+  /// Equivalent to the format passed to -fmodule-format=
+  virtual llvm::StringRef getFormat() const = 0;
+
+  /// Returns the serialized AST inside the PCH container Buffer.
+  virtual llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const = 0;
+};
+
+/// Implements write operations for a raw pass-through PCH container.
+class RawPCHContainerWriter : public PCHContainerWriter {
+  llvm::StringRef getFormat() const override { return "raw"; }
+
+  /// Return an ASTConsumer that can be chained with a
+  /// PCHGenerator that writes the module to a flat file.
+  std::unique_ptr<ASTConsumer>
+  CreatePCHContainerGenerator(CompilerInstance &CI,
+                              const std::string &MainFileName,
+                              const std::string &OutputFileName,
+                              std::unique_ptr<llvm::raw_pwrite_stream> OS,
+                              std::shared_ptr<PCHBuffer> Buffer) const override;
+};
+
+/// Implements read operations for a raw pass-through PCH container.
+class RawPCHContainerReader : public PCHContainerReader {
+  llvm::StringRef getFormat() const override { return "raw"; }
+
+  /// Simply returns the buffer contained in Buffer.
+  llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
+};
+
+/// A registry of PCHContainerWriter and -Reader objects for different formats.
+class PCHContainerOperations {
+  llvm::StringMap<std::unique_ptr<PCHContainerWriter>> Writers;
+  llvm::StringMap<std::unique_ptr<PCHContainerReader>> Readers;
+public:
+  /// Automatically registers a RawPCHContainerWriter and
+  /// RawPCHContainerReader.
+  PCHContainerOperations();
+  void registerWriter(std::unique_ptr<PCHContainerWriter> Writer) {
+    Writers[Writer->getFormat()] = std::move(Writer);
+  }
+  void registerReader(std::unique_ptr<PCHContainerReader> Reader) {
+    Readers[Reader->getFormat()] = std::move(Reader);
+  }
+  const PCHContainerWriter *getWriterOrNull(llvm::StringRef Format) {
+    return Writers[Format].get();
+  }
+  const PCHContainerReader *getReaderOrNull(llvm::StringRef Format) {
+    return Readers[Format].get();
+  }
+  const PCHContainerReader &getRawReader() {
+    return *getReaderOrNull("raw");
+  }
+};
+
+}
+
+#endif
index 1f6eacc..cbcb62e 100644 (file)
@@ -103,9 +103,6 @@ module Clang_Frontend {
   textual header "Frontend/LangStandards.def"
 
   module * { export * }
-
-  // FIXME: This violates layers.
-  exclude header "Frontend/PCHContainerOperations.h"
 }
 
 module Clang_FrontendTool { requires cplusplus umbrella "FrontendTool" module * { export * } }
index 05e47af..c7b2551 100644 (file)
@@ -44,7 +44,6 @@
 #include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Frontend/FrontendOptions.h"
 #include "clang/Frontend/MultiplexConsumer.h"
-#include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/HeaderSearch.h"
@@ -63,6 +62,7 @@
 #include "clang/Serialization/ASTWriter.h"
 #include "clang/Serialization/ContinuousRangeMap.h"
 #include "clang/Serialization/Module.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
index a207ccc..3bd1595 100644 (file)
@@ -36,7 +36,6 @@ add_clang_library(clangFrontend
   LogDiagnosticPrinter.cpp
   ModuleDependencyCollector.cpp
   MultiplexConsumer.cpp
-  PCHContainerOperations.cpp
   PrecompiledPreamble.cpp
   PrintPreprocessedOutput.cpp
   SerializedDiagnosticPrinter.cpp
index 0147e3a..67ab601 100644 (file)
@@ -61,7 +61,6 @@
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Basic/Version.h"
-#include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/MacroInfo.h"
@@ -81,6 +80,7 @@
 #include "clang/Serialization/Module.h"
 #include "clang/Serialization/ModuleFileExtension.h"
 #include "clang/Serialization/ModuleManager.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "clang/Serialization/SerializationDiagnostic.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
index 95b33c3..a312cb9 100644 (file)
@@ -17,6 +17,7 @@ add_clang_library(clangSerialization
   Module.cpp
   ModuleFileExtension.cpp
   ModuleManager.cpp
+  PCHContainerOperations.cpp
 
   ADDITIONAL_HEADERS
   ASTCommon.h
index 3733638..e7642a3 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "ASTReaderInternals.h"
-#include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "clang/Serialization/Module.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallString.h"
index 683ba8f..54e0c08 100644 (file)
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/MemoryBufferCache.h"
-#include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/ModuleMap.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
 #include "clang/Serialization/Module.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -1,4 +1,4 @@
-//===--- Frontend/PCHContainerOperations.cpp - PCH Containers ---*- C++ -*-===//
+//=== Serialization/PCHContainerOperations.cpp - PCH Containers -*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -11,7 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Frontend/PCHContainerOperations.h"
+#include "clang/Serialization/PCHContainerOperations.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/Lex/ModuleLoader.h"
 #include "llvm/Bitcode/BitstreamReader.h"