XCore.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #include "XCore.h"
  9. #include "CommonArgs.h"
  10. #include "clang/Driver/Compilation.h"
  11. #include "clang/Driver/Driver.h"
  12. #include "clang/Driver/Options.h"
  13. #include "llvm/Option/ArgList.h"
  14. #include <cstdlib> // ::getenv
  15. using namespace clang::driver;
  16. using namespace clang::driver::toolchains;
  17. using namespace clang;
  18. using namespace llvm::opt;
  19. /// XCore Tools
  20. // We pass assemble and link construction to the xcc tool.
  21. void tools::XCore::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
  22. const InputInfo &Output,
  23. const InputInfoList &Inputs,
  24. const ArgList &Args,
  25. const char *LinkingOutput) const {
  26. claimNoWarnArgs(Args);
  27. ArgStringList CmdArgs;
  28. CmdArgs.push_back("-o");
  29. CmdArgs.push_back(Output.getFilename());
  30. CmdArgs.push_back("-c");
  31. if (Args.hasArg(options::OPT_v))
  32. CmdArgs.push_back("-v");
  33. if (Arg *A = Args.getLastArg(options::OPT_g_Group))
  34. if (!A->getOption().matches(options::OPT_g0))
  35. CmdArgs.push_back("-g");
  36. if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
  37. false))
  38. CmdArgs.push_back("-fverbose-asm");
  39. Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
  40. for (const auto &II : Inputs)
  41. CmdArgs.push_back(II.getFilename());
  42. const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
  43. C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
  44. Exec, CmdArgs, Inputs, Output));
  45. }
  46. void tools::XCore::Linker::ConstructJob(Compilation &C, const JobAction &JA,
  47. const InputInfo &Output,
  48. const InputInfoList &Inputs,
  49. const ArgList &Args,
  50. const char *LinkingOutput) const {
  51. ArgStringList CmdArgs;
  52. if (Output.isFilename()) {
  53. CmdArgs.push_back("-o");
  54. CmdArgs.push_back(Output.getFilename());
  55. } else {
  56. assert(Output.isNothing() && "Invalid output.");
  57. }
  58. if (Args.hasArg(options::OPT_v))
  59. CmdArgs.push_back("-v");
  60. // Pass -fexceptions through to the linker if it was present.
  61. if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
  62. false))
  63. CmdArgs.push_back("-fexceptions");
  64. AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
  65. const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
  66. C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
  67. Exec, CmdArgs, Inputs, Output));
  68. }
  69. /// XCore tool chain
  70. XCoreToolChain::XCoreToolChain(const Driver &D, const llvm::Triple &Triple,
  71. const ArgList &Args)
  72. : ToolChain(D, Triple, Args) {
  73. // ProgramPaths are found via 'PATH' environment variable.
  74. }
  75. Tool *XCoreToolChain::buildAssembler() const {
  76. return new tools::XCore::Assembler(*this);
  77. }
  78. Tool *XCoreToolChain::buildLinker() const {
  79. return new tools::XCore::Linker(*this);
  80. }
  81. bool XCoreToolChain::isPICDefault() const { return false; }
  82. bool XCoreToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
  83. return false;
  84. }
  85. bool XCoreToolChain::isPICDefaultForced() const { return false; }
  86. bool XCoreToolChain::SupportsProfiling() const { return false; }
  87. bool XCoreToolChain::hasBlocksRuntime() const { return false; }
  88. void XCoreToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
  89. ArgStringList &CC1Args) const {
  90. if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
  91. DriverArgs.hasArg(options::OPT_nostdlibinc))
  92. return;
  93. if (const char *cl_include_dir = getenv("XCC_C_INCLUDE_PATH")) {
  94. SmallVector<StringRef, 4> Dirs;
  95. const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
  96. StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
  97. ArrayRef<StringRef> DirVec(Dirs);
  98. addSystemIncludes(DriverArgs, CC1Args, DirVec);
  99. }
  100. }
  101. void XCoreToolChain::addClangTargetOptions(const ArgList &DriverArgs,
  102. ArgStringList &CC1Args,
  103. Action::OffloadKind) const {
  104. CC1Args.push_back("-nostdsysteminc");
  105. // Set `-fno-use-cxa-atexit` to default.
  106. if (!DriverArgs.hasFlag(options::OPT_fuse_cxa_atexit,
  107. options::OPT_fno_use_cxa_atexit, false))
  108. CC1Args.push_back("-fno-use-cxa-atexit");
  109. }
  110. void XCoreToolChain::AddClangCXXStdlibIncludeArgs(
  111. const ArgList &DriverArgs, ArgStringList &CC1Args) const {
  112. if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
  113. DriverArgs.hasArg(options::OPT_nostdlibinc) ||
  114. DriverArgs.hasArg(options::OPT_nostdincxx))
  115. return;
  116. if (const char *cl_include_dir = getenv("XCC_CPLUS_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. void XCoreToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
  125. ArgStringList &CmdArgs) const {
  126. // We don't output any lib args. This is handled by xcc.
  127. }