The new option will run the semantic checks and then dump the parse tree and all the symbols. This is equivalent to running the driver twice, once with `-fdebug-dump-parse-tree` and then with the `-fdebug-dump-symbols` action flag. Currently we wouldn't be able to achieve the same by simply running: ``` flang-new -fc1 -fdebug-dump-parse-tree -fdebug-dump-symbols <input-file> ``` That's because the new driver will only run one frontend action per invocation (both of the flags used here are action flags). Diverging from this design would lead to costly compromises and it's best avoided. We may want to consider re-designing our debugging actions (and action options) in the future so that there's more code re-use. For now, I'm focusing on making sure that we support all the major cases requested by our users. Differential Revision: https://reviews.llvm.org/D104305
130 lines
3.8 KiB
C++
130 lines
3.8 KiB
C++
//===--- 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 "flang/Frontend/FrontendActions.h"
|
|
#include "clang/Driver/Options.h"
|
|
#include "llvm/Option/OptTable.h"
|
|
#include "llvm/Option/Option.h"
|
|
#include "llvm/Support/BuryPointer.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
namespace Fortran::frontend {
|
|
|
|
static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
|
|
CompilerInstance &ci) {
|
|
|
|
ActionKind ak = ci.frontendOpts().programAction_;
|
|
switch (ak) {
|
|
case InputOutputTest:
|
|
return std::make_unique<InputOutputTestAction>();
|
|
break;
|
|
case PrintPreprocessedInput:
|
|
return std::make_unique<PrintPreprocessedAction>();
|
|
break;
|
|
case ParseSyntaxOnly:
|
|
return std::make_unique<ParseSyntaxOnlyAction>();
|
|
case EmitObj:
|
|
return std::make_unique<EmitObjAction>();
|
|
break;
|
|
case DebugUnparse:
|
|
return std::make_unique<DebugUnparseAction>();
|
|
break;
|
|
case DebugUnparseNoSema:
|
|
return std::make_unique<DebugUnparseNoSemaAction>();
|
|
break;
|
|
case DebugUnparseWithSymbols:
|
|
return std::make_unique<DebugUnparseWithSymbolsAction>();
|
|
break;
|
|
case DebugDumpSymbols:
|
|
return std::make_unique<DebugDumpSymbolsAction>();
|
|
break;
|
|
case DebugDumpParseTree:
|
|
return std::make_unique<DebugDumpParseTreeAction>();
|
|
break;
|
|
case DebugDumpParseTreeNoSema:
|
|
return std::make_unique<DebugDumpParseTreeNoSemaAction>();
|
|
break;
|
|
case DebugDumpAll:
|
|
return std::make_unique<DebugDumpAllAction>();
|
|
break;
|
|
case DebugDumpProvenance:
|
|
return std::make_unique<DebugDumpProvenanceAction>();
|
|
break;
|
|
case DebugDumpParsingLog:
|
|
return std::make_unique<DebugDumpParsingLogAction>();
|
|
break;
|
|
case DebugMeasureParseTree:
|
|
return std::make_unique<DebugMeasureParseTreeAction>();
|
|
break;
|
|
case DebugPreFIRTree:
|
|
return std::make_unique<DebugPreFIRTreeAction>();
|
|
break;
|
|
case GetDefinition:
|
|
return std::make_unique<GetDefinitionAction>();
|
|
break;
|
|
case GetSymbolsSources:
|
|
return std::make_unique<GetSymbolsSourcesAction>();
|
|
break;
|
|
case InitOnly:
|
|
return std::make_unique<InitOnlyAction>();
|
|
break;
|
|
default:
|
|
break;
|
|
// TODO:
|
|
// case RunPreprocessor:
|
|
// case ParserSyntaxOnly:
|
|
// case EmitLLVM:
|
|
// case EmitLLVMOnly:
|
|
// case EmitCodeGenOnly:
|
|
// (...)
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
std::unique_ptr<FrontendAction> CreateFrontendAction(CompilerInstance &ci) {
|
|
// Create the underlying action.
|
|
std::unique_ptr<FrontendAction> act = CreateFrontendBaseAction(ci);
|
|
if (!act)
|
|
return nullptr;
|
|
|
|
return act;
|
|
}
|
|
bool ExecuteCompilerInvocation(CompilerInstance *flang) {
|
|
// Honor -help.
|
|
if (flang->frontendOpts().showHelp_) {
|
|
clang::driver::getDriverOptTable().PrintHelp(llvm::outs(),
|
|
"flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler",
|
|
/*Include=*/clang::driver::options::FC1Option,
|
|
/*Exclude=*/llvm::opt::DriverFlag::HelpHidden,
|
|
/*ShowAllAliases=*/false);
|
|
return true;
|
|
}
|
|
|
|
// Honor -version.
|
|
if (flang->frontendOpts().showVersion_) {
|
|
llvm::cl::PrintVersionMessage();
|
|
return true;
|
|
}
|
|
|
|
// Create and execute the frontend action.
|
|
std::unique_ptr<FrontendAction> act(CreateFrontendAction(*flang));
|
|
if (!act)
|
|
return false;
|
|
|
|
bool success = flang->ExecuteAction(*act);
|
|
return success;
|
|
}
|
|
|
|
} // namespace Fortran::frontend
|