diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2011-02-18 02:25:12 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2011-02-18 02:25:12 +0000 |
commit | 14a552b2d71d4a4cf496953f62bc1337cbd8f9dc (patch) | |
tree | 0d8fbcdcbefb1d1574637634383be6c5c857f4b3 /clang/lib/CodeGen/CodeGenAction.cpp | |
parent | 3ae6caaf1bddccbc8c8281ec1b67f918df954d87 (diff) | |
download | bcm5719-llvm-14a552b2d71d4a4cf496953f62bc1337cbd8f9dc.tar.gz bcm5719-llvm-14a552b2d71d4a4cf496953f62bc1337cbd8f9dc.zip |
Move CompilerInstance::LLVMContext and LLVMContext ownership to CodeGenAction
This removes the final dependency edge from any lib outside of CodeGen
to core. As a result we can, and do, trim the dependency on core
from libclang, PrintFunctionNames, the unit tests and c-index-test.
While at it, review and trim other unneeded dependencies.
llvm-svn: 125820
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 69ac995a468..a24bbc480c1 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -224,9 +224,15 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D, // -CodeGenAction::CodeGenAction(unsigned _Act) : Act(_Act) {} - -CodeGenAction::~CodeGenAction() {} +CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext) + : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext), + OwnsVMContext(!_VMContext) {} + +CodeGenAction::~CodeGenAction() { + TheModule.reset(); + if (OwnsVMContext) + delete VMContext; +} bool CodeGenAction::hasIRSupport() const { return true; } @@ -243,6 +249,11 @@ llvm::Module *CodeGenAction::takeModule() { return TheModule.take(); } +llvm::LLVMContext *CodeGenAction::takeLLVMContext() { + OwnsVMContext = false; + return VMContext; +} + static raw_ostream *GetOutputStream(CompilerInstance &CI, llvm::StringRef InFile, BackendAction Action) { @@ -275,7 +286,7 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI, new BackendConsumer(BA, CI.getDiagnostics(), CI.getCodeGenOpts(), CI.getTargetOpts(), CI.getFrontendOpts().ShowTimers, InFile, OS.take(), - CI.getLLVMContext()); + *VMContext); return BEConsumer; } @@ -301,7 +312,7 @@ void CodeGenAction::ExecuteAction() { getCurrentFile().c_str()); llvm::SMDiagnostic Err; - TheModule.reset(ParseIR(MainFileCopy, Err, CI.getLLVMContext())); + TheModule.reset(ParseIR(MainFileCopy, Err, *VMContext)); if (!TheModule) { // Translate from the diagnostic info to the SourceManager location. SourceLocation Loc = SM.getLocation( @@ -332,15 +343,20 @@ void CodeGenAction::ExecuteAction() { // -EmitAssemblyAction::EmitAssemblyAction() - : CodeGenAction(Backend_EmitAssembly) {} +EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitAssembly, _VMContext) {} -EmitBCAction::EmitBCAction() : CodeGenAction(Backend_EmitBC) {} +EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitBC, _VMContext) {} -EmitLLVMAction::EmitLLVMAction() : CodeGenAction(Backend_EmitLL) {} +EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitLL, _VMContext) {} -EmitLLVMOnlyAction::EmitLLVMOnlyAction() : CodeGenAction(Backend_EmitNothing) {} +EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitNothing, _VMContext) {} -EmitCodeGenOnlyAction::EmitCodeGenOnlyAction() : CodeGenAction(Backend_EmitMCNull) {} +EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitMCNull, _VMContext) {} -EmitObjAction::EmitObjAction() : CodeGenAction(Backend_EmitObj) {} +EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext) + : CodeGenAction(Backend_EmitObj, _VMContext) {} |