2020-09-11 17:17:31 +08:00
|
|
|
//===--- 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"
|
2020-10-24 19:33:19 +08:00
|
|
|
#include "flang/Frontend/FrontendActions.h"
|
2020-09-11 17:17:31 +08:00
|
|
|
#include "clang/Driver/Options.h"
|
|
|
|
#include "llvm/Option/OptTable.h"
|
2020-10-24 19:33:19 +08:00
|
|
|
#include "llvm/Option/Option.h"
|
|
|
|
#include "llvm/Support/BuryPointer.h"
|
2020-09-11 17:17:31 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
|
|
|
|
namespace Fortran::frontend {
|
2020-10-24 19:33:19 +08:00
|
|
|
|
|
|
|
static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
|
|
|
|
CompilerInstance &ci) {
|
|
|
|
|
2020-10-28 18:47:48 +08:00
|
|
|
ActionKind ak = ci.frontendOpts().programAction_;
|
2020-10-24 19:33:19 +08:00
|
|
|
switch (ak) {
|
|
|
|
case InputOutputTest:
|
|
|
|
return std::make_unique<InputOutputTestAction>();
|
|
|
|
break;
|
2020-10-27 20:26:47 +08:00
|
|
|
case PrintPreprocessedInput:
|
|
|
|
return std::make_unique<PrintPreprocessedAction>();
|
|
|
|
break;
|
2020-12-09 00:27:46 +08:00
|
|
|
case ParseSyntaxOnly:
|
|
|
|
return std::make_unique<ParseSyntaxOnlyAction>();
|
|
|
|
break;
|
2020-10-24 19:33:19 +08:00
|
|
|
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;
|
|
|
|
}
|
2020-09-11 17:17:31 +08:00
|
|
|
bool ExecuteCompilerInvocation(CompilerInstance *flang) {
|
|
|
|
// Honor -help.
|
2020-10-28 18:47:48 +08:00
|
|
|
if (flang->frontendOpts().showHelp_) {
|
2020-09-11 17:17:31 +08:00
|
|
|
clang::driver::getDriverOptTable().PrintHelp(llvm::outs(),
|
|
|
|
"flang-new -fc1 [options] file...", "LLVM 'Flang' Compiler",
|
2020-09-23 02:08:18 +08:00
|
|
|
/*Include=*/clang::driver::options::FC1Option,
|
2020-10-24 19:33:19 +08:00
|
|
|
/*Exclude=*/llvm::opt::DriverFlag::HelpHidden,
|
|
|
|
/*ShowAllAliases=*/false);
|
2020-09-11 17:17:31 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Honor -version.
|
2020-10-28 18:47:48 +08:00
|
|
|
if (flang->frontendOpts().showVersion_) {
|
2020-09-11 17:17:31 +08:00
|
|
|
llvm::cl::PrintVersionMessage();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-24 19:33:19 +08:00
|
|
|
// Create and execute the frontend action.
|
|
|
|
std::unique_ptr<FrontendAction> act(CreateFrontendAction(*flang));
|
|
|
|
if (!act)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool success = flang->ExecuteAction(*act);
|
|
|
|
return success;
|
2020-09-11 17:17:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Fortran::frontend
|