1 //===--- CodeGenAction.h - LLVM Code Generation Frontend Action -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_CODEGEN_CODEGENACTION_H
11 #define LLVM_CLANG_CODEGEN_CODEGENACTION_H
13 #include "clang/Frontend/FrontendAction.h"
22 class BackendConsumer;
24 class CodeGenAction : public ASTFrontendAction {
26 // Let BackendConsumer access LinkModule.
27 friend class BackendConsumer;
29 /// Info about module to link into a module we're generating.
31 /// The module to link in.
32 std::unique_ptr<llvm::Module> Module;
34 /// If true, we set attributes on Module's functions according to our
35 /// CodeGenOptions and LangOptions, as though we were generating the
36 /// function ourselves.
39 /// If true, we use LLVM module internalizer.
42 /// Bitwise combination of llvm::LinkerFlags used when we link the module.
47 std::unique_ptr<llvm::Module> TheModule;
49 /// Bitcode modules to link in to our module.
50 SmallVector<LinkModule, 4> LinkModules;
51 llvm::LLVMContext *VMContext;
54 std::unique_ptr<llvm::Module> loadModule(llvm::MemoryBufferRef MBRef);
57 /// Create a new code generation action. If the optional \p _VMContext
58 /// parameter is supplied, the action uses it without taking ownership,
59 /// otherwise it creates a fresh LLVM context and takes ownership.
60 CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = nullptr);
62 bool hasIRSupport() const override;
64 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
65 StringRef InFile) override;
67 void ExecuteAction() override;
69 void EndSourceFileAction() override;
72 ~CodeGenAction() override;
74 /// Take the generated LLVM module, for use after the action has been run.
75 /// The result may be null on failure.
76 std::unique_ptr<llvm::Module> takeModule();
78 /// Take the LLVM context used by this action.
79 llvm::LLVMContext *takeLLVMContext();
81 BackendConsumer *BEConsumer;
84 class EmitAssemblyAction : public CodeGenAction {
85 virtual void anchor();
87 EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
90 class EmitBCAction : public CodeGenAction {
91 virtual void anchor();
93 EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
96 class EmitLLVMAction : public CodeGenAction {
97 virtual void anchor();
99 EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
102 class EmitLLVMOnlyAction : public CodeGenAction {
103 virtual void anchor();
105 EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
108 class EmitCodeGenOnlyAction : public CodeGenAction {
109 virtual void anchor();
111 EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
114 class EmitObjAction : public CodeGenAction {
115 virtual void anchor();
117 EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);