Coverage Report

Created: 2020-09-19 12:23

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