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 // Vector of {Linker::Flags, Module*} pairs to specify bitcode
29 // modules to link in using corresponding linker flags.
30 SmallVector<std::pair<unsigned, llvm::Module *>, 4> LinkModules;
31 llvm::LLVMContext *VMContext;
35 /// Create a new code generation action. If the optional \p _VMContext
36 /// parameter is supplied, the action uses it without taking ownership,
37 /// otherwise it creates a fresh LLVM context and takes ownership.
38 CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = nullptr);
40 bool hasIRSupport() const override;
42 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
43 StringRef InFile) override;
45 void ExecuteAction() override;
47 void EndSourceFileAction() override;
50 ~CodeGenAction() override;
52 /// setLinkModule - Set the link module to be used by this action. If a link
53 /// module is not provided, and CodeGenOptions::LinkBitcodeFile is non-empty,
54 /// the action will load it from the specified file.
55 void addLinkModule(llvm::Module *Mod, unsigned LinkFlags) {
56 LinkModules.push_back(std::make_pair(LinkFlags, Mod));
59 /// Take the generated LLVM module, for use after the action has been run.
60 /// The result may be null on failure.
61 std::unique_ptr<llvm::Module> takeModule();
63 /// Take the LLVM context used by this action.
64 llvm::LLVMContext *takeLLVMContext();
66 BackendConsumer *BEConsumer;
69 class EmitAssemblyAction : public CodeGenAction {
70 virtual void anchor();
72 EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
75 class EmitBCAction : public CodeGenAction {
76 virtual void anchor();
78 EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
81 class EmitLLVMAction : public CodeGenAction {
82 virtual void anchor();
84 EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
87 class EmitLLVMOnlyAction : public CodeGenAction {
88 virtual void anchor();
90 EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
93 class EmitCodeGenOnlyAction : public CodeGenAction {
94 virtual void anchor();
96 EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
99 class EmitObjAction : public CodeGenAction {
100 virtual void anchor();
102 EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);