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/Option/ArgList.h"
28#include <memory>
29
30namespace llvm {
31class TargetMachine;
32} // namespace llvm
33
34namespace Fortran::frontend {
35
40bool parseDiagnosticArgs(clang::DiagnosticOptions &opts,
41 llvm::opt::ArgList &args);
42
43class CompilerInvocationBase {
44public:
46 std::shared_ptr<clang::DiagnosticOptions> diagnosticOpts;
48 std::shared_ptr<Fortran::frontend::PreprocessorOptions> preprocessorOpts;
49
50 CompilerInvocationBase();
51 CompilerInvocationBase(const CompilerInvocationBase &x);
52 ~CompilerInvocationBase();
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
67class CompilerInvocation : public CompilerInvocationBase {
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 // Executable name
106 const char *argv0;
107
112 bool useAnalyzedObjectsForUnparse = true;
113
114 // Fortran Dialect options
116
117 // Fortran Error options
118 size_t maxErrors = 0;
119 bool warnAsErr = false;
120 // Fortran Warning options
121 bool enableConformanceChecks = false;
122 bool enableUsageChecks = false;
123 bool disableWarnings = false;
124
128 [](llvm::raw_ostream &o, const Fortran::evaluate::GenericExprWrapper &x) {
129 if (x.v) {
130 x.v->AsFortran(o);
131 } else {
132 o << "(bad expression)";
133 }
134 },
135 [](llvm::raw_ostream &o,
137 if (x.v) {
138 x.v->AsFortran(o);
139 } else {
140 o << "(bad assignment)";
141 }
142 },
143 [](llvm::raw_ostream &o, const Fortran::evaluate::ProcedureRef &x) {
144 x.AsFortran(o << "CALL ");
145 },
146 };
147
150 bool enableTimers;
151
152public:
153 CompilerInvocation() = default;
154
155 FrontendOptions &getFrontendOpts() { return frontendOpts; }
156 const FrontendOptions &getFrontendOpts() const { return frontendOpts; }
157
158 Fortran::parser::Options &getFortranOpts() { return parserOpts; }
159 const Fortran::parser::Options &getFortranOpts() const { return parserOpts; }
160
161 TargetOptions &getTargetOpts() { return targetOpts; }
162 const TargetOptions &getTargetOpts() const { return targetOpts; }
163
164 CodeGenOptions &getCodeGenOpts() { return codeGenOpts; }
165 const CodeGenOptions &getCodeGenOpts() const { return codeGenOpts; }
166
167 Fortran::common::LangOptions &getLangOpts() { return langOpts; }
168 const Fortran::common::LangOptions &getLangOpts() const { return langOpts; }
169
170 Fortran::lower::LoweringOptions &getLoweringOpts() { return loweringOpts; }
171 const Fortran::lower::LoweringOptions &getLoweringOpts() const {
172 return loweringOpts;
173 }
174
176 std::unique_ptr<Fortran::semantics::SemanticsContext>
178 const llvm::TargetMachine &);
179
180 std::string &getModuleDir() { return moduleDir; }
181 const std::string &getModuleDir() const { return moduleDir; }
182
183 std::string &getModuleFileSuffix() { return moduleFileSuffix; }
184 const std::string &getModuleFileSuffix() const { return moduleFileSuffix; }
185
186 bool &getDebugModuleDir() { return debugModuleDir; }
187 const bool &getDebugModuleDir() const { return debugModuleDir; }
188
189 bool &getHermeticModuleFileOutput() { return hermeticModuleFileOutput; }
190 const bool &getHermeticModuleFileOutput() const {
191 return hermeticModuleFileOutput;
192 }
193 size_t &getMaxErrors() { return maxErrors; }
194 const size_t &getMaxErrors() const { return maxErrors; }
195
196 bool &getWarnAsErr() { return warnAsErr; }
197 const bool &getWarnAsErr() const { return warnAsErr; }
198
199 bool &getUseAnalyzedObjectsForUnparse() {
200 return useAnalyzedObjectsForUnparse;
201 }
202 const bool &getUseAnalyzedObjectsForUnparse() const {
203 return useAnalyzedObjectsForUnparse;
204 }
205
206 bool &getEnableConformanceChecks() { return enableConformanceChecks; }
207 const bool &getEnableConformanceChecks() const {
208 return enableConformanceChecks;
209 }
210
211 const char *getArgv0() { return argv0; }
212
213 bool &getEnableUsageChecks() { return enableUsageChecks; }
214 const bool &getEnableUsageChecks() const { return enableUsageChecks; }
215
216 bool &getDisableWarnings() { return disableWarnings; }
217 const bool &getDisableWarnings() const { return disableWarnings; }
218
220 return asFortran;
221 }
222 const Fortran::parser::AnalyzedObjectsAsFortran &getAsFortran() const {
223 return asFortran;
224 }
225
227 return defaultKinds;
228 }
229 const Fortran::common::IntrinsicTypeDefaultKinds &getDefaultKinds() const {
230 return defaultKinds;
231 }
232
233 bool getEnableTimers() const { return enableTimers; }
234
239 static bool createFromArgs(CompilerInvocation &res,
240 llvm::ArrayRef<const char *> commandLineArgs,
241 clang::DiagnosticsEngine &diags,
242 const char *argv0 = nullptr);
243
244 // Enables the std=f2018 conformance check
245 void setEnableConformanceChecks() { enableConformanceChecks = true; }
246
247 // Enables the usage checks
248 void setEnableUsageChecks() { enableUsageChecks = true; }
249
250 // Disables all Warnings
251 void setDisableWarnings() { disableWarnings = true; }
252
254 void setArgv0(const char *dir) { argv0 = dir; }
255
256 void setModuleDir(std::string &dir) { moduleDir = dir; }
257
258 void setModuleFileSuffix(const char *suffix) {
259 moduleFileSuffix = std::string(suffix);
260 }
261
262 void setDebugModuleDir(bool flag) { debugModuleDir = flag; }
263 void setHermeticModuleFileOutput(bool flag) {
264 hermeticModuleFileOutput = flag;
265 }
266
267 void setMaxErrors(size_t maxErrors) { this->maxErrors = maxErrors; }
268 void setWarnAsErr(bool flag) { warnAsErr = flag; }
269
270 void setUseAnalyzedObjectsForUnparse(bool flag) {
271 useAnalyzedObjectsForUnparse = flag;
272 }
273
275 // TODO: We should map frontendOpts_ to parserOpts_ instead. For that, we
276 // need to extend frontendOpts_ first. Next, we need to add the corresponding
277 // compiler driver options in libclangDriver.
279
282
286
289 void setFortranOpts();
290
293
296 void setLoweringOptions();
297};
298
299} // end namespace Fortran::frontend
300#endif // FORTRAN_FRONTEND_COMPILERINVOCATION_H
Definition default-kinds.h:26
Definition LangOptions.h:58
Definition call.h:232
Definition CodeGenOptions.h:50
std::shared_ptr< Fortran::frontend::PreprocessorOptions > preprocessorOpts
Options for the preprocessor.
Definition CompilerInvocation.h:48
std::shared_ptr< clang::DiagnosticOptions > diagnosticOpts
Options controlling the diagnostic engine.
Definition CompilerInvocation.h:46
void setDefaultFortranOpts()
Set the Fortran options to predefined defaults.
Definition CompilerInvocation.cpp:1711
void setFortranOpts()
Definition CompilerInvocation.cpp:1801
void setLoweringOptions()
Definition CompilerInvocation.cpp:1880
static bool createFromArgs(CompilerInvocation &res, llvm::ArrayRef< const char * > commandLineArgs, clang::DiagnosticsEngine &diags, const char *argv0=nullptr)
Definition CompilerInvocation.cpp:1522
void collectMacroDefinitions()
Definition CompilerInvocation.cpp:1680
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:1854
void setDefaultPredefinitions()
Set the default predefinitions.
Definition CompilerInvocation.cpp:1728
void setArgv0(const char *dir)
Useful setters.
Definition CompilerInvocation.h:254
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:89
Definition expression.h:896
Definition options.h:21