Skip to content

Commit bf8b5d2

Browse files
authored
Merge pull request #23 from vjayathirtha-nv/release_60
Enable -E, -P flags (Fortran preprocessing)
2 parents d46cbfe + 92cf0fb commit bf8b5d2

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
@@ -227,22 +227,31 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
227227

228228
// -{E,EP,P,M,MM} only run the preprocessor.
229229
if (CCCIsCPP() || (PhaseArg = DAL.getLastArg(options::OPT_E)) ||
230+
(PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
230231
(PhaseArg = DAL.getLastArg(options::OPT__SLASH_EP)) ||
231232
(PhaseArg = DAL.getLastArg(options::OPT_M, options::OPT_MM)) ||
232233
(PhaseArg = DAL.getLastArg(options::OPT__SLASH_P))) {
233-
FinalPhase = phases::Preprocess;
234234

235-
// -fsyntax-only stops Fortran compilation after FortranFrontend
236-
} else if (IsFortranMode() && (PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only))) {
237-
FinalPhase = phases::FortranFrontend;
235+
// -fsyntax-only or -E stops Fortran compilation after FortranFrontend
236+
if (IsFortranMode() && (DAL.getLastArg(options::OPT_E) ||
237+
DAL.getLastArg(options::OPT_fsyntax_only))) {
238+
FinalPhase = phases::FortranFrontend;
239+
240+
// if not Fortran, fsyntax_only implies 'Compile' is the FinalPhase
241+
} else if (DAL.getLastArg(options::OPT_fsyntax_only)) {
242+
FinalPhase = phases::Compile;
243+
244+
// everything else has 'Preprocess' as its FinalPhase
245+
} else {
246+
FinalPhase = phases::Preprocess;
247+
}
238248

239249
// --precompile only runs up to precompilation.
240250
} else if ((PhaseArg = DAL.getLastArg(options::OPT__precompile))) {
241251
FinalPhase = phases::Precompile;
242252

243-
// -{fsyntax-only,-analyze,emit-ast} only run up to the compiler.
244-
} else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
245-
(PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
253+
// -{analyze,emit-ast} only run up to the compiler.
254+
} else if ((PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
246255
(PhaseArg = DAL.getLastArg(options::OPT_verify_pch)) ||
247256
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
248257
(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)