clang 20.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
13#include <memory>
14
15namespace llvm {
16 class LLVMContext;
17 class Module;
18}
19
20namespace clang {
21class BackendConsumer;
22class CodeGenerator;
23
25private:
26 // Let BackendConsumer access LinkModule.
27 friend class BackendConsumer;
28
29 /// Info about module to link into a module we're generating.
30 struct LinkModule {
31 /// The module to link in.
32 std::unique_ptr<llvm::Module> Module;
33
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.
37 bool PropagateAttrs;
38
39 /// If true, we use LLVM module internalizer.
40 bool Internalize;
41
42 /// Bitwise combination of llvm::LinkerFlags used when we link the module.
43 unsigned LinkFlags;
44 };
45
46 unsigned Act;
47 std::unique_ptr<llvm::Module> TheModule;
48
49 /// Bitcode modules to link in to our module.
51 llvm::LLVMContext *VMContext;
52 bool OwnsVMContext;
53
54 std::unique_ptr<llvm::Module> loadModule(llvm::MemoryBufferRef MBRef);
55
56 /// Load bitcode modules to link into our module from the options.
57 bool loadLinkModules(CompilerInstance &CI);
58
59protected:
60 bool BeginSourceFileAction(CompilerInstance &CI) override;
61
62 /// Create a new code generation action. If the optional \p _VMContext
63 /// parameter is supplied, the action uses it without taking ownership,
64 /// otherwise it creates a fresh LLVM context and takes ownership.
65 CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = nullptr);
66
67 bool hasIRSupport() const override;
68
69 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
70 StringRef InFile) override;
71
72 void ExecuteAction() override;
73
74 void EndSourceFileAction() override;
75
76public:
77 ~CodeGenAction() override;
78
79 /// Take the generated LLVM module, for use after the action has been run.
80 /// The result may be null on failure.
81 std::unique_ptr<llvm::Module> takeModule();
82
83 /// Take the LLVM context used by this action.
84 llvm::LLVMContext *takeLLVMContext();
85
87
89};
90
92 virtual void anchor();
93public:
94 EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
95};
96
98 virtual void anchor();
99public:
100 EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
101};
102
104 virtual void anchor();
105public:
106 EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
107};
108
110 virtual void anchor();
111public:
112 EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
113};
114
116 virtual void anchor();
117public:
118 EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
119};
120
122 virtual void anchor();
123public:
124 EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
125};
126
127}
128
129#endif
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
Abstract base class to use for AST consumer-based frontend actions.
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.
llvm::LLVMContext * takeLLVMContext()
Take the LLVM context used by this action.
BackendConsumer * BEConsumer
Definition: CodeGenAction.h:88
bool hasIRSupport() const override
Does this action support use with IR files?
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
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.
Definition: ModuleBuilder.h:52
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Describes a module or submodule.
Definition: Module.h:105
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...
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30