mirror of
https://github.com/intel/llvm.git
synced 2026-01-30 14:07:28 +08:00
The behaviour triggered with this flag is consistent with `-fparse-only` in `flang` (i.e. the throwaway driver). This new spelling is consistent with Clang and gfortran, and was proposed and agreed on for the new driver in [1]. This patch also adds some minimal logic to communicate whether the semantic checks have failed or not. When semantic checks fail, a frontend driver error is generated. The return code from the frontend driver is then determined by checking the driver diagnostics - the presence of driver errors means that the compilation has failed. This logic is consistent with `clang -cc1`. [1] http://lists.llvm.org/pipermail/flang-dev/2020-November/000588.html Differential Revision: https://reviews.llvm.org/D92854
86 lines
2.5 KiB
C++
86 lines
2.5 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>();
|
|
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
|