[Flang][Driver] Add infrastructure for basic frontend actions and file I/O
authorCaroline Concatto <caroline.concatto@arm.com>
Sat, 24 Oct 2020 11:33:19 +0000 (12:33 +0100)
committerAndrzej Warzynski <andrzej.warzynski@arm.com>
Sat, 24 Oct 2020 13:58:32 +0000 (14:58 +0100)
commit4c5906cffd04202387d2f6b50a47d39c0e4f2c0e
treed03c6ef3813c405e602a735f479723ee208c6586
parent65a36bbc3d79f4f23843ec632e86363bc87b02d9
[Flang][Driver] Add infrastructure for basic frontend actions and file I/O

This patch introduces the dependencies required to read and manage input files
provided by the command line option. It also adds the infrastructure to create
and write to output files. The output is sent to either stdout or a file
(specified with the `-o` flag).

Separately, in order to be able to test the code for file I/O, it adds
infrastructure to create frontend actions. As a basic testable example, it adds
the `InputOutputTest` FrontendAction. The sole purpose of this action is to
read a file from the command line and print it either to stdout or the output
file.  This action is run by using the `-test-io` flag also introduced in this
patch (available for `flang-new` and `flang-new -fc1`). With this patch:
```
flang-new -test-io input-file.f90
```
will read input-file.f90 and print it in the output file.

The `InputOutputTest` frontend action has been introduced primarily to
facilitate testing. It is hidden from users (i.e. it's only displayed with
`--help-hidden`). Currently Clang doesn’t have an equivalent action.

`-test-io` is used to trigger the InputOutputTest action in the Flang frontend
driver. This patch makes sure that “flang-new” forwards it to “flang-new -fc1"
by creating a preprocessor job. However, in Flang.cpp, `-test-io` is passed to
“flang-new -fc1” without `-E`. This way we make sure that the preprocessor is
_not_ run in the frontend driver. This is the desired behaviour: `-test-io`
should only read the input file and print it to the output stream.

co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>

Differential Revision: https://reviews.llvm.org/D87989
31 files changed:
clang/include/clang/Driver/Options.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/Types.cpp
clang/test/Driver/immediate-options.c
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/CompilerInvocation.h
flang/include/flang/Frontend/FrontendAction.h [new file with mode: 0644]
flang/include/flang/Frontend/FrontendActions.h [new file with mode: 0644]
flang/include/flang/Frontend/FrontendOptions.h
flang/include/flang/FrontendTool/Utils.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp [new file with mode: 0644]
flang/lib/Frontend/FrontendActions.cpp [new file with mode: 0644]
flang/lib/Frontend/FrontendOptions.cpp
flang/lib/FrontendTool/CMakeLists.txt
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Flang-Driver/driver-help-hidden.f90 [new file with mode: 0644]
flang/test/Flang-Driver/driver-help.f90
flang/test/Flang-Driver/emit-obj.f90
flang/test/Frontend/Inputs/hello-world.f90 [new file with mode: 0644]
flang/test/Frontend/input-output-file.f90 [new file with mode: 0644]
flang/test/Frontend/multiple-input-files.f90 [new file with mode: 0644]
flang/test/lit.cfg.py
flang/tools/flang-driver/fc1_main.cpp
flang/unittests/Frontend/CMakeLists.txt
flang/unittests/Frontend/CompilerInstanceTest.cpp
flang/unittests/Frontend/InputOutputTest.cpp [new file with mode: 0644]