aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
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();
+}