16#include "llvm/Option/ArgList.h"
17#include "llvm/Support/FileSystem.h"
18#include "llvm/Support/Path.h"
27 return llvm::StringSwitch<bool>(MCU)
28#define MSP430_MCU(NAME) .Case(NAME, true)
29#include "clang/Basic/MSP430Target.def"
37 return llvm::StringSwitch<StringRef>(MCU->getValue())
38#define MSP430_MCU_FEAT(NAME, HWMULT) .Case(NAME, HWMULT)
39#include "clang/Basic/MSP430Target.def"
44 StringRef HWMult = Args.getLastArgValue(options::OPT_mhwmult_EQ,
"auto");
45 if (HWMult ==
"auto") {
49 return llvm::StringSwitch<StringRef>(HWMult)
50 .Case(
"16bit",
"-lmul_16")
51 .Case(
"32bit",
"-lmul_32")
52 .Case(
"f5series",
"-lmul_f5")
53 .Default(
"-lmul_none");
57 std::vector<StringRef> &Features) {
58 const Arg *MCU = Args.getLastArg(options::OPT_mmcu_EQ);
60 D.Diag(diag::err_drv_clang_unsupported) << MCU->getValue();
64 const Arg *HWMultArg = Args.getLastArg(options::OPT_mhwmult_EQ);
65 if (!MCU && !HWMultArg)
68 StringRef HWMult = HWMultArg ? HWMultArg->getValue() :
"auto";
71 if (HWMult ==
"auto") {
75 D.Diag(clang::diag::warn_drv_msp430_hwmult_no_device);
76 HWMult = SupportedHWMult;
79 if (HWMult ==
"none") {
81 Features.push_back(
"-hwmult16");
82 Features.push_back(
"-hwmult32");
83 Features.push_back(
"-hwmultf5");
87 if (MCU && SupportedHWMult ==
"none")
88 D.Diag(clang::diag::warn_drv_msp430_hwmult_unsupported) << HWMult;
89 if (MCU && HWMult != SupportedHWMult)
90 D.Diag(clang::diag::warn_drv_msp430_hwmult_mismatch)
91 << SupportedHWMult << HWMult;
93 if (HWMult ==
"16bit") {
95 Features.push_back(
"+hwmult16");
96 }
else if (HWMult ==
"32bit") {
98 Features.push_back(
"+hwmult32");
99 }
else if (HWMult ==
"f5series") {
101 Features.push_back(
"+hwmultf5");
103 D.Diag(clang::diag::err_drv_unsupported_option_argument)
104 << HWMultArg->getSpelling() << HWMult;
113 StringRef MultilibSuf =
"";
120 llvm::sys::path::append(GCCBinPath,
125 llvm::sys::path::append(GCCRtPath,
131 llvm::sys::path::append(SysRootDir,
"msp430-elf",
"lib", MultilibSuf);
135std::string MSP430ToolChain::computeSysRoot()
const {
143 llvm::sys::path::append(Dir,
getDriver().Dir,
"..");
145 return std::string(Dir);
149 ArgStringList &CC1Args)
const {
150 if (DriverArgs.hasArg(options::OPT_nostdinc) ||
151 DriverArgs.hasArg(options::OPT_nostdlibinc))
155 llvm::sys::path::append(Dir,
"msp430-elf",
"include");
160 ArgStringList &CC1Args,
162 CC1Args.push_back(
"-nostdsysteminc");
164 const auto *MCUArg = DriverArgs.getLastArg(options::OPT_mmcu_EQ);
168 const StringRef MCU = MCUArg->getValue();
169 if (MCU.starts_with(
"msp430i")) {
171 CC1Args.push_back(DriverArgs.MakeArgString(
172 "-D__MSP430i" + MCU.drop_front(7).upper() +
"__"));
174 CC1Args.push_back(DriverArgs.MakeArgString(
"-D__" + MCU.upper() +
"__"));
182void msp430::Linker::AddStartFiles(
bool UseExceptions,
const ArgList &Args,
183 ArgStringList &CmdArgs)
const {
187 const char *crtbegin = UseExceptions ?
"crtbegin.o" :
"crtbegin_no_eh.o";
191void msp430::Linker::AddDefaultLibs(
const llvm::opt::ArgList &Args,
192 llvm::opt::ArgStringList &CmdArgs)
const {
196 CmdArgs.push_back(
"--start-group");
197 CmdArgs.push_back(Args.MakeArgString(
getHWMultLib(Args)));
198 CmdArgs.push_back(
"-lc");
200 CmdArgs.push_back(
"-lcrt");
202 if (Args.hasArg(options::OPT_msim)) {
203 CmdArgs.push_back(
"-lsim");
210 CmdArgs.push_back(
"--undefined=__crt0_call_exit");
212 CmdArgs.push_back(
"-lnosys");
214 CmdArgs.push_back(
"--end-group");
218void msp430::Linker::AddEndFiles(
bool UseExceptions,
const ArgList &Args,
219 ArgStringList &CmdArgs)
const {
223 const char *crtend = UseExceptions ?
"crtend.o" :
"crtend_no_eh.o";
228static void AddSspArgs(
const ArgList &Args, ArgStringList &CmdArgs) {
229 Arg *SspFlag = Args.getLastArg(
230 options::OPT_fno_stack_protector, options::OPT_fstack_protector,
231 options::OPT_fstack_protector_all, options::OPT_fstack_protector_strong);
234 !SspFlag->getOption().matches(options::OPT_fno_stack_protector)) {
235 CmdArgs.push_back(
"-lssp_nonshared");
236 CmdArgs.push_back(
"-lssp");
242 ArgStringList &CmdArgs) {
243 if (Args.hasArg(options::OPT_T))
246 if (Args.hasArg(options::OPT_msim)) {
247 CmdArgs.push_back(
"-Tmsp430-sim.ld");
251 const Arg *MCUArg = Args.getLastArg(options::OPT_mmcu_EQ);
256 llvm::sys::path::append(MCULinkerScriptPath,
"include");
258 CmdArgs.push_back(Args.MakeArgString(
"-L" + MCULinkerScriptPath));
260 Args.MakeArgString(
"-T" + StringRef(MCUArg->getValue()) +
".ld"));
267 const char *LinkingOutput)
const {
271 ArgStringList CmdArgs;
272 bool UseExceptions = Args.hasFlag(options::OPT_fexceptions,
273 options::OPT_fno_exceptions,
false);
274 bool UseStartAndEndFiles = !Args.hasArg(options::OPT_nostdlib, options::OPT_r,
275 options::OPT_nostartfiles);
277 if (Args.hasArg(options::OPT_mrelax))
278 CmdArgs.push_back(
"--relax");
279 if (!Args.hasArg(options::OPT_r, options::OPT_g_Group))
280 CmdArgs.push_back(
"--gc-sections");
282 Args.addAllArgs(CmdArgs, {
289 if (UseStartAndEndFiles)
290 AddStartFiles(UseExceptions, Args, CmdArgs);
292 Args.AddAllArgs(CmdArgs, options::OPT_L);
296 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_r,
297 options::OPT_nodefaultlibs)) {
300 if (!Args.hasArg(options::OPT_nolibc)) {
301 AddDefaultLibs(Args, CmdArgs);
306 if (UseStartAndEndFiles)
307 AddEndFiles(UseExceptions, Args, CmdArgs);
309 CmdArgs.push_back(
"-o");
312 Args.AddAllArgs(CmdArgs, options::OPT_T);
314 C.addCommand(std::make_unique<Command>(
316 CmdArgs, Inputs, Output));
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
std::string SysRoot
sysroot, if present
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant.
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileCurCP()