Skip to content

Commit 937bf00

Browse files
Enable -E, -P flags (Fortran preprocessing)
1 parent 191f754 commit 937bf00

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

lib/Driver/Driver.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,31 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
218218

219219
// -{E,EP,P,M,MM} only run the preprocessor.
220220
if (CCCIsCPP() || (PhaseArg = DAL.getLastArg(options::OPT_E)) ||
221+
(PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
221222
(PhaseArg = DAL.getLastArg(options::OPT__SLASH_EP)) ||
222223
(PhaseArg = DAL.getLastArg(options::OPT_M, options::OPT_MM)) ||
223224
(PhaseArg = DAL.getLastArg(options::OPT__SLASH_P))) {
224-
FinalPhase = phases::Preprocess;
225225

226-
// -fsyntax-only stops Fortran compilation after FortranFrontend
227-
} else if (IsFortranMode() && (PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only))) {
228-
FinalPhase = phases::FortranFrontend;
226+
// -fsyntax-only or -E stops Fortran compilation after FortranFrontend
227+
if (IsFortranMode() && (DAL.getLastArg(options::OPT_E) ||
228+
DAL.getLastArg(options::OPT_fsyntax_only))) {
229+
FinalPhase = phases::FortranFrontend;
230+
231+
// if not Fortran, fsyntax_only implies 'Compile' is the FinalPhase
232+
} else if (DAL.getLastArg(options::OPT_fsyntax_only)) {
233+
FinalPhase = phases::Compile;
234+
235+
// everything else has 'Preprocess' as its FinalPhase
236+
} else {
237+
FinalPhase = phases::Preprocess;
238+
}
229239

230240
// --precompile only runs up to precompilation.
231241
} else if ((PhaseArg = DAL.getLastArg(options::OPT__precompile))) {
232242
FinalPhase = phases::Precompile;
233243

234-
// -{fsyntax-only,-analyze,emit-ast} only run up to the compiler.
235-
} else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
236-
(PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
244+
// -{analyze,emit-ast} only run up to the compiler.
245+
} else if ((PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
237246
(PhaseArg = DAL.getLastArg(options::OPT_verify_pch)) ||
238247
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
239248
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||

lib/Driver/ToolChains/Flang.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,25 @@ void FlangFrontend::ConstructJob(Compilation &C, const JobAction &JA,
613613
// Enable preprocessor
614614
if (Args.hasArg(options::OPT_Mpreprocess) ||
615615
Args.hasArg(options::OPT_cpp) ||
616+
Args.hasArg(options::OPT_E) ||
616617
types::getPreprocessedType(InputType) != types::TY_INVALID) {
617618
UpperCmdArgs.push_back("-preprocess");
618-
for (auto Arg : Args.filtered(options::OPT_Mpreprocess, options::OPT_cpp)) {
619+
for (auto Arg : Args.filtered(options::OPT_Mpreprocess, options::OPT_cpp, options::OPT_E)) {
619620
Arg->claim();
620621
}
622+
623+
// When -E option is provided, run only the fortran preprocessor.
624+
// Only in -E mode, consume -P if it exists
625+
if (Args.hasArg(options::OPT_E)) {
626+
UpperCmdArgs.push_back("-es");
627+
// Line marker mode is disabled
628+
if (Args.hasArg(options::OPT_P)) {
629+
Args.ClaimAllArgs(options::OPT_P);
630+
} else {
631+
// -pp enables line marker mode in fortran preprocessor
632+
UpperCmdArgs.push_back("-pp");
633+
}
634+
}
621635
}
622636

623637
// Enable standards checking
@@ -760,8 +774,9 @@ void FlangFrontend::ConstructJob(Compilation &C, const JobAction &JA,
760774

761775
C.addCommand(llvm::make_unique<Command>(JA, *this, UpperExec, UpperCmdArgs, Inputs));
762776

763-
// For -fsyntax-only that is it
764-
if (Args.hasArg(options::OPT_fsyntax_only)) return;
777+
// For -fsyntax-only or -E that is it
778+
if (Args.hasArg(options::OPT_fsyntax_only) ||
779+
Args.hasArg(options::OPT_E)) return;
765780

766781
/***** Lower part of Fortran frontend *****/
767782

0 commit comments

Comments
 (0)