[PATCH] D63607: [DO NOT SUBMIT] [clang][driver] Prototype --driver-mode=fortran support for new flang
peterwaller-arm updated this revision to Diff 206172. peterwaller-arm added a comment. Include full context. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63607/new/ https://reviews.llvm.org/D63607 Files: clang/include/clang/Driver/Driver.h clang/include/clang/Driver/ToolChain.h clang/include/clang/Driver/Types.h clang/lib/Driver/CMakeLists.txt clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/Flang.cpp clang/lib/Driver/ToolChains/Flang.h clang/lib/Driver/Types.cpp clang/tools/driver/CMakeLists.txt clang/tools/driver/driver.cpp Index: clang/tools/driver/driver.cpp === --- clang/tools/driver/driver.cpp +++ clang/tools/driver/driver.cpp @@ -305,12 +305,24 @@ static int ExecuteCC1Tool(ArrayRef argv, StringRef Tool) { void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath; - if (Tool == "") + // DONOTSUBMIT(peterwaller-arm): Please note that changes to this logic are + // only to facilitate demonstrating that -fc1 is being invoked, and will not + // be submitted in a future implementation. + if (Tool == "-cc1") return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP); - if (Tool == "as") + if (Tool == "-cc1as") return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP); - if (Tool == "gen-reproducer") + if (Tool == "-cc1gen-reproducer") return cc1gen_reproducer_main(argv.slice(2), argv[0], GetExecutablePathVP); + if (Tool == "-fc1") { +llvm::errs() << "invoked flang frontend: "; +for (auto arg : argv) { + llvm::errs() << arg << " "; +} +llvm::errs() << "\n"; +return 1; + } + // Reject unknown tools. llvm::errs() << "error: unknown integrated tool '" << Tool << "'. " @@ -372,13 +384,18 @@ // file. auto FirstArg = std::find_if(argv.begin() + 1, argv.end(), [](const char *A) { return A != nullptr; }); - if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) { + // DONOTSUBMIT(peterwaller-arm): Please note that changes to this logic are + // only to facilitate demonstrating that -fc1 is being invoked, and will not + // be submitted in a future implementation. + if (FirstArg != argv.end() && ( +StringRef(*FirstArg).startswith("-cc1") || StringRef(*FirstArg).startswith("-fc1") +)) { // If -cc1 came from a response file, remove the EOL sentinels. if (MarkEOLs) { auto newEnd = std::remove(argv.begin(), argv.end(), nullptr); argv.resize(newEnd - argv.begin()); } -return ExecuteCC1Tool(argv, argv[1] + 4); +return ExecuteCC1Tool(argv, argv[1]); } bool CanonicalPrefixes = true; Index: clang/tools/driver/CMakeLists.txt === --- clang/tools/driver/CMakeLists.txt +++ clang/tools/driver/CMakeLists.txt @@ -63,7 +63,7 @@ add_dependencies(clang clang-resource-headers) if(NOT CLANG_LINKS_TO_CREATE) - set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp) + set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp flang) endif() foreach(link ${CLANG_LINKS_TO_CREATE}) Index: clang/lib/Driver/Types.cpp === --- clang/lib/Driver/Types.cpp +++ clang/lib/Driver/Types.cpp @@ -187,6 +187,16 @@ } } +bool types::isFortran(ID Id) { + switch (Id) { + default: +return false; + + case TY_Fortran: case TY_PP_Fortran: +return true; + } +} + bool types::isSrcFile(ID Id) { return Id != TY_Object && getPreprocessedType(Id) != TY_INVALID; } Index: clang/lib/Driver/ToolChains/Flang.h === --- /dev/null +++ clang/lib/Driver/ToolChains/Flang.h @@ -0,0 +1,48 @@ +//===--- Flang.h - Flang Tool and ToolChain Implementations -*- C++ -*-===// +// +// 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 +// +//===--===// + +#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_FLANG_H +#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_FLANG_H + +#include "MSVC.h" +#include "clang/Basic/DebugInfoOptions.h" +#include "clang/Driver/Driver.h" +#include "clang/Driver/Tool.h" +#include "clang/Driver/Types.h" +#include "llvm/ADT/Triple.h" +#include "llvm/Option/Option.h" +#include "llvm/Support/raw_ostream.h" + +namespace clang { +namespace driver { + +namespace tools { + +/// Flang compiler tool. +class LLVM_LIBRARY_VISIBILITY Flang : public Tool { +public: + Flang(const ToolChain ); + ~Flang() override; + + bool hasGoodDiagnostics() const override { return true; } + bool hasIntegratedAssembler() const override { return true; } + bool hasIntegratedCPP() const override { return true; } + bool canEmitIR() const override { return
[PATCH] D63607: [DO NOT SUBMIT] [clang][driver] Prototype --driver-mode=fortran support for new flang
Hahnfeld added a comment. Even though I know you didn't send the email yet, can you please upload the diff with full context? Thanks :-) Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63607/new/ https://reviews.llvm.org/D63607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D63607: [DO NOT SUBMIT] [clang][driver] Prototype --driver-mode=fortran support for new flang
peterwaller-arm added a comment. Note: In case you see this early, the email isn't yet sent to the list. I'll link it here when it is, likely tomorrow. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D63607/new/ https://reviews.llvm.org/D63607 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D63607: [DO NOT SUBMIT] [clang][driver] Prototype --driver-mode=fortran support for new flang
peterwaller-arm created this revision. Herald added subscribers: cfe-commits, kadircet, ilya-biryukov, mgorny. Herald added a project: clang. This is an early prototype, not intended for full review until after the general approach is agreed. The purpose is to stimulate discussion on the overall approach. Please see discussion in RFC posted to cfe-dev on 2019-06-20 titled "Adding a fortran mode to the clang driver for flang". This patch adds a new Fortran mode. When in fortran mode, the driver will invoke flang instead of falling back to the GCC toolchain as it would otherwise do. It is intended that a soon to be implemented binary in the flang project will import libclangDriver and run the clang driver in the new fortran mode. Along with the new mode comes a new ToolChains/Flang.cpp. As the flang frontend option parser is still prototypical, the implementation inside this file is not yet fleshed out. It's a straw man. Additionally, this patch makes "bin/flang" in the clang project, a symlink to clang. This is only there to support trying the patch out now, and will be removed when the real thing lands. Likewise, the patch adds a new "-fc1" by analogy with "-cc1" and tweaks the logic to facilitate that. This change is only to demonstrate the overall effect, and will not be present in the real patch. The action of -fc1 is just to print its command line arguments at the moment, which is redundant with `-###` anyway. I just wanted to see it invoke a stub flang with my own eyes. Repository: rC Clang https://reviews.llvm.org/D63607 Files: clang/include/clang/Driver/Driver.h clang/include/clang/Driver/ToolChain.h clang/include/clang/Driver/Types.h clang/lib/Driver/CMakeLists.txt clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/Flang.cpp clang/lib/Driver/ToolChains/Flang.h clang/lib/Driver/Types.cpp clang/tools/driver/CMakeLists.txt clang/tools/driver/driver.cpp Index: clang/tools/driver/driver.cpp === --- clang/tools/driver/driver.cpp +++ clang/tools/driver/driver.cpp @@ -305,12 +305,24 @@ static int ExecuteCC1Tool(ArrayRef argv, StringRef Tool) { void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath; - if (Tool == "") + // DONOTSUBMIT(peterwaller-arm): Please note that changes to this logic are + // only to facilitate demonstrating that -fc1 is being invoked, and will not + // be submitted in a future implementation. + if (Tool == "-cc1") return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP); - if (Tool == "as") + if (Tool == "-cc1as") return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP); - if (Tool == "gen-reproducer") + if (Tool == "-cc1gen-reproducer") return cc1gen_reproducer_main(argv.slice(2), argv[0], GetExecutablePathVP); + if (Tool == "-fc1") { +llvm::errs() << "invoked flang frontend: "; +for (auto arg : argv) { + llvm::errs() << arg << " "; +} +llvm::errs() << "\n"; +return 1; + } + // Reject unknown tools. llvm::errs() << "error: unknown integrated tool '" << Tool << "'. " @@ -372,13 +384,18 @@ // file. auto FirstArg = std::find_if(argv.begin() + 1, argv.end(), [](const char *A) { return A != nullptr; }); - if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) { + // DONOTSUBMIT(peterwaller-arm): Please note that changes to this logic are + // only to facilitate demonstrating that -fc1 is being invoked, and will not + // be submitted in a future implementation. + if (FirstArg != argv.end() && ( +StringRef(*FirstArg).startswith("-cc1") || StringRef(*FirstArg).startswith("-fc1") +)) { // If -cc1 came from a response file, remove the EOL sentinels. if (MarkEOLs) { auto newEnd = std::remove(argv.begin(), argv.end(), nullptr); argv.resize(newEnd - argv.begin()); } -return ExecuteCC1Tool(argv, argv[1] + 4); +return ExecuteCC1Tool(argv, argv[1]); } bool CanonicalPrefixes = true; Index: clang/tools/driver/CMakeLists.txt === --- clang/tools/driver/CMakeLists.txt +++ clang/tools/driver/CMakeLists.txt @@ -63,7 +63,7 @@ add_dependencies(clang clang-resource-headers) if(NOT CLANG_LINKS_TO_CREATE) - set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp) + set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp flang) endif() foreach(link ${CLANG_LINKS_TO_CREATE}) Index: clang/lib/Driver/Types.cpp === --- clang/lib/Driver/Types.cpp +++ clang/lib/Driver/Types.cpp @@ -187,6 +187,16 @@ } } +bool types::isFortran(ID Id) { + switch (Id) { + default: +return false; + + case TY_Fortran: case TY_PP_Fortran: +return true; + } +} + bool types::isSrcFile(ID Id) { return Id != TY_Object && getPreprocessedType(Id) != TY_INVALID; }