push more ASTContext goodness out through interfaces that use
 TranslationUnit


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67913 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTConsumer.cpp b/lib/AST/ASTConsumer.cpp
index b3919f1..6c44d1a 100644
--- a/lib/AST/ASTConsumer.cpp
+++ b/lib/AST/ASTConsumer.cpp
@@ -13,7 +13,6 @@
 
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/Decl.h"
-#include "clang/AST/TranslationUnit.h"
 using namespace clang;
 
 ASTConsumer::~ASTConsumer() {}
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 9f8630f..f3cf6b1 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Bitcode/Serialize.h"
 #include "llvm/Bitcode/Deserialize.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/MemoryBuffer.h"
 using namespace clang;
 
 enum FloatingRank {
@@ -3086,7 +3087,21 @@
   DeclsBlock = 3
 };
 
-void ASTContext::EmitAll(llvm::Serializer &S) const {
+void ASTContext::EmitASTBitcodeBuffer(std::vector<unsigned char> &Buffer) const{
+  // Create bitstream.
+  llvm::BitstreamWriter Stream(Buffer);
+  
+  // Emit the preamble.
+  Stream.Emit((unsigned)'B', 8);
+  Stream.Emit((unsigned)'C', 8);
+  Stream.Emit(0xC, 4);
+  Stream.Emit(0xF, 4);
+  Stream.Emit(0xE, 4);
+  Stream.Emit(0x0, 4);
+  
+  // Create serializer.  
+  llvm::Serializer S(Stream);  
+  
   // ===---------------------------------------------------===/
   //      Serialize the "Translation Unit" metadata.
   // ===---------------------------------------------------===/
@@ -3142,8 +3157,32 @@
   // FIXME: S.EmitOwnedPtr(CFConstantStringTypeDecl);
 }
 
-ASTContext* ASTContext::CreateAll(llvm::Deserializer &Dezr,
-                                  FileManager &FMgr) {
+
+ASTContext *ASTContext::ReadASTBitcodeBuffer(llvm::MemoryBuffer &Buffer,
+                                             FileManager &FMgr) {
+  // Check if the file is of the proper length.
+  if (Buffer.getBufferSize() & 0x3) {
+    // FIXME: Provide diagnostic: "Length should be a multiple of 4 bytes."
+    return 0;
+  }
+  
+  // Create the bitstream reader.
+  unsigned char *BufPtr = (unsigned char *)Buffer.getBufferStart();
+  llvm::BitstreamReader Stream(BufPtr, BufPtr+Buffer.getBufferSize());
+  
+  if (Stream.Read(8) != 'B' ||
+      Stream.Read(8) != 'C' ||
+      Stream.Read(4) != 0xC ||
+      Stream.Read(4) != 0xF ||
+      Stream.Read(4) != 0xE ||
+      Stream.Read(4) != 0x0) {
+    // FIXME: Provide diagnostic.
+    return NULL;
+  }
+  
+  // Create the deserializer.
+  llvm::Deserializer Dezr(Stream);
+  
   // ===---------------------------------------------------===/
   //      Deserialize the "Translation Unit" metadata.
   // ===---------------------------------------------------===/
diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp
index 57f9f4e..0c69432 100644
--- a/lib/AST/TranslationUnit.cpp
+++ b/lib/AST/TranslationUnit.cpp
@@ -29,68 +29,3 @@
 
 TranslationUnit::~TranslationUnit() {
 }
-
-bool clang::EmitASTBitcodeBuffer(const ASTContext &Ctx, 
-                                 std::vector<unsigned char>& Buffer) {
-  // Create bitstream.
-  llvm::BitstreamWriter Stream(Buffer);
-  
-  // Emit the preamble.
-  Stream.Emit((unsigned)'B', 8);
-  Stream.Emit((unsigned)'C', 8);
-  Stream.Emit(0xC, 4);
-  Stream.Emit(0xF, 4);
-  Stream.Emit(0xE, 4);
-  Stream.Emit(0x0, 4);
-  
-  { 
-    // Create serializer.  Placing it in its own scope assures any necessary
-    // finalization of bits to the buffer in the serializer's dstor.    
-    llvm::Serializer Sezr(Stream);  
-    
-    // Emit the translation unit.
-    Ctx.EmitAll(Sezr);
-  }
-  
-  return true;
-}
-
-TranslationUnit*
-clang::ReadASTBitcodeBuffer(llvm::MemoryBuffer& MBuffer, FileManager& FMgr) {
-
-  // Check if the file is of the proper length.
-  if (MBuffer.getBufferSize() & 0x3) {
-    // FIXME: Provide diagnostic: "Length should be a multiple of 4 bytes."
-    return NULL;
-  }
-  
-  // Create the bitstream reader.
-  unsigned char *BufPtr = (unsigned char *) MBuffer.getBufferStart();
-  llvm::BitstreamReader Stream(BufPtr,BufPtr+MBuffer.getBufferSize());
-  
-  if (Stream.Read(8) != 'B' ||
-      Stream.Read(8) != 'C' ||
-      Stream.Read(4) != 0xC ||
-      Stream.Read(4) != 0xF ||
-      Stream.Read(4) != 0xE ||
-      Stream.Read(4) != 0x0) {
-    // FIXME: Provide diagnostic.
-    return NULL;
-  }
-  
-  // Create the deserializer.
-  llvm::Deserializer Dezr(Stream);
-  
-  return TranslationUnit::Create(Dezr,FMgr);
-}
-
-TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr,
-                                         FileManager& FMgr) {
-  
-  // Create the translation unit object.
-  TranslationUnit* TU = new TranslationUnit();
-  
-  TU->Context = ASTContext::CreateAll(Dezr, FMgr);
-  
-  return TU;
-}
diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp
index bcff1c8..fdc57b6 100644
--- a/lib/Sema/ParseAST.cpp
+++ b/lib/Sema/ParseAST.cpp
@@ -15,7 +15,6 @@
 #include "clang/Sema/ParseAST.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/Stmt.h"
-#include "clang/AST/TranslationUnit.h"
 #include "Sema.h"
 #include "clang/Parse/Parser.h"
 using namespace clang;