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>();
|
[flang][driver] Add support for `-c` and `-emit-obj`
This patch adds a frontend action for emitting object files. While Flang
does not support code-generation, this action remains a placeholder.
This patch simply provides glue-code to connect the compiler driver
with the appropriate frontend action.
The new action is triggered with the `-c` compiler driver flag, i.e.
`flang-new -c`. This is then translated to `flang-new -fc1 -emit-obj`,
so `-emit-obj` has to be marked as supported as well.
As code-generation is not available yet, `flang-new -c` results in a
driver error:
```
error: code-generation is not available yet
```
Hopefully this will help communicating the level of available
functionality within Flang.
The definition of `emit-obj` is updated so that it can be shared between
Clang and Flang. As the original definition was enclosed within a
Clang-specific TableGen `let` statement, it is extracted into a new `let`
statement. That felt like the cleanest option.
I also commented out `-triple` in Flang::ConstructJob and updated some
comments there. This is similar to https://reviews.llvm.org/D93027. I
wanted to make sure that it's clear that we can't support `-triple`
until we have code-generation. However, once code-generation is
available we _will need_ `-triple`.
As this patch adds `-emit-obj`, the emit-obj.f90 becomes irrelevant and
is deleted. Instead, phases.f90 is added to demonstrate that users can
control compilation phases (indeed, `-c` is a phase control flag).
Reviewed By: SouraVX, clementval
Differential Revision: https://reviews.llvm.org/D93301
2021-01-07 17:08:54 +08:00
|
|
|
case EmitObj:
|
|
|
|
return std::make_unique<EmitObjAction>();
|
2020-12-09 00:27:46 +08:00
|
|
|
break;
|
2021-02-04 19:14:57 +08:00
|
|
|
case DebugUnparse:
|
|
|
|
return std::make_unique<DebugUnparseAction>();
|
|
|
|
break;
|
2021-03-30 18:35:42 +08:00
|
|
|
case DebugUnparseNoSema:
|
|
|
|
return std::make_unique<DebugUnparseNoSemaAction>();
|
|
|
|
break;
|
2021-02-04 19:14:57 +08:00
|
|
|
case DebugUnparseWithSymbols:
|
|
|
|
return std::make_unique<DebugUnparseWithSymbolsAction>();
|
|
|
|
break;
|
2021-02-17 23:55:56 +08:00
|
|
|
case DebugDumpSymbols:
|
|
|
|
return std::make_unique<DebugDumpSymbolsAction>();
|
|
|
|
break;
|
|
|
|
case DebugDumpParseTree:
|
|
|
|
return std::make_unique<DebugDumpParseTreeAction>();
|
|
|
|
break;
|
2021-03-30 18:35:42 +08:00
|
|
|
case DebugDumpParseTreeNoSema:
|
|
|
|
return std::make_unique<DebugDumpParseTreeNoSemaAction>();
|
|
|
|
break;
|
2021-06-15 23:30:23 +08:00
|
|
|
case DebugDumpAll:
|
|
|
|
return std::make_unique<DebugDumpAllAction>();
|
|
|
|
break;
|
2021-02-17 23:55:56 +08:00
|
|
|
case DebugDumpProvenance:
|
|
|
|
return std::make_unique<DebugDumpProvenanceAction>();
|
|
|
|
break;
|
2021-02-24 01:59:17 +08:00
|
|
|
case DebugDumpParsingLog:
|
|
|
|
return std::make_unique<DebugDumpParsingLogAction>();
|
|
|
|
break;
|
2021-02-18 02:53:05 +08:00
|
|
|
case DebugMeasureParseTree:
|
|
|
|
return std::make_unique<DebugMeasureParseTreeAction>();
|
|
|
|
break;
|
|
|
|
case DebugPreFIRTree:
|
|
|
|
return std::make_unique<DebugPreFIRTreeAction>();
|
|
|
|
break;
|
2021-04-14 18:43:14 +08:00
|
|
|
case GetDefinition:
|
|
|
|
return std::make_unique<GetDefinitionAction>();
|
|
|
|
break;
|
2021-03-09 00:54:11 +08:00
|
|
|
case GetSymbolsSources:
|
|
|
|
return std::make_unique<GetSymbolsSourcesAction>();
|
|
|
|
break;
|
2021-06-07 22:40:26 +08:00
|
|
|
case InitOnly:
|
|
|
|
return std::make_unique<InitOnlyAction>();
|
|
|
|
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
|