BareMetal.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //===--- BareMetal.h - Bare Metal Tool and ToolChain -------------*- 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. #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
  9. #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
  10. #include "clang/Driver/Tool.h"
  11. #include "clang/Driver/ToolChain.h"
  12. #include <string>
  13. namespace clang {
  14. namespace driver {
  15. namespace toolchains {
  16. class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
  17. public:
  18. BareMetal(const Driver &D, const llvm::Triple &Triple,
  19. const llvm::opt::ArgList &Args);
  20. ~BareMetal() override = default;
  21. static bool handlesTarget(const llvm::Triple &Triple);
  22. void findMultilibs(const Driver &D, const llvm::Triple &Triple,
  23. const llvm::opt::ArgList &Args);
  24. protected:
  25. Tool *buildLinker() const override;
  26. std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args,
  27. StringRef Component,
  28. FileType Type = ToolChain::FT_Static,
  29. bool AddArch = true) const override;
  30. public:
  31. bool useIntegratedAs() const override { return true; }
  32. bool isCrossCompiling() const override { return true; }
  33. bool isPICDefault() const override { return false; }
  34. bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
  35. return false;
  36. }
  37. bool isPICDefaultForced() const override { return false; }
  38. bool SupportsProfiling() const override { return false; }
  39. StringRef getOSLibName() const override { return "baremetal"; }
  40. std::string getCompilerRTPath() const override;
  41. RuntimeLibType GetDefaultRuntimeLibType() const override {
  42. return ToolChain::RLT_CompilerRT;
  43. }
  44. CXXStdlibType GetDefaultCXXStdlibType() const override {
  45. return ToolChain::CST_Libcxx;
  46. }
  47. const char *getDefaultLinker() const override { return "ld.lld"; }
  48. std::string getRuntimesDir() const;
  49. void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
  50. llvm::opt::ArgStringList &CC1Args) const override;
  51. void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
  52. llvm::opt::ArgStringList &CC1Args,
  53. Action::OffloadKind DeviceOffloadKind) const override;
  54. void AddClangCXXStdlibIncludeArgs(
  55. const llvm::opt::ArgList &DriverArgs,
  56. llvm::opt::ArgStringList &CC1Args) const override;
  57. void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
  58. llvm::opt::ArgStringList &CmdArgs) const override;
  59. void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
  60. llvm::opt::ArgStringList &CmdArgs) const;
  61. std::string computeSysRoot() const override;
  62. };
  63. } // namespace toolchains
  64. namespace tools {
  65. namespace baremetal {
  66. class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
  67. public:
  68. Linker(const ToolChain &TC) : Tool("baremetal::Linker", "ld.lld", TC) {}
  69. bool isLinkJob() const override { return true; }
  70. bool hasIntegratedCPP() const override { return false; }
  71. void ConstructJob(Compilation &C, const JobAction &JA,
  72. const InputInfo &Output, const InputInfoList &Inputs,
  73. const llvm::opt::ArgList &TCArgs,
  74. const char *LinkingOutput) const override;
  75. };
  76. } // namespace baremetal
  77. } // namespace tools
  78. } // namespace driver
  79. } // namespace clang
  80. #endif