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/Lower/EnvironmentDefault.h"
17#include "flang/Parser/characters.h"
18#include "flang/Parser/unparse.h"
19#include "flang/Support/Fortran-features.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/MemoryBuffer.h"
22#include <cstdint>
23#include <optional>
24#include <string>
25
26namespace Fortran::frontend {
27
28enum ActionKind {
30 InputOutputTest,
31
33 PrintPreprocessedInput,
34
36 ParseSyntaxOnly,
37
39 EmitFIR,
40
42 EmitHLFIR,
43
45 EmitLLVM,
46
48 EmitLLVMBitcode,
49
51 EmitObj,
52
54 EmitAssembly,
55
57 DebugUnparse,
58
61 DebugUnparseNoSema,
62
65 DebugUnparseWithSymbols,
66
69 DebugUnparseWithModules,
70
72 DebugDumpSymbols,
73
75 DebugDumpParseTree,
76
78 DebugDumpPFT,
79
81 DebugDumpAll,
82
84 DebugDumpParseTreeNoSema,
85
87 DebugDumpProvenance,
88
90 DebugDumpParsingLog,
91
94 DebugMeasureParseTree,
95
97 DebugPreFIRTree,
98
100 GetDefinition,
101
103 GetSymbolsSources,
104
106 InitOnly,
107
109 PluginAction
110};
111
114bool isFixedFormSuffix(llvm::StringRef suffix);
115
118bool isFreeFormSuffix(llvm::StringRef suffix);
119
122bool isToBePreprocessed(llvm::StringRef suffix);
123
126bool isCUDAFortranSuffix(llvm::StringRef suffix);
127
128enum class Language : uint8_t {
129 Unknown,
130
133 MLIR,
134
137 LLVM_IR,
138
140 Fortran,
142};
143
144// Source file layout
145enum class FortranForm {
147 Unknown,
148
150 FixedForm,
151
153 FreeForm
154};
155
157class InputKind {
158private:
159 Language lang;
160
161public:
163 enum Format { Source, ModuleMap, Precompiled };
164
165 constexpr InputKind(Language l = Language::Unknown) : lang(l) {}
166
167 Language getLanguage() const { return static_cast<Language>(lang); }
168
170 bool isUnknown() const { return lang == Language::Unknown; }
171};
172
176 std::string file;
177
181 const llvm::MemoryBuffer *buffer = nullptr;
182
184 InputKind kind;
185
189 bool isFixedForm = false;
190
195 unsigned mustBePreprocessed : 1;
196
198 bool isCUDAFortran{false};
199
200public:
201 FrontendInputFile() = default;
202 FrontendInputFile(llvm::StringRef file, InputKind inKind)
203 : file(file.str()), kind(inKind) {
204
205 // Based on the extension, decide whether this is a fixed or free form
206 // file.
207 auto pathDotIndex{file.rfind(".")};
208 std::string pathSuffix{file.substr(pathDotIndex + 1)};
209 isFixedForm = isFixedFormSuffix(pathSuffix);
210 mustBePreprocessed = isToBePreprocessed(pathSuffix);
211 isCUDAFortran = isCUDAFortranSuffix(pathSuffix);
212 }
213
214 FrontendInputFile(const llvm::MemoryBuffer *memBuf, InputKind inKind)
215 : buffer(memBuf), kind(inKind) {}
216
217 InputKind getKind() const { return kind; }
218
219 bool isEmpty() const { return file.empty() && buffer == nullptr; }
220 bool isFile() const { return (buffer == nullptr); }
221 bool getIsFixedForm() const { return isFixedForm; }
222 bool getMustBePreprocessed() const { return mustBePreprocessed; }
223 bool getIsCUDAFortran() const { return isCUDAFortran; }
224
225 llvm::StringRef getFile() const {
226 assert(isFile());
227 return file;
228 }
229
230 const llvm::MemoryBuffer *getBuffer() const {
231 assert(buffer && "Requested buffer, but it is empty!");
232 return buffer;
233 }
234};
235
237struct FrontendOptions {
238 FrontendOptions()
239 : showHelp(false), showVersion(false), instrumentedParse(false),
240 showColors(false), printSupportedCPUs(false),
241 needProvenanceRangeToCharBlockMappings(false) {}
242
244 unsigned showHelp : 1;
245
247 unsigned showVersion : 1;
248
250 unsigned instrumentedParse : 1;
251
253 unsigned showColors : 1;
254
256 unsigned printSupportedCPUs : 1;
257
261 unsigned needProvenanceRangeToCharBlockMappings : 1;
262
264 struct GetDefinitionVals {
265 unsigned line;
266 unsigned startColumn;
267 unsigned endColumn;
268 };
269 GetDefinitionVals getDefVals;
270
272 std::vector<FrontendInputFile> inputs;
273
275 std::string outputFile;
276
278 std::string dependencyOutputFile;
279
281 std::vector<std::string> dependencyTargets;
282
284 frontend::ActionKind programAction = ParseSyntaxOnly;
285
286 // The form to process files in, if specified.
287 FortranForm fortranForm = FortranForm::Unknown;
288
289 // Default values for environment variables to be set by the runtime.
290 std::vector<Fortran::lower::EnvironmentDefault> envDefaults;
291
292 // The column after which characters are ignored in fixed form lines in the
293 // source file. std::nullopt means there is no limit
294 // (-ffixed-line-length=none or -ffixed-line-length=0).
295 std::optional<int> fixedFormColumns = 72;
296
299 InputKind dashX;
300
301 // Language features
302 common::LanguageFeatureControl features;
303
304 // Source file encoding
305 Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8};
306
308 std::vector<std::string> plugins;
309
311 std::string actionName;
312
315 std::vector<std::string> llvmArgs;
316
319 std::vector<std::string> mlirArgs;
320
321 // Return the appropriate input kind for a file extension. For example,
326 static InputKind getInputKindForExtension(llvm::StringRef extension);
327};
328} // namespace Fortran::frontend
329
330#endif // FORTRAN_FRONTEND_FRONTENDOPTIONS_H
An input file for the front end.
Definition FrontendOptions.h:174
The kind of a file that we've been handed as an input.
Definition FrontendOptions.h:157
Format
The input file format.
Definition FrontendOptions.h:163
bool isUnknown() const
Is the input kind fully-unknown?
Definition FrontendOptions.h:170