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_CODEGENACTION_H
11 #define LLVM_CLANG_CODEGEN_CODEGENACTION_H
13 #include "clang/Frontend/FrontendAction.h"
22 class BackendConsumer;
24 class CodeGenAction : public ASTFrontendAction {
27 std::unique_ptr<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 = nullptr);
38 bool hasIRSupport() const override;
40 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
41 StringRef InFile) override;
43 void ExecuteAction() override;
45 void EndSourceFileAction() override;
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 /// Take the generated LLVM module, for use after the action has been run.
56 /// The result may be null on failure.
57 std::unique_ptr<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 = nullptr);
71 class EmitBCAction : public CodeGenAction {
72 virtual void anchor();
74 EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
77 class EmitLLVMAction : public CodeGenAction {
78 virtual void anchor();
80 EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
83 class EmitLLVMOnlyAction : public CodeGenAction {
84 virtual void anchor();
86 EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
89 class EmitCodeGenOnlyAction : public CodeGenAction {
90 virtual void anchor();
92 EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
95 class EmitObjAction : public CodeGenAction {
96 virtual void anchor();
98 EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);