clang 10.0.0git

XCore.cpp
Go to the documentation of this file.
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 const char *LinkingOutput) const {
30 claimNoWarnArgs(Args);
31 ArgStringList CmdArgs;
32
33 CmdArgs.push_back("-o");
34 CmdArgs.push_back(Output.getFilename());
35
36 CmdArgs.push_back("-c");
37
38 if (Args.hasArg(options::OPT_v))
39 CmdArgs.push_back("-v");
40
41 if (Arg *A = Args.getLastArg(options::OPT_g_Group))
42 if (!A->getOption().matches(options::OPT_g0))
43 CmdArgs.push_back("-g");
44
45 if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
46 false))
47 CmdArgs.push_back("-fverbose-asm");
48
49 Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
50
51 for (const auto &II : Inputs)
52 CmdArgs.push_back(II.getFilename());
53
54 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
55 C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
56 }
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 const char *LinkingOutput) const {
63 ArgStringList CmdArgs;
64
65 if (Output.isFilename()) {
66 CmdArgs.push_back("-o");
67 CmdArgs.push_back(Output.getFilename());
68 } else {
69 assert(Output.isNothing() && "Invalid output.");
70 }
71
72 if (Args.hasArg(options::OPT_v))
73 CmdArgs.push_back("-v");
74
75 // Pass -fexceptions through to the linker if it was present.
76 if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
77 false))
78 CmdArgs.push_back("-fexceptions");
79
80 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
81
82 const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
83 C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
84 }
85
86 /// XCore tool chain
87 XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple,
88 const ArgList &Args)
89 : ToolChain(D, Triple, Args) {
90 // ProgramPaths are found via 'PATH' environment variable.
91 }
92
93 Tool *XCoreToolChain::buildAssembler() const {
94 return new tools::XCore::Assembler(*this);
95 }
96
97 Tool *XCoreToolChain::buildLinker() const {
98 return new tools::XCore::Linker(*this);
99 }
100
101 bool XCoreToolChain::isPICDefault() const { return false; }
102
103 bool XCoreToolChain::isPIEDefault() const { return false; }
104
105 bool XCoreToolChain::isPICDefaultForced() const { return false; }
106
107 bool XCoreToolChain::SupportsProfiling() const { return false; }
108
109 bool XCoreToolChain::hasBlocksRuntime() const { return false; }
110
111 void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
112 ArgStringList &CC1Args) const {
113 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
114 DriverArgs.hasArg(options::OPT_nostdlibinc))
115 return;
116 if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) {
117 SmallVector<StringRef, 4> Dirs;
118 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
119 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
120 ArrayRef<StringRef> DirVec(Dirs);
121 addSystemIncludes(DriverArgs, CC1Args, DirVec);
122 }
123 }
124
125 void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs,
126 ArgStringList &CC1Args,
127 Action::OffloadKind) const {
128 CC1Args.push_back("-nostdsysteminc");
129 }
130
131 void XCoreToolChain::AddClangCXXStdlibIncludeArgs(
132 const ArgList &DriverArgs, ArgStringList &CC1Args) const {
133 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
134 DriverArgs.hasArg(options::OPT_nostdlibinc) ||
135 DriverArgs.hasArg(options::OPT_nostdincxx))
136 return;
137 if (const char *cl_include_dir = getenv("XCC_CPLUS_INCLUDE_PATH")) {
138 SmallVector<StringRef, 4> Dirs;
139 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
140 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
141 ArrayRef<StringRef> DirVec(Dirs);
142 addSystemIncludes(DriverArgs, CC1Args, DirVec);
143 }
144 }
145
146 void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
147 ArgStringList &CmdArgs) const {
148 // We don't output any lib args. This is handled by xcc.
149 }
clang::driver::toolchains::XCoreToolChain::addClangTargetOptions
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:125
clang::driver::toolchains::XCoreToolChain::isPIEDefault
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: XCore.cpp:103
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:83
CommonArgs.h
clang::driver::toolchains::XCoreToolChain::AddClangCXXStdlibIncludeArgs
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:131
clang::driver::JobAction
Definition: Action.h:375
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
clang::driver::toolchains::XCoreToolChain::XCoreToolChain
XCoreToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
XCore tool chain.
Definition: XCore.cpp:87
clang::driver::tools::XCore::Assembler::ConstructJob
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:25
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
clang::driver::toolchains::XCoreToolChain::buildAssembler
Tool * buildAssembler() const override
Definition: XCore.cpp:93
llvm::ArrayRef
Definition: LLVM.h:31
Driver.h
Compilation.h
llvm::opt
Definition: Action.h:23
clang::driver::ToolChain::addSystemIncludes
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:850
clang::driver::toolchains::XCoreToolChain::AddClangSystemIncludeArgs
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:111
clang::driver::Compilation::addCommand
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:205
clang::driver::toolchains::XCoreToolChain::buildLinker
Tool * buildLinker() const override
Definition: XCore.cpp:97
clang::driver::tools::XCore::Linker
Definition: XCore.h:34
clang::driver::tools::XCore::Linker::ConstructJob
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:58
llvm::SmallVector
Definition: LLVM.h:35
Options.h
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:84
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::driver::toolchains::XCoreToolChain::hasBlocksRuntime
bool hasBlocksRuntime() const override
hasBlocksRuntime - Given that the user is compiling with -fblocks, does this tool chain guarantee the...
Definition: XCore.cpp:109
clang::driver::tools::AddLinkerInputs
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:33
clang::driver::tools::XCore::Assembler
Definition: XCore.h:23
clang::driver::tools::claimNoWarnArgs
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
clang::driver::toolchains::XCoreToolChain::SupportsProfiling
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition: XCore.cpp:107
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::driver
Definition: Action.h:31
clang::driver::toolchains
Definition: AIX.h:55
clang::driver::InputInfo::isNothing
bool isNothing() const
Definition: InputInfo.h:74
clang::driver::InputInfo::isFilename
bool isFilename() const
Definition: InputInfo.h:75
clang::driver::toolchains::XCoreToolChain::AddCXXStdlibLibArgs
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:146
clang::driver::toolchains::XCoreToolChain::isPICDefaultForced
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: XCore.cpp:105
clang::driver::toolchains::XCoreToolChain::isPICDefault
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: XCore.cpp:101
XCore.h
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88