Coverage Report

Created: 2022-01-15 10:30

/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::AddFortranDialectOptions(const ArgList &Args,
23
17
                                     ArgStringList &CmdArgs) const {
24
17
  Args.AddAllArgs(
25
17
      CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form,
26
17
                options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp,
27
17
                options::OPT_fopenacc, options::OPT_finput_charset_EQ,
28
17
                options::OPT_fimplicit_none, options::OPT_fno_implicit_none,
29
17
                options::OPT_fbackslash, options::OPT_fno_backslash,
30
17
                options::OPT_flogical_abbreviations,
31
17
                options::OPT_fno_logical_abbreviations,
32
17
                options::OPT_fxor_operator, options::OPT_fno_xor_operator,
33
17
                options::OPT_falternative_parameter_statement,
34
17
                options::OPT_fdefault_real_8, options::OPT_fdefault_integer_8,
35
17
                options::OPT_fdefault_double_8, options::OPT_flarge_sizes,
36
17
                options::OPT_fno_automatic});
37
17
}
38
39
void Flang::AddPreprocessingOptions(const ArgList &Args,
40
17
                                    ArgStringList &CmdArgs) const {
41
17
  Args.AddAllArgs(CmdArgs,
42
17
                  {options::OPT_P, options::OPT_D, options::OPT_U,
43
17
                   options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
44
17
}
45
46
17
void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
47
17
  Args.AddAllArgs(CmdArgs,
48
17
                  {options::OPT_module_dir, options::OPT_fdebug_module_writer,
49
17
                   options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
50
17
                   options::OPT_std_EQ, options::OPT_W_Joined});
51
17
}
52
53
void Flang::ConstructJob(Compilation &C, const JobAction &JA,
54
                         const InputInfo &Output, const InputInfoList &Inputs,
55
17
                         const ArgList &Args, const char *LinkingOutput) const {
56
17
  const auto &TC = getToolChain();
57
  // TODO: Once code-generation is available, this will need to be commented
58
  // out.
59
  // const llvm::Triple &Triple = TC.getEffectiveTriple();
60
  // const std::string &TripleStr = Triple.getTriple();
61
62
17
  ArgStringList CmdArgs;
63
64
  // Invoke ourselves in -fc1 mode.
65
17
  CmdArgs.push_back("-fc1");
66
67
  // TODO: Once code-generation is available, this will need to be commented
68
  // out.
69
  // Add the "effective" target triple.
70
  // CmdArgs.push_back("-triple");
71
  // CmdArgs.push_back(Args.MakeArgString(TripleStr));
72
73
17
  if (isa<PreprocessJobAction>(JA)) {
74
2
      CmdArgs.push_back("-E");
75
15
  } else if (isa<CompileJobAction>(JA) || 
isa<BackendJobAction>(JA)8
) {
76
13
    if (JA.getType() == types::TY_Nothing) {
77
5
      CmdArgs.push_back("-fsyntax-only");
78
8
    } else if (JA.getType() == types::TY_AST) {
79
2
      CmdArgs.push_back("-emit-ast");
80
6
    } else if (JA.getType() == types::TY_LLVM_IR ||
81
6
               
JA.getType() == types::TY_LTO_IR4
) {
82
2
      CmdArgs.push_back("-emit-llvm");
83
4
    } else if (JA.getType() == types::TY_LLVM_BC ||
84
4
               
JA.getType() == types::TY_LTO_BC2
) {
85
2
      CmdArgs.push_back("-emit-llvm-bc");
86
2
    } else if (JA.getType() == types::TY_PP_Asm) {
87
2
      CmdArgs.push_back("-S");
88
2
    } else {
89
0
      assert(false && "Unexpected output type!");
90
0
    }
91
13
  } else 
if (2
isa<AssembleJobAction>(JA)2
) {
92
2
    CmdArgs.push_back("-emit-obj");
93
2
  } else {
94
0
    assert(false && "Unexpected action class for Flang tool.");
95
0
  }
96
97
0
  const InputInfo &Input = Inputs[0];
98
17
  types::ID InputType = Input.getType();
99
100
  // Add preprocessing options like -I, -D, etc. if we are using the
101
  // preprocessor (i.e. skip when dealing with e.g. binary files).
102
17
  if (types::getPreprocessedType(InputType) != types::TY_INVALID)
103
17
    AddPreprocessingOptions(Args, CmdArgs);
104
105
17
  AddFortranDialectOptions(Args, CmdArgs);
106
107
  // Add other compile options
108
17
  AddOtherOptions(Args, CmdArgs);
109
110
  // Forward -Xflang arguments to -fc1
111
17
  Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
112
113
17
  if (Output.isFilename()) {
114
12
    CmdArgs.push_back("-o");
115
12
    CmdArgs.push_back(Output.getFilename());
116
12
  } else {
117
5
    assert(Output.isNothing() && "Invalid output.");
118
5
  }
119
120
0
  assert(Input.isFilename() && "Invalid input.");
121
0
  CmdArgs.push_back(Input.getFilename());
122
123
17
  const auto& D = C.getDriver();
124
  // TODO: Replace flang-new with flang once the new driver replaces the
125
  // throwaway driver
126
17
  const char *Exec = Args.MakeArgString(D.GetProgramPath("flang-new", TC));
127
17
  C.addCommand(std::make_unique<Command>(JA, *this,
128
17
                                         ResponseFileSupport::AtFileUTF8(),
129
17
                                         Exec, CmdArgs, Inputs, Output));
130
17
}
131
132
16
Flang::Flang(const ToolChain &TC) : Tool("flang-new", "flang frontend", TC) {}
133
134
16
Flang::~Flang() {}