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//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_CODEGEN_CODE_GEN_ACTION_H
11#define LLVM_CLANG_CODEGEN_CODE_GEN_ACTION_H
12
13#include "clang/Frontend/FrontendAction.h"
14#include <memory>
15
16namespace llvm {
17  class LLVMContext;
18  class Module;
19}
20
21namespace clang {
22class BackendConsumer;
23
24class CodeGenAction : public ASTFrontendAction {
25private:
26  unsigned Act;
27  std::unique_ptr<llvm::Module> TheModule;
28  llvm::Module *LinkModule;
29  llvm::LLVMContext *VMContext;
30  bool OwnsVMContext;
31
32protected:
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);
37
38  bool hasIRSupport() const override;
39
40  ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
41                                 StringRef InFile) override;
42
43  void ExecuteAction() override;
44
45  void EndSourceFileAction() override;
46
47public:
48  ~CodeGenAction();
49
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; }
54
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();
58
59  /// Take the LLVM context used by this action.
60  llvm::LLVMContext *takeLLVMContext();
61
62  BackendConsumer *BEConsumer;
63};
64
65class EmitAssemblyAction : public CodeGenAction {
66  virtual void anchor();
67public:
68  EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
69};
70
71class EmitBCAction : public CodeGenAction {
72  virtual void anchor();
73public:
74  EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
75};
76
77class EmitLLVMAction : public CodeGenAction {
78  virtual void anchor();
79public:
80  EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
81};
82
83class EmitLLVMOnlyAction : public CodeGenAction {
84  virtual void anchor();
85public:
86  EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
87};
88
89class EmitCodeGenOnlyAction : public CodeGenAction {
90  virtual void anchor();
91public:
92  EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
93};
94
95class EmitObjAction : public CodeGenAction {
96  virtual void anchor();
97public:
98  EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
99};
100
101}
102
103#endif
104