You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.2 KiB
91 lines
3.2 KiB
4 months ago
|
//===-- Flang.cpp - Flang+LLVM ToolChain Implementations --------*- C++ -*-===//
|
||
|
//
|
||
|
// 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
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
|
||
|
|
||
|
#include "Flang.h"
|
||
|
#include "CommonArgs.h"
|
||
|
|
||
|
#include "clang/Driver/Options.h"
|
||
|
|
||
|
#include <cassert>
|
||
|
|
||
|
using namespace clang::driver;
|
||
|
using namespace clang::driver::tools;
|
||
|
using namespace clang;
|
||
|
using namespace llvm::opt;
|
||
|
|
||
|
void Flang::ConstructJob(Compilation &C, const JobAction &JA,
|
||
|
const InputInfo &Output, const InputInfoList &Inputs,
|
||
|
const ArgList &Args, const char *LinkingOutput) const {
|
||
|
const auto &TC = getToolChain();
|
||
|
const llvm::Triple &Triple = TC.getEffectiveTriple();
|
||
|
const std::string &TripleStr = Triple.getTriple();
|
||
|
|
||
|
ArgStringList CmdArgs;
|
||
|
|
||
|
CmdArgs.push_back("-fc1");
|
||
|
|
||
|
// TODO: Eventually all actions will require a triple (e.g. `-triple
|
||
|
// aarch64-unknown-linux-gnu`). However, `-triple` is currently not supported
|
||
|
// by `flang-new -fc1`, so we only add it selectively to actions that we
|
||
|
// don't support/execute just yet.
|
||
|
if (isa<PreprocessJobAction>(JA)) {
|
||
|
if (C.getArgs().hasArg(options::OPT_test_io))
|
||
|
CmdArgs.push_back("-test-io");
|
||
|
else
|
||
|
CmdArgs.push_back("-E");
|
||
|
} else if (isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) {
|
||
|
CmdArgs.push_back("-triple");
|
||
|
CmdArgs.push_back(Args.MakeArgString(TripleStr));
|
||
|
if (JA.getType() == types::TY_Nothing) {
|
||
|
CmdArgs.push_back("-fsyntax-only");
|
||
|
} else if (JA.getType() == types::TY_AST) {
|
||
|
CmdArgs.push_back("-emit-ast");
|
||
|
} else if (JA.getType() == types::TY_LLVM_IR ||
|
||
|
JA.getType() == types::TY_LTO_IR) {
|
||
|
CmdArgs.push_back("-emit-llvm");
|
||
|
} else if (JA.getType() == types::TY_LLVM_BC ||
|
||
|
JA.getType() == types::TY_LTO_BC) {
|
||
|
CmdArgs.push_back("-emit-llvm-bc");
|
||
|
} else if (JA.getType() == types::TY_PP_Asm) {
|
||
|
CmdArgs.push_back("-S");
|
||
|
} else {
|
||
|
assert(false && "Unexpected output type!");
|
||
|
}
|
||
|
} else if (isa<AssembleJobAction>(JA)) {
|
||
|
CmdArgs.push_back("-triple");
|
||
|
CmdArgs.push_back(Args.MakeArgString(TripleStr));
|
||
|
CmdArgs.push_back("-emit-obj");
|
||
|
} else {
|
||
|
assert(false && "Unexpected action class for Flang tool.");
|
||
|
}
|
||
|
|
||
|
if (Output.isFilename()) {
|
||
|
CmdArgs.push_back("-o");
|
||
|
CmdArgs.push_back(Output.getFilename());
|
||
|
} else {
|
||
|
assert(Output.isNothing() && "Invalid output.");
|
||
|
}
|
||
|
|
||
|
const InputInfo &Input = Inputs[0];
|
||
|
assert(Input.isFilename() && "Invalid input.");
|
||
|
CmdArgs.push_back(Input.getFilename());
|
||
|
|
||
|
const auto& D = C.getDriver();
|
||
|
// TODO: Replace flang-new with flang once the new driver replaces the
|
||
|
// throwaway driver
|
||
|
const char *Exec = Args.MakeArgString(D.GetProgramPath("flang-new", TC));
|
||
|
C.addCommand(std::make_unique<Command>(JA, *this,
|
||
|
ResponseFileSupport::AtFileUTF8(),
|
||
|
Exec, CmdArgs, Inputs, Output));
|
||
|
}
|
||
|
|
||
|
Flang::Flang(const ToolChain &TC) : Tool("flang-new", "flang frontend", TC) {}
|
||
|
|
||
|
Flang::~Flang() {}
|