aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend
diff options
context:
space:
mode:
authorpeter klausler <pklausler@nvidia.com>2021-07-23 16:41:04 -0700
committerpeter klausler <pklausler@nvidia.com>2021-07-30 15:13:56 -0700
commit3338ef93b02837edf69abc203e15a42fa55aa1b3 (patch)
tree0fb8f1461450b302d91246d01b2b30f5247e2dca /flang/lib/Frontend
parent3df649e6191516547c6ddbcf26d507cd9b824519 (diff)
downloadllvm-3338ef93b02837edf69abc203e15a42fa55aa1b3.zip
llvm-3338ef93b02837edf69abc203e15a42fa55aa1b3.tar.gz
llvm-3338ef93b02837edf69abc203e15a42fa55aa1b3.tar.bz2
[flang] Produce proper "preprocessor output" for -E option
Rename the current -E option to "-E -Xflang -fno-reformat". Add a new Parsing::EmitPreprocessedSource() routine to convert the cooked character stream output of the prescanner back to something more closely resembling output from a traditional preprocessor; call this new routine when -E appears. The new -E output is suitable for use as fixed form Fortran source to compilation by (one hopes) any Fortran compiler. If the original top-level source file had been free form source, the output will be suitable for use as free form source as well; otherwise there may be diagnostics about missing spaces if they were indeed absent in the original fixed form source. Unless the -P option appears, #line directives are interspersed with the output (but be advised, f18 will ignore these if presented with them in a later compilation). An effort has been made to preserve original alphabetic character case and source indentation. Add -P and -fno-reformat to the new drivers. Tweak test options to avoid confusion with prior -E output; use -fno-reformat where needed, but prefer to keep -E, sometimes in concert with -P, on most, updating expected results accordingly. Differential Revision: https://reviews.llvm.org/D106727
Diffstat (limited to 'flang/lib/Frontend')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp3
-rw-r--r--flang/lib/Frontend/FrontendActions.cpp12
-rw-r--r--flang/lib/Frontend/FrontendOptions.cpp1
3 files changed, 11 insertions, 5 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 6a2bf19..bd79b01 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -371,6 +371,9 @@ static void parsePreprocessorArgs(
(currentArg->getOption().matches(clang::driver::options::OPT_cpp))
? PPMacrosFlag::Include
: PPMacrosFlag::Exclude;
+
+ opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat);
+ opts.noLineDirectives = args.hasArg(clang::driver::options::OPT_P);
}
/// Parses all semantic related arguments and populates the variables
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index fae0584..9ec751b 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -208,9 +208,14 @@ void PrintPreprocessedAction::ExecuteAction() {
std::string buf;
llvm::raw_string_ostream outForPP{buf};
- // Run the preprocessor
+ // Format or dump the prescanner's output
CompilerInstance &ci = this->instance();
- ci.parsing().DumpCookedChars(outForPP);
+ if (ci.invocation().preprocessorOpts().noReformat) {
+ ci.parsing().DumpCookedChars(outForPP);
+ } else {
+ ci.parsing().EmitPreprocessedSource(
+ outForPP, !ci.invocation().preprocessorOpts().noLineDirectives);
+ }
// If a pre-defined output stream exists, dump the preprocessed content there
if (!ci.IsOutputStreamNull()) {
@@ -219,7 +224,7 @@ void PrintPreprocessedAction::ExecuteAction() {
return;
}
- // Print diagnostics from the preprocessor
+ // Print diagnostics from the prescanner
ci.parsing().messages().Emit(llvm::errs(), ci.allCookedSources());
// Create a file and save the preprocessed output there
@@ -228,7 +233,6 @@ void PrintPreprocessedAction::ExecuteAction() {
(*os) << outForPP.str();
} else {
llvm::errs() << "Unable to create the output file\n";
- return;
}
}
diff --git a/flang/lib/Frontend/FrontendOptions.cpp b/flang/lib/Frontend/FrontendOptions.cpp
index dcad975..886baa3 100644
--- a/flang/lib/Frontend/FrontendOptions.cpp
+++ b/flang/lib/Frontend/FrontendOptions.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "flang/Frontend/FrontendOptions.h"
-#include "flang/Evaluate/expression.h"
using namespace Fortran::frontend;