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 | 906c73ffbc78542ad333becb6e013dd9efc299b6 (patch) | |
tree | ba454de9c55cb9e52010de9a138225f7fa4debe3 /lib/CodeGen/CodeGenAction.cpp | |
parent | ef9a1d0e13662162aa8cdae8732c33b5d751d80c (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125820 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenAction.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index 69ac995a46..a24bbc480c 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/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) {} |