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
88 lines
2.6 KiB
C++
88 lines
2.6 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;
|
|
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
|