clang  3.7.0
CodeGenAction.h
Go to the documentation of this file.
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_CODEGENACTION_H
11 #define LLVM_CLANG_CODEGEN_CODEGENACTION_H
12 
14 #include <memory>
15 
16 namespace llvm {
17  class LLVMContext;
18  class Module;
19 }
20 
21 namespace clang {
22 class BackendConsumer;
23 
25 private:
26  unsigned Act;
27  std::unique_ptr<llvm::Module> TheModule;
28  llvm::Module *LinkModule;
29  llvm::LLVMContext *VMContext;
30  bool OwnsVMContext;
31 
32 protected:
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  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
41  StringRef InFile) override;
42 
43  void ExecuteAction() override;
44 
45  void EndSourceFileAction() override;
46 
47 public:
48  ~CodeGenAction() override;
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  /// 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();
58 
59  /// Take the LLVM context used by this action.
60  llvm::LLVMContext *takeLLVMContext();
61 
63 };
64 
66  virtual void anchor();
67 public:
68  EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
69 };
70 
71 class EmitBCAction : public CodeGenAction {
72  virtual void anchor();
73 public:
74  EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
75 };
76 
77 class EmitLLVMAction : public CodeGenAction {
78  virtual void anchor();
79 public:
80  EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
81 };
82 
84  virtual void anchor();
85 public:
86  EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
87 };
88 
90  virtual void anchor();
91 public:
92  EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
93 };
94 
95 class EmitObjAction : public CodeGenAction {
96  virtual void anchor();
97 public:
98  EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
99 };
100 
101 }
102 
103 #endif
bool hasIRSupport() const override
Does this action support use with IR files?
void EndSourceFileAction() override
Callback at the end of processing a single input.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
BackendConsumer * BEConsumer
Definition: CodeGenAction.h:62
EmitLLVMAction(llvm::LLVMContext *_VMContext=nullptr)
CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext=nullptr)
EmitObjAction(llvm::LLVMContext *_VMContext=nullptr)
EmitBCAction(llvm::LLVMContext *_VMContext=nullptr)
EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext=nullptr)
Abstract base class to use for AST consumer-based frontend actions.
EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext=nullptr)
std::unique_ptr< llvm::Module > takeModule()
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
EmitAssemblyAction(llvm::LLVMContext *_VMContext=nullptr)
llvm::LLVMContext * takeLLVMContext()
Take the LLVM context used by this action.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
void setLinkModule(llvm::Module *Mod)
Definition: CodeGenAction.h:53