ParseAST now conditionally deletes the passed ASTConsumer.

ModuleBuilder now performs llvmgen in HandleTranslationUnit.

This patch follows from the discussion on the following thread on cfe-commits:

http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080804/006849.html

llvm-svn: 54486
This commit is contained in:
Ted Kremenek 2008-08-07 19:47:41 +00:00
parent 02ff450f13
commit 7db4f60b26
3 changed files with 15 additions and 11 deletions

View File

@ -21,7 +21,7 @@ namespace clang {
/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
/// the file is parsed. This takes ownership of the ASTConsumer and
/// ultimately deletes it.
void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false);
void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false, bool DeleteConsumer = true);
} // end namespace clang
#endif

View File

@ -50,12 +50,6 @@ namespace {
virtual ~CodeGeneratorImpl() {}
virtual llvm::Module* ReleaseModule() {
if (Diags.hasErrorOccurred())
return 0;
if (Builder)
Builder->Release();
return M.take();
}
@ -135,6 +129,15 @@ namespace {
Builder->UpdateCompletedType(D);
}
virtual void HandleTranslationUnit(TranslationUnit& TU) {
if (Diags.hasErrorOccurred()) {
M.reset();
return;
}
if (Builder)
Builder->Release();
};
};
}

View File

@ -27,7 +27,7 @@ using namespace clang;
/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
/// the file is parsed. This takes ownership of the ASTConsumer and
/// ultimately deletes it.
void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats, bool DeleteConsumer) {
// Collect global stats on Decls/Stmts (until we have a module streamer).
if (PrintStats) {
Decl::CollectingStats(true);
@ -78,5 +78,6 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
Stmt::CollectingStats(false);
}
if (DeleteConsumer)
delete Consumer;
}