FLANG
FrontendActions.h
1//===- FrontendActions.h -----------------------------------------*- 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// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef FORTRAN_FRONTEND_FRONTENDACTIONS_H
14#define FORTRAN_FRONTEND_FRONTENDACTIONS_H
15
17#include "flang/Frontend/ParserActions.h"
18
19#include "mlir/IR/BuiltinOps.h"
20#include "mlir/IR/OwningOpRef.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/IR/Module.h"
23#include <memory>
24
25namespace Fortran::frontend {
26
27//===----------------------------------------------------------------------===//
28// Custom Consumer Actions
29//===----------------------------------------------------------------------===//
30
31class InputOutputTestAction : public FrontendAction {
32 void executeAction() override;
33};
34
35class InitOnlyAction : public FrontendAction {
36 void executeAction() override;
37};
38
39//===----------------------------------------------------------------------===//
40// Prescan Actions
41//===----------------------------------------------------------------------===//
42class PrescanAction : public FrontendAction {
43 void executeAction() override = 0;
44 bool beginSourceFileAction() override;
45};
46
48 void executeAction() override;
49};
50
52 void executeAction() override;
53};
54
56 void executeAction() override;
57};
58
60 void executeAction() override;
61};
62
63//===----------------------------------------------------------------------===//
64// PrescanAndParse Actions
65//===----------------------------------------------------------------------===//
66class PrescanAndParseAction : public FrontendAction {
67 void executeAction() override = 0;
68 bool beginSourceFileAction() override;
69};
70
72 void executeAction() override;
73};
74
76 void executeAction() override;
77};
78
79//===----------------------------------------------------------------------===//
80// PrescanAndSema Actions
81//
82// These actions will parse the input, run the semantic checks and execute
83// their actions provided that no parsing or semantic errors were found.
84//===----------------------------------------------------------------------===//
85class PrescanAndSemaAction : public FrontendAction {
86
87 void executeAction() override = 0;
88 bool beginSourceFileAction() override;
89};
90
92 void executeAction() override;
93};
94
96 void executeAction() override;
97};
98
100 void executeAction() override;
101};
102
104 void executeAction() override;
105};
106
108 void executeAction() override;
109};
110
112 void executeAction() override;
113};
114
116 void executeAction() override;
117};
118
120 void executeAction() override;
121};
122
124 void executeAction() override;
125};
126
128 void executeAction() override;
129};
130
132 void executeAction() override = 0;
133
134public:
135 Fortran::parser::Parsing &getParsing();
142 std::unique_ptr<llvm::raw_pwrite_stream>
143 createOutputFile(llvm::StringRef extension);
144};
145
146//===----------------------------------------------------------------------===//
147// PrescanAndSemaDebug Actions
148//
149// These actions will parse the input, run the semantic checks and execute
150// their actions _regardless of_ whether any semantic errors have been found.
151// This can be useful when adding new languge feature and when you wish to
152// investigate compiler output (e.g. the parse tree) despite any semantic
153// errors.
154//
155// NOTE: Use with care and for development only!
156//===----------------------------------------------------------------------===//
157class PrescanAndSemaDebugAction : public FrontendAction {
158
159 void executeAction() override = 0;
160 bool beginSourceFileAction() override;
161};
162
164 void executeAction() override;
165};
166
167//===----------------------------------------------------------------------===//
168// CodeGen Actions
169//===----------------------------------------------------------------------===//
176enum class BackendActionTy {
177 Backend_EmitAssembly,
178 Backend_EmitObj,
179 Backend_EmitBC,
180 Backend_EmitLL,
181 Backend_EmitFIR,
182 Backend_EmitHLFIR,
183};
184
189class CodeGenAction : public FrontendAction {
190
191 void executeAction() override;
193 bool beginSourceFileAction() override;
196 void runOptimizationPipeline(llvm::raw_pwrite_stream &os);
197
198protected:
199 CodeGenAction(BackendActionTy act) : action{act} {};
202 std::unique_ptr<mlir::MLIRContext> mlirCtx;
203 mlir::OwningOpRef<mlir::ModuleOp> mlirModule;
205
207 std::unique_ptr<llvm::LLVMContext> llvmCtx;
208 std::unique_ptr<llvm::Module> llvmModule;
209
211 void embedOffloadObjects();
212
214 void linkBuiltinBCLibs();
215
217 void lowerHLFIRToFIR();
218
221 void generateLLVMIR();
222
223 BackendActionTy action;
224
226public:
227 ~CodeGenAction() override;
228};
229
230class EmitFIRAction : public CodeGenAction {
231public:
232 EmitFIRAction() : CodeGenAction(BackendActionTy::Backend_EmitFIR) {}
233};
234
235class EmitHLFIRAction : public CodeGenAction {
236public:
237 EmitHLFIRAction() : CodeGenAction(BackendActionTy::Backend_EmitHLFIR) {}
238};
239
240class EmitLLVMAction : public CodeGenAction {
241public:
242 EmitLLVMAction() : CodeGenAction(BackendActionTy::Backend_EmitLL) {}
243};
244
245class EmitLLVMBitcodeAction : public CodeGenAction {
246public:
247 EmitLLVMBitcodeAction() : CodeGenAction(BackendActionTy::Backend_EmitBC) {}
248};
249
250class EmitObjAction : public CodeGenAction {
251public:
252 EmitObjAction() : CodeGenAction(BackendActionTy::Backend_EmitObj) {}
253};
254
255class EmitAssemblyAction : public CodeGenAction {
256public:
257 EmitAssemblyAction() : CodeGenAction(BackendActionTy::Backend_EmitAssembly) {}
258};
259
260} // namespace Fortran::frontend
261
262#endif // FORTRAN_FRONTEND_FRONTENDACTIONS_H
void generateLLVMIR()
Definition FrontendActions.cpp:715
void lowerHLFIRToFIR()
Runs pass pipeline to lower HLFIR into FIR.
Definition FrontendActions.cpp:604
void embedOffloadObjects()
Embeds offload objects specified with -fembed-offload-object.
Definition FrontendActions.cpp:1171
void linkBuiltinBCLibs()
Links in BC libraries spefified with -mlink-builtin-bitcode.
Definition FrontendActions.cpp:1190
Definition FrontendActions.h:163
Definition FrontendActions.h:111
Definition FrontendActions.h:107
Definition FrontendActions.h:55
Definition FrontendActions.h:51
Definition FrontendActions.h:103
Definition FrontendActions.h:59
Definition FrontendActions.h:115
Definition FrontendActions.h:99
Definition FrontendActions.h:71
virtual bool beginSourceFileAction()
Definition FrontendAction.h:50
Definition FrontendActions.h:119
Definition FrontendActions.h:123
Definition FrontendActions.h:35
Definition FrontendActions.h:31
Definition FrontendActions.h:127
Definition FrontendActions.h:131
std::unique_ptr< llvm::raw_pwrite_stream > createOutputFile(llvm::StringRef extension)
Definition FrontendActions.cpp:1420
Definition FrontendActions.h:42
Definition FrontendActions.h:66
Definition FrontendActions.h:85
Definition FrontendActions.h:157
Definition FrontendActions.h:47
Definition parsing.h:24