clang 8.0.0

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"
12 #include "clang/Driver/Compilation.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
26 void tools::XCore::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
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
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;
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
94 Tool *XCoreToolChain::buildAssembler() const {
95 return new tools::XCore::Assembler(*this);
96 }
97
98 Tool *XCoreToolChain::buildLinker() const {
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")) {
118 SmallVector<StringRef, 4> Dirs;
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
132 void XCoreToolChain::AddClangCXXStdlibIncludeArgs(
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")) {
139 SmallVector<StringRef, 4> Dirs;
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 }
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:126
clang::driver::toolchains::XCoreToolChain::isPIEDefault
bool isPIEDefault() const override
Test whether this toolchain defaults to PIE.
Definition: XCore.cpp:104
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:84
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:132
clang::driver::JobAction
Definition: Action.h:374
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:23
clang::driver::toolchains::XCoreToolChain::XCoreToolChain
XCoreToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
XCore tool chain.
Definition: XCore.cpp:88
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:26
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:58
clang::driver::toolchains::XCoreToolChain::buildAssembler
Tool * buildAssembler() const override
Definition: XCore.cpp:94
llvm::ArrayRef
Definition: LLVM.h:32
Driver.h
Compilation.h
llvm::opt
Definition: Action.h:24
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:732
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:112
clang::driver::Compilation::addCommand
void addCommand(std::unique_ptr< Command > C)
Definition: Compilation.h:206
clang::driver::toolchains::XCoreToolChain::buildLinker
Tool * buildLinker() const override
Definition: XCore.cpp:98
clang::driver::tools::XCore::Linker
Definition: XCore.h:35
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:59
llvm::SmallVector
Definition: LLVM.h:36
Options.h
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:83
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
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:110
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:34
clang::driver::tools::XCore::Assembler
Definition: XCore.h:24
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:108
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:46
clang::driver
Definition: Action.h:32
clang::driver::toolchains
Definition: AMDGPU.h:41
clang::driver::InputInfo::isNothing
bool isNothing() const
Definition: InputInfo.h:75
clang::driver::InputInfo::isFilename
bool isFilename() const
Definition: InputInfo.h:76
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:147
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:106
clang::driver::toolchains::XCoreToolChain::isPICDefault
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: XCore.cpp:102
XCore.h
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:89