Coverage Report

Created: 2021-01-19 06:58

/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::AddPreprocessingOptions(const ArgList &Args,
23
17
                                    ArgStringList &CmdArgs) const {
24
17
  Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U});
25
17
}
26
27
void Flang::ConstructJob(Compilation &C, const JobAction &JA,
28
                         const InputInfo &Output, const InputInfoList &Inputs,
29
17
                         const ArgList &Args, const char *LinkingOutput) const {
30
17
  const auto &TC = getToolChain();
31
  // TODO: Once code-generation is available, this will need to be commented
32
  // out.
33
  // const llvm::Triple &Triple = TC.getEffectiveTriple();
34
  // const std::string &TripleStr = Triple.getTriple();
35
36
17
  ArgStringList CmdArgs;
37
38
  // Invoke ourselves in -fc1 mode.
39
17
  CmdArgs.push_back("-fc1");
40
41
  // TODO: Once code-generation is available, this will need to be commented
42
  // out.
43
  // Add the "effective" target triple.
44
  // CmdArgs.push_back("-triple");
45
  // CmdArgs.push_back(Args.MakeArgString(TripleStr));
46
47
17
  if (isa<PreprocessJobAction>(JA)) {
48
2
    if (C.getArgs().hasArg(options::OPT_test_io))
49
0
      CmdArgs.push_back("-test-io");
50
2
    else
51
2
      CmdArgs.push_back("-E");
52
15
  } else if (isa<CompileJobAction>(JA) || 
isa<BackendJobAction>(JA)8
) {
53
13
    if (JA.getType() == types::TY_Nothing) {
54
5
      CmdArgs.push_back("-fsyntax-only");
55
8
    } else if (JA.getType() == types::TY_AST) {
56
2
      CmdArgs.push_back("-emit-ast");
57
6
    } else if (JA.getType() == types::TY_LLVM_IR ||
58
4
               JA.getType() == types::TY_LTO_IR) {
59
2
      CmdArgs.push_back("-emit-llvm");
60
4
    } else if (JA.getType() == types::TY_LLVM_BC ||
61
2
               JA.getType() == types::TY_LTO_BC) {
62
2
      CmdArgs.push_back("-emit-llvm-bc");
63
2
    } else if (JA.getType() == types::TY_PP_Asm) {
64
2
      CmdArgs.push_back("-S");
65
0
    } else {
66
0
      assert(false && "Unexpected output type!");
67
0
    }
68
2
  } else if (isa<AssembleJobAction>(JA)) {
69
2
    CmdArgs.push_back("-emit-obj");
70
0
  } else {
71
0
    assert(false && "Unexpected action class for Flang tool.");
72
0
  }
73
74
17
  const InputInfo &Input = Inputs[0];
75
17
  types::ID InputType = Input.getType();
76
77
  // Add preprocessing options like -I, -D, etc. if we are using the
78
  // preprocessor (i.e. skip when dealing with e.g. binary files).
79
17
  if (types::getPreprocessedType(InputType) != types::TY_INVALID)
80
17
    AddPreprocessingOptions(Args, CmdArgs);
81
82
17
  if (Output.isFilename()) {
83
12
    CmdArgs.push_back("-o");
84
12
    CmdArgs.push_back(Output.getFilename());
85
5
  } else {
86
5
    assert(Output.isNothing() && "Invalid output.");
87
5
  }
88
89
17
  assert(Input.isFilename() && "Invalid input.");
90
17
  CmdArgs.push_back(Input.getFilename());
91
92
17
  const auto& D = C.getDriver();
93
  // TODO: Replace flang-new with flang once the new driver replaces the
94
  // throwaway driver
95
17
  const char *Exec = Args.MakeArgString(D.GetProgramPath("flang-new", TC));
96
17
  C.addCommand(std::make_unique<Command>(JA, *this,
97
17
                                         ResponseFileSupport::AtFileUTF8(),
98
17
                                         Exec, CmdArgs, Inputs, Output));
99
17
}
100
101
16
Flang::Flang(const ToolChain &TC) : Tool("flang-new", "flang frontend", TC) {}
102
103
16
Flang::~Flang() {}