aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-08-13 05:36:37 +0000
committerDouglas Gregor <dgregor@apple.com>2010-08-13 05:36:37 +0000
commit7ae2faafd30524ef5f863bb3b8701977888839bb (patch)
tree4749e0f5a8fb4572043bf74a2bc2bd300cf1da51 /lib/Frontend/ASTUnit.cpp
parentcaeed1d3a5b366ae8fda5dda9bddc7bbb859c41f (diff)
Implement clang_saveTranslationUnit(), which saves a translation unit
into a PCH/AST file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111006 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTUnit.cpp')
-rw-r--r--lib/Frontend/ASTUnit.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index b56a0d83a8..e501260af7 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -1340,3 +1340,26 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
Clang.takeCodeCompletionConsumer();
CCInvocation.getLangOpts().SpellChecking = SpellChecking;
}
+
+bool ASTUnit::Save(llvm::StringRef File) {
+ if (getDiagnostics().hasErrorOccurred())
+ return true;
+
+ // FIXME: Can we somehow regenerate the stat cache here, or do we need to
+ // unconditionally create a stat cache when we parse the file?
+ std::string ErrorInfo;
+ llvm::raw_fd_ostream Out(File.str().c_str(), ErrorInfo);
+ if (!ErrorInfo.empty() || Out.has_error())
+ return true;
+
+ std::vector<unsigned char> Buffer;
+ llvm::BitstreamWriter Stream(Buffer);
+ PCHWriter Writer(Stream);
+ Writer.WritePCH(getSema(), 0, 0);
+
+ // Write the generated bitstream to "Out".
+ Out.write((char *)&Buffer.front(), Buffer.size());
+ Out.flush();
+ Out.close();
+ return Out.has_error();
+}