Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
5
33
5
  CmdArgs.push_back("-o");
34
5
  CmdArgs.push_back(Output.getFilename());
35
5
36
5
  CmdArgs.push_back("-c");
37
5
38
5
  if (Args.hasArg(options::OPT_v))
39
2
    CmdArgs.push_back("-v");
40
5
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
5
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
5
49
5
  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
50
5
51
5
  for (const auto &II : Inputs)
52
5
    CmdArgs.push_back(II.getFilename());
53
5
54
5
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
55
5
  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
56
5
}
57
58
void tools::XCore::Linker::ConstructJob(Compilation &C, const JobAction &JA,
59
                                        const InputInfo &Output,
60
                                        const InputInfoList &Inputs,
61
                                        const ArgList &Args,
62
4
                                        const char *LinkingOutput) const {
63
4
  ArgStringList CmdArgs;
64
4
65
4
  if (Output.isFilename()) {
66
4
    CmdArgs.push_back("-o");
67
4
    CmdArgs.push_back(Output.getFilename());
68
4
  } else {
69
0
    assert(Output.isNothing() && "Invalid output.");
70
0
  }
71
4
72
4
  if (Args.hasArg(options::OPT_v))
73
2
    CmdArgs.push_back("-v");
74
4
75
4
  // Pass -fexceptions through to the linker if it was present.
76
4
  if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
77
4
                   false))
78
1
    CmdArgs.push_back("-fexceptions");
79
4
80
4
  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
81
4
82
4
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
83
4
  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
84
4
}
85
86
/// XCore tool chain
87
XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple,
88
                               const ArgList &Args)
89
5
    : ToolChain(D, Triple, Args) {
90
5
  // ProgramPaths are found via 'PATH' environment variable.
91
5
}
92
93
5
Tool *XCoreToolChain::buildAssembler() const {
94
5
  return new tools::XCore::Assembler(*this);
95
5
}
96
97
4
Tool *XCoreToolChain::buildLinker() const {
98
4
  return new tools::XCore::Linker(*this);
99
4
}
100
101
5
bool XCoreToolChain::isPICDefault() const { return false; }
102
103
5
bool XCoreToolChain::isPIEDefault() const { return false; }
104
105
5
bool XCoreToolChain::isPICDefaultForced() const { return false; }
106
107
10
bool XCoreToolChain::SupportsProfiling() const { return false; }
108
109
0
bool XCoreToolChain::hasBlocksRuntime() const { return false; }
110
111
void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
112
5
                                               ArgStringList &CC1Args) const {
113
5
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
114
5
      DriverArgs.hasArg(options::OPT_nostdlibinc))
115
0
    return;
116
5
  if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) {
117
0
    SmallVector<StringRef, 4> Dirs;
118
0
    const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
119
0
    StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
120
0
    ArrayRef<StringRef> DirVec(Dirs);
121
0
    addSystemIncludes(DriverArgs, CC1Args, DirVec);
122
0
  }
123
5
}
124
125
void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs,
126
                                           ArgStringList &CC1Args,
127
5
                                           Action::OffloadKind) const {
128
5
  CC1Args.push_back("-nostdsysteminc");
129
5
}
130
131
void XCoreToolChain::AddClangCXXStdlibIncludeArgs(
132
3
    const ArgList &DriverArgs, ArgStringList &CC1Args) const {
133
3
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
134
3
      DriverArgs.hasArg(options::OPT_nostdlibinc) ||
135
3
      DriverArgs.hasArg(options::OPT_nostdincxx))
136
0
    return;
137
3
  if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) {
138
0
    SmallVector<StringRef, 4> Dirs;
139
0
    const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
140
0
    StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
141
0
    ArrayRef<StringRef> DirVec(Dirs);
142
0
    addSystemIncludes(DriverArgs, CC1Args, DirVec);
143
0
  }
144
3
}
145
146
void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
147
0
                                         ArgStringList &CmdArgs) const {
148
0
  // We don't output any lib args. This is handled by xcc.
149
0
}