Move CompilerInstance::LLVMContext and LLVMContext ownership to CodeGenAction
[clang.git] / include / clang / CodeGen / CodeGenAction.h
blob052c6603f5a7b639750b51adaa2177ce0e0a1ce6
1 //===--- CodeGenAction.h - LLVM Code Generation Frontend Action -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_CODEGEN_CODE_GEN_ACTION_H
11 #define LLVM_CLANG_CODEGEN_CODE_GEN_ACTION_H
13 #include "clang/Frontend/FrontendAction.h"
14 #include "llvm/ADT/OwningPtr.h"
16 namespace llvm {
17 class LLVMContext;
18 class Module;
21 namespace clang {
22 class BackendConsumer;
24 class CodeGenAction : public ASTFrontendAction {
25 private:
26 unsigned Act;
27 llvm::OwningPtr<llvm::Module> TheModule;
28 llvm::LLVMContext *VMContext;
29 bool OwnsVMContext;
31 protected:
32 /// Create a new code generation action. If the optional \arg _VMContext
33 /// parameter is supplied, the action uses it without taking ownership,
34 /// otherwise it creates a fresh LLVM context and takes ownership.
35 CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = 0);
37 virtual bool hasIRSupport() const;
39 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
40 llvm::StringRef InFile);
42 virtual void ExecuteAction();
44 virtual void EndSourceFileAction();
46 public:
47 ~CodeGenAction();
49 /// takeModule - Take the generated LLVM module, for use after the action has
50 /// been run. The result may be null on failure.
51 llvm::Module *takeModule();
53 /// Take the LLVM context used by this action.
54 llvm::LLVMContext *takeLLVMContext();
56 BackendConsumer *BEConsumer;
59 class EmitAssemblyAction : public CodeGenAction {
60 public:
61 EmitAssemblyAction(llvm::LLVMContext *_VMContext = 0);
64 class EmitBCAction : public CodeGenAction {
65 public:
66 EmitBCAction(llvm::LLVMContext *_VMContext = 0);
69 class EmitLLVMAction : public CodeGenAction {
70 public:
71 EmitLLVMAction(llvm::LLVMContext *_VMContext = 0);
74 class EmitLLVMOnlyAction : public CodeGenAction {
75 public:
76 EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = 0);
79 class EmitCodeGenOnlyAction : public CodeGenAction {
80 public:
81 EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = 0);
84 class EmitObjAction : public CodeGenAction {
85 public:
86 EmitObjAction(llvm::LLVMContext *_VMContext = 0);
91 #endif