xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/Flang.cpp (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1480093f4SDimitry Andric //===-- Flang.cpp - Flang+LLVM ToolChain Implementations --------*- C++ -*-===//
2480093f4SDimitry Andric //
3480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6480093f4SDimitry Andric //
7480093f4SDimitry Andric //===----------------------------------------------------------------------===//
8480093f4SDimitry Andric 
9480093f4SDimitry Andric 
10480093f4SDimitry Andric #include "Flang.h"
11480093f4SDimitry Andric #include "CommonArgs.h"
12480093f4SDimitry Andric 
13480093f4SDimitry Andric #include "clang/Driver/Options.h"
14480093f4SDimitry Andric 
15480093f4SDimitry Andric #include <cassert>
16480093f4SDimitry Andric 
17480093f4SDimitry Andric using namespace clang::driver;
18480093f4SDimitry Andric using namespace clang::driver::tools;
19480093f4SDimitry Andric using namespace clang;
20480093f4SDimitry Andric using namespace llvm::opt;
21480093f4SDimitry Andric 
2281ad6265SDimitry Andric /// Add -x lang to \p CmdArgs for \p Input.
2381ad6265SDimitry Andric static void addDashXForInput(const ArgList &Args, const InputInfo &Input,
2481ad6265SDimitry Andric                              ArgStringList &CmdArgs) {
2581ad6265SDimitry Andric   CmdArgs.push_back("-x");
2681ad6265SDimitry Andric   // Map the driver type to the frontend type.
2781ad6265SDimitry Andric   CmdArgs.push_back(types::getTypeName(Input.getType()));
2881ad6265SDimitry Andric }
2981ad6265SDimitry Andric 
30*bdd1243dSDimitry Andric void Flang::addFortranDialectOptions(const ArgList &Args,
31fe6060f1SDimitry Andric                                      ArgStringList &CmdArgs) const {
32fe6060f1SDimitry Andric   Args.AddAllArgs(
33fe6060f1SDimitry Andric       CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form,
34fe6060f1SDimitry Andric                 options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp,
35fe6060f1SDimitry Andric                 options::OPT_fopenacc, options::OPT_finput_charset_EQ,
36fe6060f1SDimitry Andric                 options::OPT_fimplicit_none, options::OPT_fno_implicit_none,
37fe6060f1SDimitry Andric                 options::OPT_fbackslash, options::OPT_fno_backslash,
38fe6060f1SDimitry Andric                 options::OPT_flogical_abbreviations,
39fe6060f1SDimitry Andric                 options::OPT_fno_logical_abbreviations,
40fe6060f1SDimitry Andric                 options::OPT_fxor_operator, options::OPT_fno_xor_operator,
41fe6060f1SDimitry Andric                 options::OPT_falternative_parameter_statement,
42fe6060f1SDimitry Andric                 options::OPT_fdefault_real_8, options::OPT_fdefault_integer_8,
434824e7fdSDimitry Andric                 options::OPT_fdefault_double_8, options::OPT_flarge_sizes,
444824e7fdSDimitry Andric                 options::OPT_fno_automatic});
45fe6060f1SDimitry Andric }
46fe6060f1SDimitry Andric 
47*bdd1243dSDimitry Andric void Flang::addPreprocessingOptions(const ArgList &Args,
48e8d8bef9SDimitry Andric                                     ArgStringList &CmdArgs) const {
49349cc55cSDimitry Andric   Args.AddAllArgs(CmdArgs,
50349cc55cSDimitry Andric                   {options::OPT_P, options::OPT_D, options::OPT_U,
51349cc55cSDimitry Andric                    options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
52fe6060f1SDimitry Andric }
53fe6060f1SDimitry Andric 
54*bdd1243dSDimitry Andric void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
55fe6060f1SDimitry Andric   Args.AddAllArgs(CmdArgs,
56fe6060f1SDimitry Andric                   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
57fe6060f1SDimitry Andric                    options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
58*bdd1243dSDimitry Andric                    options::OPT_std_EQ, options::OPT_W_Joined,
59*bdd1243dSDimitry Andric                    options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ});
60*bdd1243dSDimitry Andric }
61*bdd1243dSDimitry Andric 
62*bdd1243dSDimitry Andric void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
63*bdd1243dSDimitry Andric   // ParsePICArgs parses -fPIC/-fPIE and their variants and returns a tuple of
64*bdd1243dSDimitry Andric   // (RelocationModel, PICLevel, IsPIE).
65*bdd1243dSDimitry Andric   llvm::Reloc::Model RelocationModel;
66*bdd1243dSDimitry Andric   unsigned PICLevel;
67*bdd1243dSDimitry Andric   bool IsPIE;
68*bdd1243dSDimitry Andric   std::tie(RelocationModel, PICLevel, IsPIE) =
69*bdd1243dSDimitry Andric       ParsePICArgs(getToolChain(), Args);
70*bdd1243dSDimitry Andric 
71*bdd1243dSDimitry Andric   if (auto *RMName = RelocationModelName(RelocationModel)) {
72*bdd1243dSDimitry Andric     CmdArgs.push_back("-mrelocation-model");
73*bdd1243dSDimitry Andric     CmdArgs.push_back(RMName);
74*bdd1243dSDimitry Andric   }
75*bdd1243dSDimitry Andric   if (PICLevel > 0) {
76*bdd1243dSDimitry Andric     CmdArgs.push_back("-pic-level");
77*bdd1243dSDimitry Andric     CmdArgs.push_back(PICLevel == 1 ? "1" : "2");
78*bdd1243dSDimitry Andric     if (IsPIE)
79*bdd1243dSDimitry Andric       CmdArgs.push_back("-pic-is-pie");
80*bdd1243dSDimitry Andric   }
81*bdd1243dSDimitry Andric }
82*bdd1243dSDimitry Andric 
83*bdd1243dSDimitry Andric void Flang::addTargetOptions(const ArgList &Args,
84*bdd1243dSDimitry Andric                              ArgStringList &CmdArgs) const {
85*bdd1243dSDimitry Andric   const ToolChain &TC = getToolChain();
86*bdd1243dSDimitry Andric   const llvm::Triple &Triple = TC.getEffectiveTriple();
87*bdd1243dSDimitry Andric   const Driver &D = TC.getDriver();
88*bdd1243dSDimitry Andric 
89*bdd1243dSDimitry Andric   std::string CPU = getCPUName(D, Args, Triple);
90*bdd1243dSDimitry Andric   if (!CPU.empty()) {
91*bdd1243dSDimitry Andric     CmdArgs.push_back("-target-cpu");
92*bdd1243dSDimitry Andric     CmdArgs.push_back(Args.MakeArgString(CPU));
93*bdd1243dSDimitry Andric   }
94*bdd1243dSDimitry Andric 
95*bdd1243dSDimitry Andric   // Add the target features.
96*bdd1243dSDimitry Andric   switch (TC.getArch()) {
97*bdd1243dSDimitry Andric   default:
98*bdd1243dSDimitry Andric     break;
99*bdd1243dSDimitry Andric   case llvm::Triple::aarch64:
100*bdd1243dSDimitry Andric     [[fallthrough]];
101*bdd1243dSDimitry Andric   case llvm::Triple::x86_64:
102*bdd1243dSDimitry Andric     getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
103*bdd1243dSDimitry Andric     break;
104*bdd1243dSDimitry Andric   }
105*bdd1243dSDimitry Andric 
106*bdd1243dSDimitry Andric   // TODO: Add target specific flags, ABI, mtune option etc.
107*bdd1243dSDimitry Andric }
108*bdd1243dSDimitry Andric 
109*bdd1243dSDimitry Andric static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
110*bdd1243dSDimitry Andric                                     ArgStringList &CmdArgs) {
111*bdd1243dSDimitry Andric   StringRef FPContract;
112*bdd1243dSDimitry Andric   bool HonorINFs = true;
113*bdd1243dSDimitry Andric   bool HonorNaNs = true;
114*bdd1243dSDimitry Andric   bool ApproxFunc = false;
115*bdd1243dSDimitry Andric   bool SignedZeros = true;
116*bdd1243dSDimitry Andric   bool AssociativeMath = false;
117*bdd1243dSDimitry Andric   bool ReciprocalMath = false;
118*bdd1243dSDimitry Andric 
119*bdd1243dSDimitry Andric   if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
120*bdd1243dSDimitry Andric     const StringRef Val = A->getValue();
121*bdd1243dSDimitry Andric     if (Val == "fast" || Val == "off") {
122*bdd1243dSDimitry Andric       FPContract = Val;
123*bdd1243dSDimitry Andric     } else if (Val == "on") {
124*bdd1243dSDimitry Andric       // Warn instead of error because users might have makefiles written for
125*bdd1243dSDimitry Andric       // gfortran (which accepts -ffp-contract=on)
126*bdd1243dSDimitry Andric       D.Diag(diag::warn_drv_unsupported_option_for_flang)
127*bdd1243dSDimitry Andric           << Val << A->getOption().getName() << "off";
128*bdd1243dSDimitry Andric       FPContract = "off";
129*bdd1243dSDimitry Andric     } else
130*bdd1243dSDimitry Andric       // Clang's "fast-honor-pragmas" option is not supported because it is
131*bdd1243dSDimitry Andric       // non-standard
132*bdd1243dSDimitry Andric       D.Diag(diag::err_drv_unsupported_option_argument)
133*bdd1243dSDimitry Andric           << A->getSpelling() << Val;
134*bdd1243dSDimitry Andric   }
135*bdd1243dSDimitry Andric 
136*bdd1243dSDimitry Andric   for (const Arg *A : Args) {
137*bdd1243dSDimitry Andric     auto optId = A->getOption().getID();
138*bdd1243dSDimitry Andric     switch (optId) {
139*bdd1243dSDimitry Andric     // if this isn't an FP option, skip the claim below
140*bdd1243dSDimitry Andric     default:
141*bdd1243dSDimitry Andric       continue;
142*bdd1243dSDimitry Andric 
143*bdd1243dSDimitry Andric     case options::OPT_fhonor_infinities:
144*bdd1243dSDimitry Andric       HonorINFs = true;
145*bdd1243dSDimitry Andric       break;
146*bdd1243dSDimitry Andric     case options::OPT_fno_honor_infinities:
147*bdd1243dSDimitry Andric       HonorINFs = false;
148*bdd1243dSDimitry Andric       break;
149*bdd1243dSDimitry Andric     case options::OPT_fhonor_nans:
150*bdd1243dSDimitry Andric       HonorNaNs = true;
151*bdd1243dSDimitry Andric       break;
152*bdd1243dSDimitry Andric     case options::OPT_fno_honor_nans:
153*bdd1243dSDimitry Andric       HonorNaNs = false;
154*bdd1243dSDimitry Andric       break;
155*bdd1243dSDimitry Andric     case options::OPT_fapprox_func:
156*bdd1243dSDimitry Andric       ApproxFunc = true;
157*bdd1243dSDimitry Andric       break;
158*bdd1243dSDimitry Andric     case options::OPT_fno_approx_func:
159*bdd1243dSDimitry Andric       ApproxFunc = false;
160*bdd1243dSDimitry Andric       break;
161*bdd1243dSDimitry Andric     case options::OPT_fsigned_zeros:
162*bdd1243dSDimitry Andric       SignedZeros = true;
163*bdd1243dSDimitry Andric       break;
164*bdd1243dSDimitry Andric     case options::OPT_fno_signed_zeros:
165*bdd1243dSDimitry Andric       SignedZeros = false;
166*bdd1243dSDimitry Andric       break;
167*bdd1243dSDimitry Andric     case options::OPT_fassociative_math:
168*bdd1243dSDimitry Andric       AssociativeMath = true;
169*bdd1243dSDimitry Andric       break;
170*bdd1243dSDimitry Andric     case options::OPT_fno_associative_math:
171*bdd1243dSDimitry Andric       AssociativeMath = false;
172*bdd1243dSDimitry Andric       break;
173*bdd1243dSDimitry Andric     case options::OPT_freciprocal_math:
174*bdd1243dSDimitry Andric       ReciprocalMath = true;
175*bdd1243dSDimitry Andric       break;
176*bdd1243dSDimitry Andric     case options::OPT_fno_reciprocal_math:
177*bdd1243dSDimitry Andric       ReciprocalMath = false;
178*bdd1243dSDimitry Andric       break;
179*bdd1243dSDimitry Andric     case options::OPT_Ofast:
180*bdd1243dSDimitry Andric       [[fallthrough]];
181*bdd1243dSDimitry Andric     case options::OPT_ffast_math:
182*bdd1243dSDimitry Andric       HonorINFs = false;
183*bdd1243dSDimitry Andric       HonorNaNs = false;
184*bdd1243dSDimitry Andric       AssociativeMath = true;
185*bdd1243dSDimitry Andric       ReciprocalMath = true;
186*bdd1243dSDimitry Andric       ApproxFunc = true;
187*bdd1243dSDimitry Andric       SignedZeros = false;
188*bdd1243dSDimitry Andric       FPContract = "fast";
189*bdd1243dSDimitry Andric       break;
190*bdd1243dSDimitry Andric     case options::OPT_fno_fast_math:
191*bdd1243dSDimitry Andric       HonorINFs = true;
192*bdd1243dSDimitry Andric       HonorNaNs = true;
193*bdd1243dSDimitry Andric       AssociativeMath = false;
194*bdd1243dSDimitry Andric       ReciprocalMath = false;
195*bdd1243dSDimitry Andric       ApproxFunc = false;
196*bdd1243dSDimitry Andric       SignedZeros = true;
197*bdd1243dSDimitry Andric       // -fno-fast-math should undo -ffast-math so I return FPContract to the
198*bdd1243dSDimitry Andric       // default. It is important to check it is "fast" (the default) so that
199*bdd1243dSDimitry Andric       // --ffp-contract=off -fno-fast-math --> -ffp-contract=off
200*bdd1243dSDimitry Andric       if (FPContract == "fast")
201*bdd1243dSDimitry Andric         FPContract = "";
202*bdd1243dSDimitry Andric       break;
203*bdd1243dSDimitry Andric     }
204*bdd1243dSDimitry Andric 
205*bdd1243dSDimitry Andric     // If we handled this option claim it
206*bdd1243dSDimitry Andric     A->claim();
207*bdd1243dSDimitry Andric   }
208*bdd1243dSDimitry Andric 
209*bdd1243dSDimitry Andric   if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
210*bdd1243dSDimitry Andric       ApproxFunc && !SignedZeros &&
211*bdd1243dSDimitry Andric       (FPContract == "fast" || FPContract == "")) {
212*bdd1243dSDimitry Andric     CmdArgs.push_back("-ffast-math");
213*bdd1243dSDimitry Andric     return;
214*bdd1243dSDimitry Andric   }
215*bdd1243dSDimitry Andric 
216*bdd1243dSDimitry Andric   if (!FPContract.empty())
217*bdd1243dSDimitry Andric     CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + FPContract));
218*bdd1243dSDimitry Andric 
219*bdd1243dSDimitry Andric   if (!HonorINFs)
220*bdd1243dSDimitry Andric     CmdArgs.push_back("-menable-no-infs");
221*bdd1243dSDimitry Andric 
222*bdd1243dSDimitry Andric   if (!HonorNaNs)
223*bdd1243dSDimitry Andric     CmdArgs.push_back("-menable-no-nans");
224*bdd1243dSDimitry Andric 
225*bdd1243dSDimitry Andric   if (ApproxFunc)
226*bdd1243dSDimitry Andric     CmdArgs.push_back("-fapprox-func");
227*bdd1243dSDimitry Andric 
228*bdd1243dSDimitry Andric   if (!SignedZeros)
229*bdd1243dSDimitry Andric     CmdArgs.push_back("-fno-signed-zeros");
230*bdd1243dSDimitry Andric 
231*bdd1243dSDimitry Andric   if (AssociativeMath && !SignedZeros)
232*bdd1243dSDimitry Andric     CmdArgs.push_back("-mreassociate");
233*bdd1243dSDimitry Andric 
234*bdd1243dSDimitry Andric   if (ReciprocalMath)
235*bdd1243dSDimitry Andric     CmdArgs.push_back("-freciprocal-math");
236e8d8bef9SDimitry Andric }
237e8d8bef9SDimitry Andric 
238480093f4SDimitry Andric void Flang::ConstructJob(Compilation &C, const JobAction &JA,
239480093f4SDimitry Andric                          const InputInfo &Output, const InputInfoList &Inputs,
240480093f4SDimitry Andric                          const ArgList &Args, const char *LinkingOutput) const {
241480093f4SDimitry Andric   const auto &TC = getToolChain();
24281ad6265SDimitry Andric   const llvm::Triple &Triple = TC.getEffectiveTriple();
24381ad6265SDimitry Andric   const std::string &TripleStr = Triple.getTriple();
244480093f4SDimitry Andric 
24581ad6265SDimitry Andric   const Driver &D = TC.getDriver();
246480093f4SDimitry Andric   ArgStringList CmdArgs;
247480093f4SDimitry Andric 
248e8d8bef9SDimitry Andric   // Invoke ourselves in -fc1 mode.
249480093f4SDimitry Andric   CmdArgs.push_back("-fc1");
250480093f4SDimitry Andric 
251e8d8bef9SDimitry Andric   // Add the "effective" target triple.
25281ad6265SDimitry Andric   CmdArgs.push_back("-triple");
25381ad6265SDimitry Andric   CmdArgs.push_back(Args.MakeArgString(TripleStr));
254480093f4SDimitry Andric 
255480093f4SDimitry Andric   if (isa<PreprocessJobAction>(JA)) {
256480093f4SDimitry Andric       CmdArgs.push_back("-E");
257480093f4SDimitry Andric   } else if (isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) {
258480093f4SDimitry Andric     if (JA.getType() == types::TY_Nothing) {
259480093f4SDimitry Andric       CmdArgs.push_back("-fsyntax-only");
260480093f4SDimitry Andric     } else if (JA.getType() == types::TY_AST) {
261480093f4SDimitry Andric       CmdArgs.push_back("-emit-ast");
262480093f4SDimitry Andric     } else if (JA.getType() == types::TY_LLVM_IR ||
263480093f4SDimitry Andric                JA.getType() == types::TY_LTO_IR) {
264480093f4SDimitry Andric       CmdArgs.push_back("-emit-llvm");
265480093f4SDimitry Andric     } else if (JA.getType() == types::TY_LLVM_BC ||
266480093f4SDimitry Andric                JA.getType() == types::TY_LTO_BC) {
267480093f4SDimitry Andric       CmdArgs.push_back("-emit-llvm-bc");
268480093f4SDimitry Andric     } else if (JA.getType() == types::TY_PP_Asm) {
269480093f4SDimitry Andric       CmdArgs.push_back("-S");
270480093f4SDimitry Andric     } else {
271480093f4SDimitry Andric       assert(false && "Unexpected output type!");
272480093f4SDimitry Andric     }
273480093f4SDimitry Andric   } else if (isa<AssembleJobAction>(JA)) {
274480093f4SDimitry Andric     CmdArgs.push_back("-emit-obj");
275480093f4SDimitry Andric   } else {
276480093f4SDimitry Andric     assert(false && "Unexpected action class for Flang tool.");
277480093f4SDimitry Andric   }
278480093f4SDimitry Andric 
279e8d8bef9SDimitry Andric   const InputInfo &Input = Inputs[0];
280e8d8bef9SDimitry Andric   types::ID InputType = Input.getType();
281e8d8bef9SDimitry Andric 
282e8d8bef9SDimitry Andric   // Add preprocessing options like -I, -D, etc. if we are using the
283e8d8bef9SDimitry Andric   // preprocessor (i.e. skip when dealing with e.g. binary files).
284e8d8bef9SDimitry Andric   if (types::getPreprocessedType(InputType) != types::TY_INVALID)
285*bdd1243dSDimitry Andric     addPreprocessingOptions(Args, CmdArgs);
286e8d8bef9SDimitry Andric 
287*bdd1243dSDimitry Andric   addFortranDialectOptions(Args, CmdArgs);
288fe6060f1SDimitry Andric 
28981ad6265SDimitry Andric   // Color diagnostics are parsed by the driver directly from argv and later
29081ad6265SDimitry Andric   // re-parsed to construct this job; claim any possible color diagnostic here
29181ad6265SDimitry Andric   // to avoid warn_drv_unused_argument.
29281ad6265SDimitry Andric   Args.getLastArg(options::OPT_fcolor_diagnostics,
29381ad6265SDimitry Andric                   options::OPT_fno_color_diagnostics);
29481ad6265SDimitry Andric   if (D.getDiags().getDiagnosticOptions().ShowColors)
29581ad6265SDimitry Andric     CmdArgs.push_back("-fcolor-diagnostics");
29681ad6265SDimitry Andric 
297*bdd1243dSDimitry Andric   // -fPIC and related options.
298*bdd1243dSDimitry Andric   addPicOptions(Args, CmdArgs);
299*bdd1243dSDimitry Andric 
300*bdd1243dSDimitry Andric   // Floating point related options
301*bdd1243dSDimitry Andric   addFloatingPointOptions(D, Args, CmdArgs);
302*bdd1243dSDimitry Andric 
303*bdd1243dSDimitry Andric   // Add target args, features, etc.
304*bdd1243dSDimitry Andric   addTargetOptions(Args, CmdArgs);
305*bdd1243dSDimitry Andric 
306fe6060f1SDimitry Andric   // Add other compile options
307*bdd1243dSDimitry Andric   addOtherOptions(Args, CmdArgs);
308fe6060f1SDimitry Andric 
309fe6060f1SDimitry Andric   // Forward -Xflang arguments to -fc1
310fe6060f1SDimitry Andric   Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
311fe6060f1SDimitry Andric 
31281ad6265SDimitry Andric   // Forward -mllvm options to the LLVM option parser. In practice, this means
31381ad6265SDimitry Andric   // forwarding to `-fc1` as that's where the LLVM parser is run.
31481ad6265SDimitry Andric   for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
31581ad6265SDimitry Andric     A->claim();
31681ad6265SDimitry Andric     A->render(Args, CmdArgs);
31781ad6265SDimitry Andric   }
31881ad6265SDimitry Andric 
31981ad6265SDimitry Andric   for (const Arg *A : Args.filtered(options::OPT_mmlir)) {
32081ad6265SDimitry Andric     A->claim();
32181ad6265SDimitry Andric     A->render(Args, CmdArgs);
32281ad6265SDimitry Andric   }
32381ad6265SDimitry Andric 
32481ad6265SDimitry Andric   // Optimization level for CodeGen.
32581ad6265SDimitry Andric   if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
32681ad6265SDimitry Andric     if (A->getOption().matches(options::OPT_O4)) {
32781ad6265SDimitry Andric       CmdArgs.push_back("-O3");
32881ad6265SDimitry Andric       D.Diag(diag::warn_O4_is_O3);
329*bdd1243dSDimitry Andric     } else if (A->getOption().matches(options::OPT_Ofast)) {
330*bdd1243dSDimitry Andric       CmdArgs.push_back("-O3");
33181ad6265SDimitry Andric     } else {
33281ad6265SDimitry Andric       A->render(Args, CmdArgs);
33381ad6265SDimitry Andric     }
33481ad6265SDimitry Andric   }
33581ad6265SDimitry Andric 
336480093f4SDimitry Andric   if (Output.isFilename()) {
337480093f4SDimitry Andric     CmdArgs.push_back("-o");
338480093f4SDimitry Andric     CmdArgs.push_back(Output.getFilename());
339480093f4SDimitry Andric   } else {
340480093f4SDimitry Andric     assert(Output.isNothing() && "Invalid output.");
341480093f4SDimitry Andric   }
342480093f4SDimitry Andric 
343480093f4SDimitry Andric   assert(Input.isFilename() && "Invalid input.");
34481ad6265SDimitry Andric 
34581ad6265SDimitry Andric   addDashXForInput(Args, Input, CmdArgs);
34681ad6265SDimitry Andric 
347480093f4SDimitry Andric   CmdArgs.push_back(Input.getFilename());
348480093f4SDimitry Andric 
349e8d8bef9SDimitry Andric   // TODO: Replace flang-new with flang once the new driver replaces the
350e8d8bef9SDimitry Andric   // throwaway driver
351e8d8bef9SDimitry Andric   const char *Exec = Args.MakeArgString(D.GetProgramPath("flang-new", TC));
352e8d8bef9SDimitry Andric   C.addCommand(std::make_unique<Command>(JA, *this,
353e8d8bef9SDimitry Andric                                          ResponseFileSupport::AtFileUTF8(),
354e8d8bef9SDimitry Andric                                          Exec, CmdArgs, Inputs, Output));
355480093f4SDimitry Andric }
356480093f4SDimitry Andric 
357e8d8bef9SDimitry Andric Flang::Flang(const ToolChain &TC) : Tool("flang-new", "flang frontend", TC) {}
358480093f4SDimitry Andric 
359480093f4SDimitry Andric Flang::~Flang() {}
360