clang API Documentation

CodeGenAction.h
Go to the documentation of this file.
00001 //===--- CodeGenAction.h - LLVM Code Generation Frontend Action -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_CODEGEN_CODEGENACTION_H
00011 #define LLVM_CLANG_CODEGEN_CODEGENACTION_H
00012 
00013 #include "clang/Frontend/FrontendAction.h"
00014 #include <memory>
00015 
00016 namespace llvm {
00017   class LLVMContext;
00018   class Module;
00019 }
00020 
00021 namespace clang {
00022 class BackendConsumer;
00023 
00024 class CodeGenAction : public ASTFrontendAction {
00025 private:
00026   unsigned Act;
00027   std::unique_ptr<llvm::Module> TheModule;
00028   llvm::Module *LinkModule;
00029   llvm::LLVMContext *VMContext;
00030   bool OwnsVMContext;
00031 
00032 protected:
00033   /// Create a new code generation action.  If the optional \p _VMContext
00034   /// parameter is supplied, the action uses it without taking ownership,
00035   /// otherwise it creates a fresh LLVM context and takes ownership.
00036   CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = nullptr);
00037 
00038   bool hasIRSupport() const override;
00039 
00040   std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
00041                                                  StringRef InFile) override;
00042 
00043   void ExecuteAction() override;
00044 
00045   void EndSourceFileAction() override;
00046 
00047 public:
00048   ~CodeGenAction();
00049 
00050   /// setLinkModule - Set the link module to be used by this action.  If a link
00051   /// module is not provided, and CodeGenOptions::LinkBitcodeFile is non-empty,
00052   /// the action will load it from the specified file.
00053   void setLinkModule(llvm::Module *Mod) { LinkModule = Mod; }
00054 
00055   /// Take the generated LLVM module, for use after the action has been run.
00056   /// The result may be null on failure.
00057   std::unique_ptr<llvm::Module> takeModule();
00058 
00059   /// Take the LLVM context used by this action.
00060   llvm::LLVMContext *takeLLVMContext();
00061 
00062   BackendConsumer *BEConsumer;
00063 };
00064 
00065 class EmitAssemblyAction : public CodeGenAction {
00066   virtual void anchor();
00067 public:
00068   EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
00069 };
00070 
00071 class EmitBCAction : public CodeGenAction {
00072   virtual void anchor();
00073 public:
00074   EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
00075 };
00076 
00077 class EmitLLVMAction : public CodeGenAction {
00078   virtual void anchor();
00079 public:
00080   EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
00081 };
00082 
00083 class EmitLLVMOnlyAction : public CodeGenAction {
00084   virtual void anchor();
00085 public:
00086   EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
00087 };
00088 
00089 class EmitCodeGenOnlyAction : public CodeGenAction {
00090   virtual void anchor();
00091 public:
00092   EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
00093 };
00094 
00095 class EmitObjAction : public CodeGenAction {
00096   virtual void anchor();
00097 public:
00098   EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
00099 };
00100 
00101 }
00102 
00103 #endif