1 //===--- ExecuteCompilerInvocation.cpp ------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file holds ExecuteCompilerInvocation(). It is split into its own file to 10 // minimize the impact of pulling in essentially everything else in Flang. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "flang/Frontend/CompilerInstance.h" 15 #include "flang/Frontend/FrontendActions.h" 16 #include "clang/Driver/Options.h" 17 #include "llvm/Option/OptTable.h" 18 #include "llvm/Option/Option.h" 19 #include "llvm/Support/BuryPointer.h" 20 #include "llvm/Support/CommandLine.h" 21 22 namespace Fortran::frontend { 23 24 static std::unique_ptr<FrontendAction> CreateFrontendBaseAction( 25 CompilerInstance &ci) { 26 27 ActionKind ak = ci.GetFrontendOpts().programAction_; 28 switch (ak) { 29 case InputOutputTest: 30 return std::make_unique<InputOutputTestAction>(); 31 break; 32 default: 33 break; 34 // TODO: 35 // case RunPreprocessor: 36 // case ParserSyntaxOnly: 37 // case EmitLLVM: 38 // case EmitLLVMOnly: 39 // case EmitCodeGenOnly: 40 // (...) 41 } 42 return 0; 43 } 44 45 std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci) { 46 // Create the underlying action. 47 std::unique_ptr<FrontendAction> act = CreateFrontendBaseAction(ci); 48 if (!act) 49 return nullptr; 50 51 return act; 52 } 53 bool ExecuteCompilerInvocation(CompilerInstance *flang) { 54 // Honor -help. 55 if (flang->GetFrontendOpts().showHelp_) { 56 clang::driver::getDriverOptTable().PrintHelp(llvm::outs(), 57 "flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler", 58 /*Include=*/clang::driver::options::FC1Option, 59 /*Exclude=*/llvm::opt::DriverFlag::HelpHidden, 60 /*ShowAllAliases=*/false); 61 return true; 62 } 63 64 // Honor -version. 65 if (flang->GetFrontendOpts().showVersion_) { 66 llvm::cl::PrintVersionMessage(); 67 return true; 68 } 69 70 // Create and execute the frontend action. 71 std::unique_ptr<FrontendAction> act(CreateFrontendAction(*flang)); 72 if (!act) 73 return false; 74 75 bool success = flang->ExecuteAction(*act); 76 return success; 77 } 78 79 } // namespace Fortran::frontend 80