[Flang][Driver] Add PrintPreprocessedInput FrontendAction (`flang-new -E`)
authorCaroline Concatto <caroline.concatto@arm.com>
Tue, 27 Oct 2020 12:26:47 +0000 (12:26 +0000)
committerAndrzej Warzynski <andrzej.warzynski@arm.com>
Mon, 2 Nov 2020 14:03:35 +0000 (14:03 +0000)
commitd28de0d7f257bbe4703f3449f1672f1744cf306b
treef3bdc9fca200ee3a1cb4d8859b38980cf3bcb4d3
parent274de447fe9621082a523a7227157aeb84702a7d
[Flang][Driver] Add PrintPreprocessedInput FrontendAction (`flang-new -E`)

This patch implements the first frontend action for the Flang parser (i.e.
Fortran::parser). This action runs the preprocessor and is invoked with the
`-E` flag. (i.e. `flang-new -E <input-file>). The generated output is printed
to either stdout or the output file (specified with `-` or `-o <output-file>`).

Note that currently there is no mechanism to map options for the
frontend driver (i.e. Fortran::frontend::FrontendOptions) to options for
the parser (i.e. Fortran::parser::Options). Instead,
Frotran::parser::options are hard-coded to:

```
std::vector<std::string> searchDirectories{"."s};
searchDirectories = searchDirectories;
isFixedForm = false;
_encoding(Fortran::parser::Encoding::UTF_8);
```

These default settings are compatible with the current Flang driver. Further
work is required in order for CompilerInvocation to read and map
clang::driver::options to Fortran::parser::options.

Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
Differential Revision: https://reviews.llvm.org/D88381
17 files changed:
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/CompilerInvocation.h
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90
flang/test/Frontend/Inputs/hello-world.c [new file with mode: 0644]
flang/test/Frontend/print-preprocess-C-file.f90 [new file with mode: 0644]
flang/test/Frontend/print-preprocessed-file.f90 [new file with mode: 0644]
flang/unittests/Frontend/CMakeLists.txt
flang/unittests/Frontend/PrintPreprocessedTest.cpp [new file with mode: 0644]