diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-13 05:36:37 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-13 05:36:37 +0000 |
commit | e93866800330987d31579ae2fb2a323ba46ffecf (patch) | |
tree | d1694e5a6171be6672aa217838df92177499fcb6 /clang/lib | |
parent | 568b7500febfd2da88edf36e9aa0c89a9a6be1e8 (diff) | |
download | bcm5719-llvm-e93866800330987d31579ae2fb2a323ba46ffecf.tar.gz bcm5719-llvm-e93866800330987d31579ae2fb2a323ba46ffecf.zip |
Implement clang_saveTranslationUnit(), which saves a translation unit
into a PCH/AST file.
llvm-svn: 111006
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index b56a0d83a85..e501260af72 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/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(); +} |