aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/FrontendTool
diff options
context:
space:
mode:
authorCaroline Concatto <caroline.concatto@arm.com>2020-09-11 10:17:31 +0100
committerCaroline Concatto <caroline.concatto@arm.com>2020-09-11 10:55:54 +0100
commit257b29715bb27b7d9f6c3c40c481b6a4af0b37e5 (patch)
tree2e3561b672b159815b904a87779f5bde71c097bb /flang/lib/FrontendTool
parent002f5ab3b171c7d9c9ea192b04a5303be78f6e52 (diff)
downloadllvm-257b29715bb27b7d9f6c3c40c481b6a4af0b37e5.zip
llvm-257b29715bb27b7d9f6c3c40c481b6a4af0b37e5.tar.gz
llvm-257b29715bb27b7d9f6c3c40c481b6a4af0b37e5.tar.bz2
[flang][driver] Add the new flang compiler and frontend drivers
Summary: This is the first patch implementing the new Flang driver as outlined in [1], [2] & [3]. It creates Flang driver (`flang-new`) and Flang frontend driver (`flang-new -fc1`). These will be renamed as `flang` and `flang -fc1` once the current Flang throwaway driver, `flang`, can be replaced with `flang-new`. Currently only 2 options are supported: `-help` and `--version`. `flang-new` is implemented in terms of libclangDriver, defaulting the driver mode to `FlangMode` (added to libclangDriver in [4]). This ensures that the driver runs in Flang mode regardless of the name of the binary inferred from argv[0]. The design of the new Flang compiler and frontend drivers is inspired by it counterparts in Clang [3]. Currently, the new Flang compiler and frontend drivers re-use Clang libraries: clangBasic, clangDriver and clangFrontend. To identify Flang options, this patch adds FlangOption/FC1Option enums. Driver::printHelp is updated so that `flang-new` prints only Flang options. The new Flang driver is disabled by default. To enable it, set `-DBUILD_FLANG_NEW_DRIVER=ON` when configuring CMake and add clang to `LLVM_ENABLE_PROJECTS` (e.g. -DLLVM_ENABLE_PROJECTS=“clang;flang;mlir”). [1] “RFC: new Flang driver - next steps” http://lists.llvm.org/pipermail/flang-dev/2020-July/000470.html [2] “RFC: Adding a fortran mode to the clang driver for flang” http://lists.llvm.org/pipermail/cfe-dev/2019-June/062669.html [3] “RFC: refactoring libclangDriver/libclangFrontend to share with Flang” http://lists.llvm.org/pipermail/cfe-dev/2020-July/066393.html [4] https://reviews.llvm.org/rG6bf55804924d5a1d902925ad080b1a2b57c5c75c co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com> Reviewed By: richard.barton.arm, sameeranjoshi Differential Revision: https://reviews.llvm.org/D86089
Diffstat (limited to 'flang/lib/FrontendTool')
-rw-r--r--flang/lib/FrontendTool/CMakeLists.txt11
-rw-r--r--flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp39
2 files changed, 50 insertions, 0 deletions
diff --git a/flang/lib/FrontendTool/CMakeLists.txt b/flang/lib/FrontendTool/CMakeLists.txt
new file mode 100644
index 0000000..eda040f
--- /dev/null
+++ b/flang/lib/FrontendTool/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_flang_library(flangFrontendTool
+ ExecuteCompilerInvocation.cpp
+
+ LINK_LIBS
+ clangBasic
+ clangDriver
+
+ LINK_COMPONENTS
+ Option
+ Support
+)
diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
new file mode 100644
index 0000000..ab773c9
--- /dev/null
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -0,0 +1,39 @@
+//===--- ExecuteCompilerInvocation.cpp ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file holds ExecuteCompilerInvocation(). It is split into its own file to
+// minimize the impact of pulling in essentially everything else in Flang.
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Frontend/CompilerInstance.h"
+#include "clang/Driver/Options.h"
+#include "llvm/Option/OptTable.h"
+#include "llvm/Support/CommandLine.h"
+
+namespace Fortran::frontend {
+bool ExecuteCompilerInvocation(CompilerInstance *flang) {
+ // Honor -help.
+ if (flang->GetFrontendOpts().showHelp_) {
+ clang::driver::getDriverOptTable().PrintHelp(llvm::outs(),
+ "flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler",
+ /*Include=*/clang::driver::options::FlangOption,
+ /*Exclude=*/0, /*ShowAllAliases=*/false);
+ return true;
+ }
+
+ // Honor -version.
+ if (flang->GetFrontendOpts().showVersion_) {
+ llvm::cl::PrintVersionMessage();
+ return true;
+ }
+
+ return true;
+}
+
+} // namespace Fortran::frontend