clang  6.0.0svn
XCore.cpp
Go to the documentation of this file.
1 //===--- XCore.cpp - XCore ToolChain Implementations ------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "XCore.h"
11 #include "CommonArgs.h"
13 #include "clang/Driver/Driver.h"
14 #include "clang/Driver/Options.h"
15 #include "llvm/Option/ArgList.h"
16 #include <cstdlib> // ::getenv
17 
18 using namespace clang::driver;
19 using namespace clang::driver::toolchains;
20 using namespace clang;
21 using namespace llvm::opt;
22 
23 /// XCore Tools
24 // We pass assemble and link construction to the xcc tool.
25 
27  const InputInfo &Output,
28  const InputInfoList &Inputs,
29  const ArgList &Args,
30  const char *LinkingOutput) const {
31  claimNoWarnArgs(Args);
32  ArgStringList CmdArgs;
33 
34  CmdArgs.push_back("-o");
35  CmdArgs.push_back(Output.getFilename());
36 
37  CmdArgs.push_back("-c");
38 
39  if (Args.hasArg(options::OPT_v))
40  CmdArgs.push_back("-v");
41 
42  if (Arg *A = Args.getLastArg(options::OPT_g_Group))
43  if (!A->getOption().matches(options::OPT_g0))
44  CmdArgs.push_back("-g");
45 
46  if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
47  false))
48  CmdArgs.push_back("-fverbose-asm");
49 
50  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
51 
52  for (const auto &II : Inputs)
53  CmdArgs.push_back(II.getFilename());
54 
55  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
56  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
57 }
58 
60  const InputInfo &Output,
61  const InputInfoList &Inputs,
62  const ArgList &Args,
63  const char *LinkingOutput) const {
64  ArgStringList CmdArgs;
65 
66  if (Output.isFilename()) {
67  CmdArgs.push_back("-o");
68  CmdArgs.push_back(Output.getFilename());
69  } else {
70  assert(Output.isNothing() && "Invalid output.");
71  }
72 
73  if (Args.hasArg(options::OPT_v))
74  CmdArgs.push_back("-v");
75 
76  // Pass -fexceptions through to the linker if it was present.
77  if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
78  false))
79  CmdArgs.push_back("-fexceptions");
80 
81  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
82 
83  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
84  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
85 }
86 
87 /// XCore tool chain
88 XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple,
89  const ArgList &Args)
90  : ToolChain(D, Triple, Args) {
91  // ProgramPaths are found via 'PATH' environment variable.
92 }
93 
95  return new tools::XCore::Assembler(*this);
96 }
97 
99  return new tools::XCore::Linker(*this);
100 }
101 
102 bool XCoreToolChain::isPICDefault() const { return false; }
103 
104 bool XCoreToolChain::isPIEDefault() const { return false; }
105 
106 bool XCoreToolChain::isPICDefaultForced() const { return false; }
107 
108 bool XCoreToolChain::SupportsProfiling() const { return false; }
109 
110 bool XCoreToolChain::hasBlocksRuntime() const { return false; }
111 
112 void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
113  ArgStringList &CC1Args) const {
114  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
115  DriverArgs.hasArg(options::OPT_nostdlibinc))
116  return;
117  if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) {
119  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
120  StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
121  ArrayRef<StringRef> DirVec(Dirs);
122  addSystemIncludes(DriverArgs, CC1Args, DirVec);
123  }
124 }
125 
126 void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs,
127  ArgStringList &CC1Args,
128  Action::OffloadKind) const {
129  CC1Args.push_back("-nostdsysteminc");
130 }
131 
133  const ArgList &DriverArgs, ArgStringList &CC1Args) const {
134  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
135  DriverArgs.hasArg(options::OPT_nostdlibinc) ||
136  DriverArgs.hasArg(options::OPT_nostdincxx))
137  return;
138  if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) {
140  const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
141  StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
142  ArrayRef<StringRef> DirVec(Dirs);
143  addSystemIncludes(DriverArgs, CC1Args, DirVec);
144  }
145 }
146 
147 void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
148  ArgStringList &CmdArgs) const {
149  // We don't output any lib args. This is handled by xcc.
150 }
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: XCore.cpp:126
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: XCore.cpp:104
const char * getFilename() const
Definition: InputInfo.h:84
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
Definition: XCore.cpp:132
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
XCoreToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
XCore tool chain.
Definition: XCore.cpp:88
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
XCore Tools.
Definition: XCore.cpp:26
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:65
Tool * buildAssembler() const override
Definition: XCore.cpp:94
static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, ArrayRef< StringRef > Paths)
Utility function to add a list of system include directories to CC1.
Definition: ToolChain.cpp:694
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: XCore.cpp:112
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:189
Tool * buildLinker() const override
Definition: XCore.cpp:98
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs...
Definition: XCore.cpp:59
Dataflow Directional Tag Classes.
bool hasBlocksRuntime() const override
hasBlocksRuntime - Given that the user is compiling with -fblocks, does this tool chain guarantee the...
Definition: XCore.cpp:110
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
Tool - Information on a specific compilation tool.
Definition: Tool.h:34
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition: XCore.cpp:108
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:34
bool isNothing() const
Definition: InputInfo.h:75
bool isFilename() const
Definition: InputInfo.h:76
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
Definition: XCore.cpp:147
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: XCore.cpp:106
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: XCore.cpp:102
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:73