clang  3.9.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  // Vector of {Linker::Flags, Module*} pairs to specify bitcode
29  // modules to link in using corresponding linker flags.
31  llvm::LLVMContext *VMContext;
32  bool OwnsVMContext;
33 
34 protected:
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);
39 
40  bool hasIRSupport() const override;
41 
42  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
43  StringRef InFile) override;
44 
45  void ExecuteAction() override;
46 
47  void EndSourceFileAction() override;
48 
49 public:
50  ~CodeGenAction() override;
51 
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));
57  }
58 
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();
62 
63  /// Take the LLVM context used by this action.
64  llvm::LLVMContext *takeLLVMContext();
65 
67 };
68 
70  virtual void anchor();
71 public:
72  EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
73 };
74 
75 class EmitBCAction : public CodeGenAction {
76  virtual void anchor();
77 public:
78  EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
79 };
80 
81 class EmitLLVMAction : public CodeGenAction {
82  virtual void anchor();
83 public:
84  EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
85 };
86 
88  virtual void anchor();
89 public:
90  EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
91 };
92 
94  virtual void anchor();
95 public:
96  EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
97 };
98 
99 class EmitObjAction : public CodeGenAction {
100  virtual void anchor();
101 public:
102  EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
103 };
104 
105 }
106 
107 #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:66
EmitLLVMAction(llvm::LLVMContext *_VMContext=nullptr)
CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext=nullptr)
Create a new code generation action.
EmitObjAction(llvm::LLVMContext *_VMContext=nullptr)
EmitBCAction(llvm::LLVMContext *_VMContext=nullptr)
EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext=nullptr)
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Abstract base class to use for AST consumer-based frontend actions.
EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext=nullptr)
std::unique_ptr< llvm::Module > takeModule()
Take the generated LLVM module, for use after the action has been run.
void addLinkModule(llvm::Module *Mod, unsigned LinkFlags)
setLinkModule - Set the link module to be used by this action.
Definition: CodeGenAction.h:55
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...