1 //===--- CodeGenAction.h - LLVM Code Generation Frontend Action -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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"
22 class BackendConsumer;
24 class CodeGenAction : public ASTFrontendAction {
27 OwningPtr<llvm::Module> TheModule;
28 llvm::Module *LinkModule;
29 llvm::LLVMContext *VMContext;
33 /// Create a new code generation action. If the optional \p _VMContext
34 /// parameter is supplied, the action uses it without taking ownership,
35 /// otherwise it creates a fresh LLVM context and takes ownership.
36 CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = 0);
38 virtual bool hasIRSupport() const;
40 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
43 virtual void ExecuteAction();
45 virtual void EndSourceFileAction();
50 /// setLinkModule - Set the link module to be used by this action. If a link
51 /// module is not provided, and CodeGenOptions::LinkBitcodeFile is non-empty,
52 /// the action will load it from the specified file.
53 void setLinkModule(llvm::Module *Mod) { LinkModule = Mod; }
55 /// takeModule - Take the generated LLVM module, for use after the action has
56 /// been run. The result may be null on failure.
57 llvm::Module *takeModule();
59 /// Take the LLVM context used by this action.
60 llvm::LLVMContext *takeLLVMContext();
62 BackendConsumer *BEConsumer;
65 class EmitAssemblyAction : public CodeGenAction {
66 virtual void anchor();
68 EmitAssemblyAction(llvm::LLVMContext *_VMContext = 0);
71 class EmitBCAction : public CodeGenAction {
72 virtual void anchor();
74 EmitBCAction(llvm::LLVMContext *_VMContext = 0);
77 class EmitLLVMAction : public CodeGenAction {
78 virtual void anchor();
80 EmitLLVMAction(llvm::LLVMContext *_VMContext = 0);
83 class EmitLLVMOnlyAction : public CodeGenAction {
84 virtual void anchor();
86 EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = 0);
89 class EmitCodeGenOnlyAction : public CodeGenAction {
90 virtual void anchor();
92 EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = 0);
95 class EmitObjAction : public CodeGenAction {
96 virtual void anchor();
98 EmitObjAction(llvm::LLVMContext *_VMContext = 0);