blob: f8fd56152f23b0b85f73b985a52b70f55d826fd4 [file] [log] [blame]
Daniel Dunbar4ee34612010-02-25 04:37:45 +00001//===--- 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
Stephen Hines176edba2014-12-01 14:53:08 -080010#ifndef LLVM_CLANG_CODEGEN_CODEGENACTION_H
11#define LLVM_CLANG_CODEGEN_CODEGENACTION_H
Daniel Dunbar9b414d32010-06-15 17:48:49 +000012
Daniel Dunbar4ee34612010-02-25 04:37:45 +000013#include "clang/Frontend/FrontendAction.h"
Stephen Hines651f13c2014-04-23 16:59:28 -070014#include <memory>
Daniel Dunbarb954e982010-02-25 04:37:50 +000015
16namespace llvm {
Peter Collingbourne4b93d662011-02-19 23:03:58 +000017 class LLVMContext;
Daniel Dunbarb954e982010-02-25 04:37:50 +000018 class Module;
19}
Daniel Dunbar4ee34612010-02-25 04:37:45 +000020
21namespace clang {
Nico Weber5aa74af2011-01-25 20:34:14 +000022class BackendConsumer;
Daniel Dunbar4ee34612010-02-25 04:37:45 +000023
24class CodeGenAction : public ASTFrontendAction {
25private:
26 unsigned Act;
Stephen Hines651f13c2014-04-23 16:59:28 -070027 std::unique_ptr<llvm::Module> TheModule;
Peter Collingbourne22a7dfe2011-10-30 17:30:44 +000028 llvm::Module *LinkModule;
Peter Collingbourne4b93d662011-02-19 23:03:58 +000029 llvm::LLVMContext *VMContext;
30 bool OwnsVMContext;
Daniel Dunbar4ee34612010-02-25 04:37:45 +000031
32protected:
Dmitri Gribenko1824d542012-09-13 13:11:20 +000033 /// Create a new code generation action. If the optional \p _VMContext
Peter Collingbourne4b93d662011-02-19 23:03:58 +000034 /// parameter is supplied, the action uses it without taking ownership,
35 /// otherwise it creates a fresh LLVM context and takes ownership.
Stephen Hines6bcf27b2014-05-29 04:14:42 -070036 CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = nullptr);
Daniel Dunbar4ee34612010-02-25 04:37:45 +000037
Stephen Hines651f13c2014-04-23 16:59:28 -070038 bool hasIRSupport() const override;
Daniel Dunbar4cbbd942010-06-07 23:27:59 +000039
Stephen Hines176edba2014-12-01 14:53:08 -080040 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
41 StringRef InFile) override;
Daniel Dunbarb954e982010-02-25 04:37:50 +000042
Stephen Hines651f13c2014-04-23 16:59:28 -070043 void ExecuteAction() override;
Daniel Dunbar4cbbd942010-06-07 23:27:59 +000044
Stephen Hines651f13c2014-04-23 16:59:28 -070045 void EndSourceFileAction() override;
Daniel Dunbarb954e982010-02-25 04:37:50 +000046
47public:
Chandler Carruthf84df9f2010-02-26 08:51:12 +000048 ~CodeGenAction();
49
Peter Collingbourne22a7dfe2011-10-30 17:30:44 +000050 /// 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
Stephen Hines176edba2014-12-01 14:53:08 -080055 /// 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();
Nico Weber5aa74af2011-01-25 20:34:14 +000058
Peter Collingbourne4b93d662011-02-19 23:03:58 +000059 /// Take the LLVM context used by this action.
60 llvm::LLVMContext *takeLLVMContext();
61
Nico Weber5aa74af2011-01-25 20:34:14 +000062 BackendConsumer *BEConsumer;
Daniel Dunbar4ee34612010-02-25 04:37:45 +000063};
64
65class EmitAssemblyAction : public CodeGenAction {
David Blaikie99ba9e32011-12-20 02:48:34 +000066 virtual void anchor();
Daniel Dunbar4ee34612010-02-25 04:37:45 +000067public:
Stephen Hines6bcf27b2014-05-29 04:14:42 -070068 EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
Daniel Dunbar4ee34612010-02-25 04:37:45 +000069};
70
71class EmitBCAction : public CodeGenAction {
David Blaikie99ba9e32011-12-20 02:48:34 +000072 virtual void anchor();
Daniel Dunbar4ee34612010-02-25 04:37:45 +000073public:
Stephen Hines6bcf27b2014-05-29 04:14:42 -070074 EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
Daniel Dunbar4ee34612010-02-25 04:37:45 +000075};
76
77class EmitLLVMAction : public CodeGenAction {
David Blaikie99ba9e32011-12-20 02:48:34 +000078 virtual void anchor();
Daniel Dunbar4ee34612010-02-25 04:37:45 +000079public:
Stephen Hines6bcf27b2014-05-29 04:14:42 -070080 EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
Daniel Dunbar4ee34612010-02-25 04:37:45 +000081};
82
83class EmitLLVMOnlyAction : public CodeGenAction {
David Blaikie99ba9e32011-12-20 02:48:34 +000084 virtual void anchor();
Daniel Dunbar4ee34612010-02-25 04:37:45 +000085public:
Stephen Hines6bcf27b2014-05-29 04:14:42 -070086 EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
Daniel Dunbar4ee34612010-02-25 04:37:45 +000087};
88
Daniel Dunbar32148ce2010-05-25 18:41:01 +000089class EmitCodeGenOnlyAction : public CodeGenAction {
David Blaikie99ba9e32011-12-20 02:48:34 +000090 virtual void anchor();
Daniel Dunbar32148ce2010-05-25 18:41:01 +000091public:
Stephen Hines6bcf27b2014-05-29 04:14:42 -070092 EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
Daniel Dunbar32148ce2010-05-25 18:41:01 +000093};
94
Daniel Dunbar4ee34612010-02-25 04:37:45 +000095class EmitObjAction : public CodeGenAction {
David Blaikie99ba9e32011-12-20 02:48:34 +000096 virtual void anchor();
Daniel Dunbar4ee34612010-02-25 04:37:45 +000097public:
Stephen Hines6bcf27b2014-05-29 04:14:42 -070098 EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
Daniel Dunbar4ee34612010-02-25 04:37:45 +000099};
100
101}
Daniel Dunbar9b414d32010-06-15 17:48:49 +0000102
103#endif