1*480093f4SDimitry Andric //===-- Flang.cpp - Flang+LLVM ToolChain Implementations --------*- C++ -*-===// 2*480093f4SDimitry Andric // 3*480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*480093f4SDimitry Andric // 7*480093f4SDimitry Andric //===----------------------------------------------------------------------===// 8*480093f4SDimitry Andric 9*480093f4SDimitry Andric 10*480093f4SDimitry Andric #include "Flang.h" 11*480093f4SDimitry Andric #include "CommonArgs.h" 12*480093f4SDimitry Andric 13*480093f4SDimitry Andric #include "clang/Driver/Options.h" 14*480093f4SDimitry Andric 15*480093f4SDimitry Andric #include <cassert> 16*480093f4SDimitry Andric 17*480093f4SDimitry Andric using namespace clang::driver; 18*480093f4SDimitry Andric using namespace clang::driver::tools; 19*480093f4SDimitry Andric using namespace clang; 20*480093f4SDimitry Andric using namespace llvm::opt; 21*480093f4SDimitry Andric 22*480093f4SDimitry Andric void Flang::ConstructJob(Compilation &C, const JobAction &JA, 23*480093f4SDimitry Andric const InputInfo &Output, const InputInfoList &Inputs, 24*480093f4SDimitry Andric const ArgList &Args, const char *LinkingOutput) const { 25*480093f4SDimitry Andric const auto &TC = getToolChain(); 26*480093f4SDimitry Andric const llvm::Triple &Triple = TC.getEffectiveTriple(); 27*480093f4SDimitry Andric const std::string &TripleStr = Triple.getTriple(); 28*480093f4SDimitry Andric 29*480093f4SDimitry Andric ArgStringList CmdArgs; 30*480093f4SDimitry Andric 31*480093f4SDimitry Andric CmdArgs.push_back("-fc1"); 32*480093f4SDimitry Andric 33*480093f4SDimitry Andric CmdArgs.push_back("-triple"); 34*480093f4SDimitry Andric CmdArgs.push_back(Args.MakeArgString(TripleStr)); 35*480093f4SDimitry Andric 36*480093f4SDimitry Andric if (isa<PreprocessJobAction>(JA)) { 37*480093f4SDimitry Andric CmdArgs.push_back("-E"); 38*480093f4SDimitry Andric } else if (isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) { 39*480093f4SDimitry Andric if (JA.getType() == types::TY_Nothing) { 40*480093f4SDimitry Andric CmdArgs.push_back("-fsyntax-only"); 41*480093f4SDimitry Andric } else if (JA.getType() == types::TY_AST) { 42*480093f4SDimitry Andric CmdArgs.push_back("-emit-ast"); 43*480093f4SDimitry Andric } else if (JA.getType() == types::TY_LLVM_IR || 44*480093f4SDimitry Andric JA.getType() == types::TY_LTO_IR) { 45*480093f4SDimitry Andric CmdArgs.push_back("-emit-llvm"); 46*480093f4SDimitry Andric } else if (JA.getType() == types::TY_LLVM_BC || 47*480093f4SDimitry Andric JA.getType() == types::TY_LTO_BC) { 48*480093f4SDimitry Andric CmdArgs.push_back("-emit-llvm-bc"); 49*480093f4SDimitry Andric } else if (JA.getType() == types::TY_PP_Asm) { 50*480093f4SDimitry Andric CmdArgs.push_back("-S"); 51*480093f4SDimitry Andric } else { 52*480093f4SDimitry Andric assert(false && "Unexpected output type!"); 53*480093f4SDimitry Andric } 54*480093f4SDimitry Andric } else if (isa<AssembleJobAction>(JA)) { 55*480093f4SDimitry Andric CmdArgs.push_back("-emit-obj"); 56*480093f4SDimitry Andric } else { 57*480093f4SDimitry Andric assert(false && "Unexpected action class for Flang tool."); 58*480093f4SDimitry Andric } 59*480093f4SDimitry Andric 60*480093f4SDimitry Andric if (Output.isFilename()) { 61*480093f4SDimitry Andric CmdArgs.push_back("-o"); 62*480093f4SDimitry Andric CmdArgs.push_back(Output.getFilename()); 63*480093f4SDimitry Andric } else { 64*480093f4SDimitry Andric assert(Output.isNothing() && "Invalid output."); 65*480093f4SDimitry Andric } 66*480093f4SDimitry Andric 67*480093f4SDimitry Andric const InputInfo &Input = Inputs[0]; 68*480093f4SDimitry Andric assert(Input.isFilename() && "Invalid input."); 69*480093f4SDimitry Andric CmdArgs.push_back(Input.getFilename()); 70*480093f4SDimitry Andric 71*480093f4SDimitry Andric const auto& D = C.getDriver(); 72*480093f4SDimitry Andric const char* Exec = Args.MakeArgString(D.GetProgramPath("flang", TC)); 73*480093f4SDimitry Andric C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); 74*480093f4SDimitry Andric } 75*480093f4SDimitry Andric 76*480093f4SDimitry Andric Flang::Flang(const ToolChain &TC) 77*480093f4SDimitry Andric : Tool("flang", "flang frontend", TC, RF_Full) {} 78*480093f4SDimitry Andric 79*480093f4SDimitry Andric Flang::~Flang() {} 80