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/Common/LangOptions.h"
17#include "flang/Frontend/CodeGenOptions.h"
18#include "flang/Frontend/FrontendOptions.h"
22#include "flang/Parser/parsing.h"
23#include "flang/Semantics/semantics.h"
24#include "mlir/Support/Timing.h"
25#include "clang/Basic/Diagnostic.h"
26#include "clang/Basic/DiagnosticOptions.h"
27#include "llvm/Option/ArgList.h"
28#include <memory>
29
30namespace llvm {
31class TargetMachine;
32}
33
34namespace Fortran::frontend {
35
40bool parseDiagnosticArgs(clang::DiagnosticOptions &opts,
41 llvm::opt::ArgList &args);
42
44public:
46 llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagnosticOpts;
48 std::shared_ptr<Fortran::frontend::PreprocessorOptions> preprocessorOpts;
49
53
54 clang::DiagnosticOptions &getDiagnosticOpts() {
55 return *diagnosticOpts.get();
56 }
57 const clang::DiagnosticOptions &getDiagnosticOpts() const {
58 return *diagnosticOpts.get();
59 }
60
61 PreprocessorOptions &getPreprocessorOpts() { return *preprocessorOpts; }
62 const PreprocessorOptions &getPreprocessorOpts() const {
63 return *preprocessorOpts;
64 }
65};
66
69 // TODO: Merge with or translate to parserOpts_. We shouldn't need two sets of
70 // options.
71 FrontendOptions frontendOpts;
72
74 // TODO: Merge with or translate to frontendOpts. We shouldn't need two sets
75 // of options.
76 Fortran::parser::Options parserOpts;
77
80
83
86
89
90 // The original invocation of the compiler driver.
91 // This string will be set as the return value from the COMPILER_OPTIONS
92 // intrinsic of iso_fortran_env.
93 std::string allCompilerInvocOpts;
94
96 // TODO: Merge with or translate to frontendOpts. We shouldn't need two sets
97 // of options.
98 std::string moduleDir = ".";
99
100 std::string moduleFileSuffix = ".mod";
101
102 bool debugModuleDir = false;
103 bool hermeticModuleFileOutput = false;
104
105 bool warnAsErr = false;
106
107 // Executable name
108 const char *argv0;
109
114 bool useAnalyzedObjectsForUnparse = true;
115
116 // Fortran Dialect options
118
119 // Fortran Warning options
120 bool enableConformanceChecks = false;
121 bool enableUsageChecks = false;
122 bool disableWarnings = false;
123
127 [](llvm::raw_ostream &o, const Fortran::evaluate::GenericExprWrapper &x) {
128 if (x.v) {
129 x.v->AsFortran(o);
130 } else {
131 o << "(bad expression)";
132 }
133 },
134 [](llvm::raw_ostream &o,
136 if (x.v) {
137 x.v->AsFortran(o);
138 } else {
139 o << "(bad assignment)";
140 }
141 },
142 [](llvm::raw_ostream &o, const Fortran::evaluate::ProcedureRef &x) {
143 x.AsFortran(o << "CALL ");
144 },
145 };
146
149 bool enableTimers;
150
151public:
152 CompilerInvocation() = default;
153
154 FrontendOptions &getFrontendOpts() { return frontendOpts; }
155 const FrontendOptions &getFrontendOpts() const { return frontendOpts; }
156
157 Fortran::parser::Options &getFortranOpts() { return parserOpts; }
158 const Fortran::parser::Options &getFortranOpts() const { return parserOpts; }
159
160 TargetOptions &getTargetOpts() { return targetOpts; }
161 const TargetOptions &getTargetOpts() const { return targetOpts; }
162
163 CodeGenOptions &getCodeGenOpts() { return codeGenOpts; }
164 const CodeGenOptions &getCodeGenOpts() const { return codeGenOpts; }
165
166 Fortran::common::LangOptions &getLangOpts() { return langOpts; }
167 const Fortran::common::LangOptions &getLangOpts() const { return langOpts; }
168
169 Fortran::lower::LoweringOptions &getLoweringOpts() { return loweringOpts; }
170 const Fortran::lower::LoweringOptions &getLoweringOpts() const {
171 return loweringOpts;
172 }
173
175 std::unique_ptr<Fortran::semantics::SemanticsContext>
177 const llvm::TargetMachine &);
178
179 std::string &getModuleDir() { return moduleDir; }
180 const std::string &getModuleDir() const { return moduleDir; }
181
182 std::string &getModuleFileSuffix() { return moduleFileSuffix; }
183 const std::string &getModuleFileSuffix() const { return moduleFileSuffix; }
184
185 bool &getDebugModuleDir() { return debugModuleDir; }
186 const bool &getDebugModuleDir() const { return debugModuleDir; }
187
188 bool &getHermeticModuleFileOutput() { return hermeticModuleFileOutput; }
189 const bool &getHermeticModuleFileOutput() const {
190 return hermeticModuleFileOutput;
191 }
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 setWarnAsErr(bool flag) { warnAsErr = flag; }
265
266 void setUseAnalyzedObjectsForUnparse(bool flag) {
267 useAnalyzedObjectsForUnparse = flag;
268 }
269
271 // TODO: We should map frontendOpts_ to parserOpts_ instead. For that, we
272 // need to extend frontendOpts_ first. Next, we need to add the corresponding
273 // compiler driver options in libclangDriver.
275
278
282
285 void setFortranOpts();
286
289
292 void setLoweringOptions();
293};
294
295} // end namespace Fortran::frontend
296#endif // FORTRAN_FRONTEND_COMPILERINVOCATION_H
Definition: default-kinds.h:26
Definition: LangOptions.h:58
Definition: call.h:232
Definition: CodeGenOptions.h:49
Definition: CompilerInvocation.h:43
std::shared_ptr< Fortran::frontend::PreprocessorOptions > preprocessorOpts
Options for the preprocessor.
Definition: CompilerInvocation.h:48
llvm::IntrusiveRefCntPtr< clang::DiagnosticOptions > diagnosticOpts
Options controlling the diagnostic engine.
Definition: CompilerInvocation.h:46
Definition: CompilerInvocation.h:67
void setDefaultFortranOpts()
Set the Fortran options to predefined defaults.
Definition: CompilerInvocation.cpp:1483
void setFortranOpts()
Definition: CompilerInvocation.cpp:1543
void setLoweringOptions()
Definition: CompilerInvocation.cpp:1630
static bool createFromArgs(CompilerInvocation &res, llvm::ArrayRef< const char * > commandLineArgs, clang::DiagnosticsEngine &diags, const char *argv0=nullptr)
Definition: CompilerInvocation.cpp:1315
void collectMacroDefinitions()
Definition: CompilerInvocation.cpp:1452
std::unique_ptr< Fortran::semantics::SemanticsContext > getSemanticsCtx(Fortran::parser::AllCookedSources &allCookedSources, const llvm::TargetMachine &)
Creates and configures semantics context based on the compilation flags.
Definition: CompilerInvocation.cpp:1605
void setDefaultPredefinitions()
Set the default predefinitions.
Definition: CompilerInvocation.cpp:1500
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:34
Definition: provenance.h:281
Definition: FIRType.h:77
Definition: expression.h:896
FrontendOptions - Options for controlling the behavior of the frontend.
Definition: FrontendOptions.h:236
Definition: parsing.h:27