clang 23.0.0git
CodeGenAction.h
Go to the documentation of this file.
1//===--- CodeGenAction.h - LLVM Code Generation Frontend Action -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_CODEGEN_CODEGENACTION_H
10#define LLVM_CLANG_CODEGEN_CODEGENACTION_H
11
14#include <memory>
15
16namespace llvm {
17 class LLVMContext;
18 class Module;
19}
20
21namespace clang {
22class BackendConsumer;
23class CodeGenerator;
24
26private:
27 unsigned Act;
28 std::unique_ptr<llvm::Module> TheModule;
29
30 /// Bitcode modules to link in to our module.
32 llvm::LLVMContext *VMContext;
33 bool OwnsVMContext;
34
35 std::unique_ptr<llvm::Module> loadModule(llvm::MemoryBufferRef MBRef);
36
37protected:
38 bool BeginSourceFileAction(CompilerInstance &CI) override;
39
40 /// Create a new code generation action. If the optional \p _VMContext
41 /// parameter is supplied, the action uses it without taking ownership,
42 /// otherwise it creates a fresh LLVM context and takes ownership.
43 CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = nullptr);
44
45 bool hasIRSupport() const override;
46
47 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
48 StringRef InFile) override;
49
50 void ExecuteAction() override;
51
52 void EndSourceFileAction() override;
53
54public:
55 ~CodeGenAction() override;
56
57 /// Take the generated LLVM module, for use after the action has been run.
58 /// The result may be null on failure.
59 std::unique_ptr<llvm::Module> takeModule();
60
61 /// Take the LLVM context used by this action.
62 llvm::LLVMContext *takeLLVMContext();
63
65
67};
68
70 virtual void anchor();
71public:
72 EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
73};
74
76 virtual void anchor();
77public:
78 EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
79};
80
82 virtual void anchor();
83public:
84 EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
85};
86
88 virtual void anchor();
89public:
90 EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
91};
92
94 virtual void anchor();
95public:
96 EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
97};
98
100 virtual void anchor();
101public:
102 EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
103};
104
105}
106
107#endif
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
CodeGenerator * getCodeGenerator() const
void EndSourceFileAction() override
Callback at the end of processing a single input.
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext=nullptr)
Create a new code generation action.
llvm::LLVMContext * takeLLVMContext()
Take the LLVM context used by this action.
BackendConsumer * BEConsumer
bool hasIRSupport() const override
Does this action support use with IR files?
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer.
std::unique_ptr< llvm::Module > takeModule()
Take the generated LLVM module, for use after the action has been run.
The primary public interface to the Clang code generator.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
EmitAssemblyAction(llvm::LLVMContext *_VMContext=nullptr)
EmitBCAction(llvm::LLVMContext *_VMContext=nullptr)
EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext=nullptr)
EmitLLVMAction(llvm::LLVMContext *_VMContext=nullptr)
EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext=nullptr)
EmitObjAction(llvm::LLVMContext *_VMContext=nullptr)
The JSON file list parser is used to communicate input to InstallAPI.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30