Coverage Report

Created: 2020-09-22 08:39

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/XCore.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- XCore.cpp - XCore 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
#include "XCore.h"
10
#include "CommonArgs.h"
11
#include "clang/Driver/Compilation.h"
12
#include "clang/Driver/Driver.h"
13
#include "clang/Driver/Options.h"
14
#include "llvm/Option/ArgList.h"
15
#include <cstdlib> // ::getenv
16
17
using namespace clang::driver;
18
using namespace clang::driver::toolchains;
19
using namespace clang;
20
using namespace llvm::opt;
21
22
/// XCore Tools
23
// We pass assemble and link construction to the xcc tool.
24
25
void tools::XCore::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
26
                                           const InputInfo &Output,
27
                                           const InputInfoList &Inputs,
28
                                           const ArgList &Args,
29
5
                                           const char *LinkingOutput) const {
30
5
  claimNoWarnArgs(Args);
31
5
  ArgStringList CmdArgs;
32
33
5
  CmdArgs.push_back("-o");
34
5
  CmdArgs.push_back(Output.getFilename());
35
36
5
  CmdArgs.push_back("-c");
37
38
5
  if (Args.hasArg(options::OPT_v))
39
2
    CmdArgs.push_back("-v");
40
41
5
  if (Arg *A = Args.getLastArg(options::OPT_g_Group))
42
3
    if (!A->getOption().matches(options::OPT_g0))
43
2
      CmdArgs.push_back("-g");
44
45
5
  if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
46
5
                   false))
47
2
    CmdArgs.push_back("-fverbose-asm");
48
49
5
  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
50
51
5
  for (const auto &II : Inputs)
52
5
    CmdArgs.push_back(II.getFilename());
53
54
5
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
55
5
  C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
56
5
                                         Exec, CmdArgs, Inputs));
57
5
}
58
59
void tools::XCore::Linker::ConstructJob(Compilation &C, const JobAction &JA,
60
                                        const InputInfo &Output,
61
                                        const InputInfoList &Inputs,
62
                                        const ArgList &Args,
63
4
                                        const char *LinkingOutput) const {
64
4
  ArgStringList CmdArgs;
65
66
4
  if (Output.isFilename()) {
67
4
    CmdArgs.push_back("-o");
68
4
    CmdArgs.push_back(Output.getFilename());
69
0
  } else {
70
0
    assert(Output.isNothing() && "Invalid output.");
71
0
  }
72
73
4
  if (Args.hasArg(options::OPT_v))
74
2
    CmdArgs.push_back("-v");
75
76
  // Pass -fexceptions through to the linker if it was present.
77
4
  if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
78
4
                   false))
79
1
    CmdArgs.push_back("-fexceptions");
80
81
4
  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
82
83
4
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
84
4
  C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
85
4
                                         Exec, CmdArgs, Inputs));
86
4
}
87
88
/// XCore tool chain
89
XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple,
90
                               const ArgList &Args)
91
5
    : ToolChain(D, Triple, Args) {
92
  // ProgramPaths are found via 'PATH' environment variable.
93
5
}
94
95
5
Tool *XCoreToolChain::buildAssembler() const {
96
5
  return new tools::XCore::Assembler(*this);
97
5
}
98
99
4
Tool *XCoreToolChain::buildLinker() const {
100
4
  return new tools::XCore::Linker(*this);
101
4
}
102
103
5
bool XCoreToolChain::isPICDefault() const { return false; }
104
105
5
bool XCoreToolChain::isPIEDefault() const { return false; }
106
107
5
bool XCoreToolChain::isPICDefaultForced() const { return false; }
108
109
5
bool XCoreToolChain::SupportsProfiling() const { return false; }
110
111
0
bool XCoreToolChain::hasBlocksRuntime() const { return false; }
112
113
void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
114
5
                                               ArgStringList &CC1Args) const {
115
5
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
116
5
      DriverArgs.hasArg(options::OPT_nostdlibinc))
117
0
    return;
118
5
  if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) {
119
0
    SmallVector<StringRef, 4> Dirs;
120
0
    const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
121
0
    StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
122
0
    ArrayRef<StringRef> DirVec(Dirs);
123
0
    addSystemIncludes(DriverArgs, CC1Args, DirVec);
124
0
  }
125
5
}
126
127
void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs,
128
                                           ArgStringList &CC1Args,
129
5
                                           Action::OffloadKind) const {
130
5
  CC1Args.push_back("-nostdsysteminc");
131
5
}
132
133
void XCoreToolChain::AddClangCXXStdlibIncludeArgs(
134
3
    const ArgList &DriverArgs, ArgStringList &CC1Args) const {
135
3
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
136
3
      DriverArgs.hasArg(options::OPT_nostdlibinc) ||
137
3
      DriverArgs.hasArg(options::OPT_nostdincxx))
138
0
    return;
139
3
  if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) {
140
0
    SmallVector<StringRef, 4> Dirs;
141
0
    const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
142
0
    StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
143
0
    ArrayRef<StringRef> DirVec(Dirs);
144
0
    addSystemIncludes(DriverArgs, CC1Args, DirVec);
145
0
  }
146
3
}
147
148
void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
149
0
                                         ArgStringList &CmdArgs) const {
150
  // We don't output any lib args. This is handled by xcc.
151
0
}