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.frontendOpts().programAction_; 28 switch (ak) { 29 case InputOutputTest: 30 return std::make_unique<InputOutputTestAction>(); 31 break; 32 case PrintPreprocessedInput: 33 return std::make_unique<PrintPreprocessedAction>(); 34 break; 35 case ParseSyntaxOnly: 36 return std::make_unique<ParseSyntaxOnlyAction>(); 37 case EmitObj: 38 return std::make_unique<EmitObjAction>(); 39 break; 40 case DebugUnparse: 41 return std::make_unique<DebugUnparseAction>(); 42 break; 43 case DebugUnparseWithSymbols: 44 return std::make_unique<DebugUnparseWithSymbolsAction>(); 45 break; 46 case DebugDumpSymbols: 47 return std::make_unique<DebugDumpSymbolsAction>(); 48 break; 49 case DebugDumpParseTree: 50 return std::make_unique<DebugDumpParseTreeAction>(); 51 break; 52 case DebugDumpProvenance: 53 return std::make_unique<DebugDumpProvenanceAction>(); 54 break; 55 case DebugDumpParsingLog: 56 return std::make_unique<DebugDumpParsingLogAction>(); 57 break; 58 case DebugMeasureParseTree: 59 return std::make_unique<DebugMeasureParseTreeAction>(); 60 break; 61 case DebugPreFIRTree: 62 return std::make_unique<DebugPreFIRTreeAction>(); 63 break; 64 case GetSymbolsSources: 65 return std::make_unique<GetSymbolsSourcesAction>(); 66 break; 67 default: 68 break; 69 // TODO: 70 // case RunPreprocessor: 71 // case ParserSyntaxOnly: 72 // case EmitLLVM: 73 // case EmitLLVMOnly: 74 // case EmitCodeGenOnly: 75 // (...) 76 } 77 return 0; 78 } 79 80 std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci) { 81 // Create the underlying action. 82 std::unique_ptr<FrontendAction> act = CreateFrontendBaseAction(ci); 83 if (!act) 84 return nullptr; 85 86 return act; 87 } 88 bool ExecuteCompilerInvocation(CompilerInstance *flang) { 89 // Honor -help. 90 if (flang->frontendOpts().showHelp_) { 91 clang::driver::getDriverOptTable().PrintHelp(llvm::outs(), 92 "flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler", 93 /*Include=*/clang::driver::options::FC1Option, 94 /*Exclude=*/llvm::opt::DriverFlag::HelpHidden, 95 /*ShowAllAliases=*/false); 96 return true; 97 } 98 99 // Honor -version. 100 if (flang->frontendOpts().showVersion_) { 101 llvm::cl::PrintVersionMessage(); 102 return true; 103 } 104 105 // Create and execute the frontend action. 106 std::unique_ptr<FrontendAction> act(CreateFrontendAction(*flang)); 107 if (!act) 108 return false; 109 110 bool success = flang->ExecuteAction(*act); 111 return success; 112 } 113 114 } // namespace Fortran::frontend 115