FLANG
CompilerInvocation.h
1//===- CompilerInvocation.h - Compiler Invocation Helper Data ---*- 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_COMPILERINVOCATION_H
14#define FORTRAN_FRONTEND_COMPILERINVOCATION_H
15
16#include "flang/Frontend/CodeGenOptions.h"
17#include "flang/Frontend/FrontendOptions.h"
21#include "flang/Parser/options.h"
22#include "flang/Semantics/semantics.h"
23#include "flang/Support/LangOptions.h"
24#include "mlir/Support/Timing.h"
25#include "clang/Basic/Diagnostic.h"
26#include "clang/Basic/DiagnosticOptions.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/Option/ArgList.h"
29#include <memory>
30
31namespace Fortran::frontend {
32
37bool parseDiagnosticArgs(clang::DiagnosticOptions &opts,
38 llvm::opt::ArgList &args);
39
40class CompilerInvocationBase {
41public:
43 std::shared_ptr<clang::DiagnosticOptions> diagnosticOpts;
45 std::shared_ptr<Fortran::frontend::PreprocessorOptions> preprocessorOpts;
46
47 CompilerInvocationBase();
48 CompilerInvocationBase(const CompilerInvocationBase &x);
49 ~CompilerInvocationBase();
50
51 clang::DiagnosticOptions &getDiagnosticOpts() {
52 return *diagnosticOpts.get();
53 }
54 const clang::DiagnosticOptions &getDiagnosticOpts() const {
55 return *diagnosticOpts.get();
56 }
57
58 PreprocessorOptions &getPreprocessorOpts() { return *preprocessorOpts; }
59 const PreprocessorOptions &getPreprocessorOpts() const {
60 return *preprocessorOpts;
61 }
62};
63
64class CompilerInvocation : public CompilerInvocationBase {
66 // TODO: Merge with or translate to parserOpts_. We shouldn't need two sets of
67 // options.
68 FrontendOptions frontendOpts;
69
71 // TODO: Merge with or translate to frontendOpts. We shouldn't need two sets
72 // of options.
73 Fortran::parser::Options parserOpts;
74
77
80
83
86
87 // The original invocation of the compiler driver.
88 // This string will be set as the return value from the COMPILER_OPTIONS
89 // intrinsic of iso_fortran_env.
90 std::string allCompilerInvocOpts;
91
93 // TODO: Merge with or translate to frontendOpts. We shouldn't need two sets
94 // of options.
95 std::string moduleDir = ".";
96
97 std::string moduleFileSuffix = ".mod";
98
99 bool debugModuleDir = false;
100 bool hermeticModuleFileOutput = false;
101
102 // Executable name
103 const char *argv0;
104
109 bool useAnalyzedObjectsForUnparse = true;
110
111 // Fortran Dialect options
113
114 // Fortran Error options
115 size_t maxErrors = 0;
116 bool warnAsErr = false;
117 // Fortran Warning options
118 bool enableConformanceChecks = false;
119 bool enableUsageChecks = false;
120 bool disableWarnings = false;
121
125 [](llvm::raw_ostream &o, const Fortran::evaluate::GenericExprWrapper &x) {
126 if (x.v) {
127 x.v->AsFortran(o);
128 } else {
129 o << "(bad expression)";
130 }
131 },
132 [](llvm::raw_ostream &o,
134 if (x.v) {
135 x.v->AsFortran(o);
136 } else {
137 o << "(bad assignment)";
138 }
139 },
140 [](llvm::raw_ostream &o, const Fortran::evaluate::ProcedureRef &x) {
141 x.AsFortran(o << "CALL ");
142 },
143 };
144
147 bool enableTimers;
148
149public:
150 CompilerInvocation() = default;
151
152 FrontendOptions &getFrontendOpts() { return frontendOpts; }
153 const FrontendOptions &getFrontendOpts() const { return frontendOpts; }
154
155 Fortran::parser::Options &getFortranOpts() { return parserOpts; }
156 const Fortran::parser::Options &getFortranOpts() const { return parserOpts; }
157
158 TargetOptions &getTargetOpts() { return targetOpts; }
159 const TargetOptions &getTargetOpts() const { return targetOpts; }
160
161 CodeGenOptions &getCodeGenOpts() { return codeGenOpts; }
162 const CodeGenOptions &getCodeGenOpts() const { return codeGenOpts; }
163
164 Fortran::common::LangOptions &getLangOpts() { return langOpts; }
165 const Fortran::common::LangOptions &getLangOpts() const { return langOpts; }
166
167 Fortran::lower::LoweringOptions &getLoweringOpts() { return loweringOpts; }
168 const Fortran::lower::LoweringOptions &getLoweringOpts() const {
169 return loweringOpts;
170 }
171
173 std::unique_ptr<Fortran::semantics::SemanticsContext>
175 llvm::StringRef targetFeatures);
176
177 std::string &getModuleDir() { return moduleDir; }
178 const std::string &getModuleDir() const { return moduleDir; }
179
180 std::string &getModuleFileSuffix() { return moduleFileSuffix; }
181 const std::string &getModuleFileSuffix() const { return moduleFileSuffix; }
182
183 bool &getDebugModuleDir() { return debugModuleDir; }
184 const bool &getDebugModuleDir() const { return debugModuleDir; }
185
186 bool &getHermeticModuleFileOutput() { return hermeticModuleFileOutput; }
187 const bool &getHermeticModuleFileOutput() const {
188 return hermeticModuleFileOutput;
189 }
190 size_t &getMaxErrors() { return maxErrors; }
191 const size_t &getMaxErrors() const { return maxErrors; }
192
193 bool &getWarnAsErr() { return warnAsErr; }
194 const bool &getWarnAsErr() const { return warnAsErr; }
195
196 bool &getUseAnalyzedObjectsForUnparse() {
197 return useAnalyzedObjectsForUnparse;
198 }
199 const bool &getUseAnalyzedObjectsForUnparse() const {
200 return useAnalyzedObjectsForUnparse;
201 }
202
203 bool &getEnableConformanceChecks() { return enableConformanceChecks; }
204 const bool &getEnableConformanceChecks() const {
205 return enableConformanceChecks;
206 }
207
208 const char *getArgv0() { return argv0; }
209
210 bool &getEnableUsageChecks() { return enableUsageChecks; }
211 const bool &getEnableUsageChecks() const { return enableUsageChecks; }
212
213 bool &getDisableWarnings() { return disableWarnings; }
214 const bool &getDisableWarnings() const { return disableWarnings; }
215
217 return asFortran;
218 }
219 const Fortran::parser::AnalyzedObjectsAsFortran &getAsFortran() const {
220 return asFortran;
221 }
222
224 return defaultKinds;
225 }
226 const Fortran::common::IntrinsicTypeDefaultKinds &getDefaultKinds() const {
227 return defaultKinds;
228 }
229
230 bool getEnableTimers() const { return enableTimers; }
231
236 static bool createFromArgs(CompilerInvocation &res,
237 llvm::ArrayRef<const char *> commandLineArgs,
238 clang::DiagnosticsEngine &diags,
239 const char *argv0 = nullptr);
240
241 // Enables the std=f2018 conformance check
242 void setEnableConformanceChecks() { enableConformanceChecks = true; }
243
244 // Enables the usage checks
245 void setEnableUsageChecks() { enableUsageChecks = true; }
246
247 // Disables all Warnings
248 void setDisableWarnings() { disableWarnings = true; }
249
251 void setArgv0(const char *dir) { argv0 = dir; }
252
253 void setModuleDir(std::string &dir) { moduleDir = dir; }
254
255 void setModuleFileSuffix(const char *suffix) {
256 moduleFileSuffix = std::string(suffix);
257 }
258
259 void setDebugModuleDir(bool flag) { debugModuleDir = flag; }
260 void setHermeticModuleFileOutput(bool flag) {
261 hermeticModuleFileOutput = flag;
262 }
263
264 void setMaxErrors(size_t maxErrors) { this->maxErrors = maxErrors; }
265 void setWarnAsErr(bool flag) { warnAsErr = flag; }
266
267 void setUseAnalyzedObjectsForUnparse(bool flag) {
268 useAnalyzedObjectsForUnparse = flag;
269 }
270
272 // TODO: We should map frontendOpts_ to parserOpts_ instead. For that, we
273 // need to extend frontendOpts_ first. Next, we need to add the corresponding
274 // compiler driver options in libclangDriver.
276
279
283
286 void setFortranOpts();
287
290
293 void setLoweringOptions();
294};
295
296} // end namespace Fortran::frontend
297#endif // FORTRAN_FRONTEND_COMPILERINVOCATION_H
Definition default-kinds.h:26
Definition LangOptions.h:71
Definition call.h:356
Definition CodeGenOptions.h:50
std::shared_ptr< Fortran::frontend::PreprocessorOptions > preprocessorOpts
Options for the preprocessor.
Definition CompilerInvocation.h:45
std::shared_ptr< clang::DiagnosticOptions > diagnosticOpts
Options controlling the diagnostic engine.
Definition CompilerInvocation.h:43
void setDefaultFortranOpts()
Set the Fortran options to predefined defaults.
Definition CompilerInvocation.cpp:2009
void setFortranOpts()
Definition CompilerInvocation.cpp:2098
void setLoweringOptions()
Definition CompilerInvocation.cpp:2191
static bool createFromArgs(CompilerInvocation &res, llvm::ArrayRef< const char * > commandLineArgs, clang::DiagnosticsEngine &diags, const char *argv0=nullptr)
Definition CompilerInvocation.cpp:1779
void collectMacroDefinitions()
Definition CompilerInvocation.cpp:1978
std::unique_ptr< Fortran::semantics::SemanticsContext > getSemanticsCtx(Fortran::parser::AllCookedSources &allCookedSources, llvm::StringRef targetFeatures)
Creates and configures semantics context based on the compilation flags.
Definition CompilerInvocation.cpp:2157
void setDefaultPredefinitions()
Set the default predefinitions.
Definition CompilerInvocation.cpp:2021
void setArgv0(const char *dir)
Useful setters.
Definition CompilerInvocation.h:251
void setSemanticsOpts(Fortran::parser::AllCookedSources &)
Set the Semantic Options.
Options for controlling the target.
Definition TargetOptions.h:27
Definition LoweringOptions.h:48
Definition provenance.h:286
Definition FIRType.h:106
Definition expression.h:978
Definition options.h:21