[docs] Fix build-docs.sh
[llvm-project.git] / clang / lib / Driver / ToolChains / XCore.cpp
blob29fa82aec0a9fec80d59723c520da30a9210267e
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 //===----------------------------------------------------------------------===//
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
17 using namespace clang::driver;
18 using namespace clang::driver::toolchains;
19 using namespace clang;
20 using namespace llvm::opt;
22 /// XCore Tools
23 // We pass assemble and link construction to the xcc tool.
25 void tools::XCore::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
26 const InputInfo &Output,
27 const InputInfoList &Inputs,
28 const ArgList &Args,
29 const char *LinkingOutput) const {
30 claimNoWarnArgs(Args);
31 ArgStringList CmdArgs;
33 CmdArgs.push_back("-o");
34 CmdArgs.push_back(Output.getFilename());
36 CmdArgs.push_back("-c");
38 if (Args.hasArg(options::OPT_v))
39 CmdArgs.push_back("-v");
41 if (Arg *A = Args.getLastArg(options::OPT_g_Group))
42 if (!A->getOption().matches(options::OPT_g0))
43 CmdArgs.push_back("-g");
45 if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
46 false))
47 CmdArgs.push_back("-fverbose-asm");
49 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
51 for (const auto &II : Inputs)
52 CmdArgs.push_back(II.getFilename());
54 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
55 C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
56 Exec, CmdArgs, Inputs, Output));
59 void tools::XCore::Linker::ConstructJob(Compilation &C, const JobAction &JA,
60 const InputInfo &Output,
61 const InputInfoList &Inputs,
62 const ArgList &Args,
63 const char *LinkingOutput) const {
64 ArgStringList CmdArgs;
66 if (Output.isFilename()) {
67 CmdArgs.push_back("-o");
68 CmdArgs.push_back(Output.getFilename());
69 } else {
70 assert(Output.isNothing() && "Invalid output.");
73 if (Args.hasArg(options::OPT_v))
74 CmdArgs.push_back("-v");
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");
81 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
83 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
84 C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
85 Exec, CmdArgs, Inputs, Output));
88 /// XCore tool chain
89 XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple,
90 const ArgList &Args)
91 : ToolChain(D, Triple, Args) {
92 // ProgramPaths are found via 'PATH' environment variable.
95 Tool *XCoreToolChain::buildAssembler() const {
96 return new tools::XCore::Assembler(*this);
99 Tool *XCoreToolChain::buildLinker() const {
100 return new tools::XCore::Linker(*this);
103 bool XCoreToolChain::isPICDefault() const { return false; }
105 bool XCoreToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
106 return false;
109 bool XCoreToolChain::isPICDefaultForced() const { return false; }
111 bool XCoreToolChain::SupportsProfiling() const { return false; }
113 bool XCoreToolChain::hasBlocksRuntime() const { return false; }
115 void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
116 ArgStringList &CC1Args) const {
117 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
118 DriverArgs.hasArg(options::OPT_nostdlibinc))
119 return;
120 if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) {
121 SmallVector<StringRef, 4> Dirs;
122 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
123 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
124 ArrayRef<StringRef> DirVec(Dirs);
125 addSystemIncludes(DriverArgs, CC1Args, DirVec);
129 void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs,
130 ArgStringList &CC1Args,
131 Action::OffloadKind) const {
132 CC1Args.push_back("-nostdsysteminc");
133 // Set `-fno-use-cxa-atexit` to default.
134 if (!DriverArgs.hasFlag(options::OPT_fuse_cxa_atexit,
135 options::OPT_fno_use_cxa_atexit, false))
136 CC1Args.push_back("-fno-use-cxa-atexit");
139 void XCoreToolChain::AddClangCXXStdlibIncludeArgs(
140 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
141 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
142 DriverArgs.hasArg(options::OPT_nostdlibinc) ||
143 DriverArgs.hasArg(options::OPT_nostdincxx))
144 return;
145 if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) {
146 SmallVector<StringRef, 4> Dirs;
147 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
148 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
149 ArrayRef<StringRef> DirVec(Dirs);
150 addSystemIncludes(DriverArgs, CC1Args, DirVec);
154 void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
155 ArgStringList &CmdArgs) const {
156 // We don't output any lib args. This is handled by xcc.