FLANG
FrontendOptions.h
1//===- FrontendOptions.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_FRONTENDOPTIONS_H
14#define FORTRAN_FRONTEND_FRONTENDOPTIONS_H
15
16#include "flang/Common/Fortran-features.h"
17#include "flang/Lower/EnvironmentDefault.h"
18#include "flang/Parser/characters.h"
19#include "flang/Parser/unparse.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/MemoryBuffer.h"
22#include <cstdint>
23#include <string>
24
25namespace Fortran::frontend {
26
27enum ActionKind {
29 InputOutputTest,
30
32 PrintPreprocessedInput,
33
35 ParseSyntaxOnly,
36
38 EmitFIR,
39
41 EmitHLFIR,
42
44 EmitLLVM,
45
47 EmitLLVMBitcode,
48
50 EmitObj,
51
53 EmitAssembly,
54
56 DebugUnparse,
57
60 DebugUnparseNoSema,
61
64 DebugUnparseWithSymbols,
65
68 DebugUnparseWithModules,
69
71 DebugDumpSymbols,
72
74 DebugDumpParseTree,
75
77 DebugDumpPFT,
78
80 DebugDumpAll,
81
83 DebugDumpParseTreeNoSema,
84
86 DebugDumpProvenance,
87
89 DebugDumpParsingLog,
90
93 DebugMeasureParseTree,
94
96 DebugPreFIRTree,
97
99 GetDefinition,
100
102 GetSymbolsSources,
103
105 InitOnly,
106
108 PluginAction
109};
110
113bool isFixedFormSuffix(llvm::StringRef suffix);
114
117bool isFreeFormSuffix(llvm::StringRef suffix);
118
121bool isToBePreprocessed(llvm::StringRef suffix);
122
125bool isCUDAFortranSuffix(llvm::StringRef suffix);
126
127enum class Language : uint8_t {
128 Unknown,
129
132 MLIR,
133
136 LLVM_IR,
137
139 Fortran,
141};
142
143// Source file layout
144enum class FortranForm {
146 Unknown,
147
149 FixedForm,
150
152 FreeForm
153};
154
157private:
158 Language lang;
159
160public:
162 enum Format { Source, ModuleMap, Precompiled };
163
164 constexpr InputKind(Language l = Language::Unknown) : lang(l) {}
165
166 Language getLanguage() const { return static_cast<Language>(lang); }
167
169 bool isUnknown() const { return lang == Language::Unknown; }
170};
171
175 std::string file;
176
180 const llvm::MemoryBuffer *buffer = nullptr;
181
183 InputKind kind;
184
188 bool isFixedForm = false;
189
194 unsigned mustBePreprocessed : 1;
195
197 bool isCUDAFortran{false};
198
199public:
200 FrontendInputFile() = default;
201 FrontendInputFile(llvm::StringRef file, InputKind inKind)
202 : file(file.str()), kind(inKind) {
203
204 // Based on the extension, decide whether this is a fixed or free form
205 // file.
206 auto pathDotIndex{file.rfind(".")};
207 std::string pathSuffix{file.substr(pathDotIndex + 1)};
208 isFixedForm = isFixedFormSuffix(pathSuffix);
209 mustBePreprocessed = isToBePreprocessed(pathSuffix);
210 isCUDAFortran = isCUDAFortranSuffix(pathSuffix);
211 }
212
213 FrontendInputFile(const llvm::MemoryBuffer *memBuf, InputKind inKind)
214 : buffer(memBuf), kind(inKind) {}
215
216 InputKind getKind() const { return kind; }
217
218 bool isEmpty() const { return file.empty() && buffer == nullptr; }
219 bool isFile() const { return (buffer == nullptr); }
220 bool getIsFixedForm() const { return isFixedForm; }
221 bool getMustBePreprocessed() const { return mustBePreprocessed; }
222 bool getIsCUDAFortran() const { return isCUDAFortran; }
223
224 llvm::StringRef getFile() const {
225 assert(isFile());
226 return file;
227 }
228
229 const llvm::MemoryBuffer *getBuffer() const {
230 assert(buffer && "Requested buffer, but it is empty!");
231 return buffer;
232 }
233};
234
238 : showHelp(false), showVersion(false), instrumentedParse(false),
239 showColors(false), printSupportedCPUs(false),
241
243 unsigned showHelp : 1;
244
246 unsigned showVersion : 1;
247
249 unsigned instrumentedParse : 1;
250
252 unsigned showColors : 1;
253
255 unsigned printSupportedCPUs : 1;
256
261
264 unsigned line;
265 unsigned startColumn;
266 unsigned endColumn;
267 };
268 GetDefinitionVals getDefVals;
269
271 std::vector<FrontendInputFile> inputs;
272
274 std::string outputFile;
275
277 frontend::ActionKind programAction = ParseSyntaxOnly;
278
279 // The form to process files in, if specified.
280 FortranForm fortranForm = FortranForm::Unknown;
281
282 // Default values for environment variables to be set by the runtime.
283 std::vector<Fortran::lower::EnvironmentDefault> envDefaults;
284
285 // The column after which characters are ignored in fixed form lines in the
286 // source file.
287 int fixedFormColumns = 72;
288
292
293 // Language features
295
296 // Source file encoding
297 Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8};
298
300 std::vector<std::string> plugins;
301
303 std::string actionName;
304
307 std::vector<std::string> llvmArgs;
308
311 std::vector<std::string> mlirArgs;
312
313 // Return the appropriate input kind for a file extension. For example,
318 static InputKind getInputKindForExtension(llvm::StringRef extension);
319};
320} // namespace Fortran::frontend
321
322#endif // FORTRAN_FRONTEND_FRONTENDOPTIONS_H
Definition: Fortran-features.h:84
An input file for the front end.
Definition: FrontendOptions.h:173
The kind of a file that we've been handed as an input.
Definition: FrontendOptions.h:156
Format
The input file format.
Definition: FrontendOptions.h:162
bool isUnknown() const
Is the input kind fully-unknown?
Definition: FrontendOptions.h:169
Definition: bit-population-count.h:20
Input values from -fget-definition
Definition: FrontendOptions.h:263
FrontendOptions - Options for controlling the behavior of the frontend.
Definition: FrontendOptions.h:236
unsigned needProvenanceRangeToCharBlockMappings
Definition: FrontendOptions.h:260
InputKind dashX
Definition: FrontendOptions.h:291
unsigned showHelp
Show the -help text.
Definition: FrontendOptions.h:243
unsigned instrumentedParse
Instrument the parse to get a more verbose log.
Definition: FrontendOptions.h:249
std::vector< std::string > mlirArgs
Definition: FrontendOptions.h:311
std::vector< std::string > llvmArgs
Definition: FrontendOptions.h:307
unsigned showColors
Enable color diagnostics.
Definition: FrontendOptions.h:252
std::string outputFile
The output file, if any.
Definition: FrontendOptions.h:274
std::vector< std::string > plugins
The list of plugins to load.
Definition: FrontendOptions.h:300
std::string actionName
The name of the action to run when using a plugin action.
Definition: FrontendOptions.h:303
std::vector< FrontendInputFile > inputs
The input files and their types.
Definition: FrontendOptions.h:271
unsigned printSupportedCPUs
Print the supported cpus for the current target.
Definition: FrontendOptions.h:255
frontend::ActionKind programAction
The frontend action to perform.
Definition: FrontendOptions.h:277
unsigned showVersion
Show the -version text.
Definition: FrontendOptions.h:246
static InputKind getInputKindForExtension(llvm::StringRef extension)
Definition: FrontendOptions.cpp:44