xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/BareMetal.h (revision 02e9120893770924227138ba49df1edb3896112a)
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 
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_BAREMETAL_H
11 
12 #include "clang/Driver/Tool.h"
13 #include "clang/Driver/ToolChain.h"
14 
15 #include <string>
16 
17 namespace clang {
18 namespace driver {
19 
20 namespace toolchains {
21 
22 class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
23 public:
24   BareMetal(const Driver &D, const llvm::Triple &Triple,
25             const llvm::opt::ArgList &Args);
26   ~BareMetal() override = default;
27 
28   static bool handlesTarget(const llvm::Triple &Triple);
29 
30   void findMultilibs(const Driver &D, const llvm::Triple &Triple,
31                      const llvm::opt::ArgList &Args);
32 
33 protected:
34   Tool *buildLinker() const override;
35   Tool *buildStaticLibTool() const override;
36 
37 public:
38   bool useIntegratedAs() const override { return true; }
39   bool isBareMetal() const override { return true; }
40   bool isCrossCompiling() const override { return true; }
41   bool HasNativeLLVMSupport() const override { return true; }
42   bool isPICDefault() const override { return false; }
43   bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
44     return false;
45   }
46   bool isPICDefaultForced() const override { return false; }
47   bool SupportsProfiling() const override { return false; }
48 
49   StringRef getOSLibName() const override { return "baremetal"; }
50 
51   RuntimeLibType GetDefaultRuntimeLibType() const override {
52     return ToolChain::RLT_CompilerRT;
53   }
54   CXXStdlibType GetDefaultCXXStdlibType() const override {
55     return ToolChain::CST_Libcxx;
56   }
57 
58   const char *getDefaultLinker() const override { return "ld.lld"; }
59 
60   void
61   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
62                             llvm::opt::ArgStringList &CC1Args) const override;
63   void
64   addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
65                         llvm::opt::ArgStringList &CC1Args,
66                         Action::OffloadKind DeviceOffloadKind) const override;
67   void AddClangCXXStdlibIncludeArgs(
68       const llvm::opt::ArgList &DriverArgs,
69       llvm::opt::ArgStringList &CC1Args) const override;
70   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
71                            llvm::opt::ArgStringList &CmdArgs) const override;
72   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
73                          llvm::opt::ArgStringList &CmdArgs) const;
74   std::string computeSysRoot() const override;
75 
76 private:
77   using OrderedMultilibs =
78       llvm::iterator_range<llvm::SmallVector<Multilib>::const_reverse_iterator>;
79   OrderedMultilibs getOrderedMultilibs() const;
80 };
81 
82 } // namespace toolchains
83 
84 namespace tools {
85 namespace baremetal {
86 
87 class LLVM_LIBRARY_VISIBILITY StaticLibTool : public Tool {
88 public:
89   StaticLibTool(const ToolChain &TC)
90       : Tool("baremetal::StaticLibTool", "llvm-ar", TC) {}
91 
92   bool hasIntegratedCPP() const override { return false; }
93   bool isLinkJob() const override { return true; }
94 
95   void ConstructJob(Compilation &C, const JobAction &JA,
96                     const InputInfo &Output, const InputInfoList &Inputs,
97                     const llvm::opt::ArgList &TCArgs,
98                     const char *LinkingOutput) const override;
99 };
100 
101 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
102 public:
103   Linker(const ToolChain &TC) : Tool("baremetal::Linker", "ld.lld", TC) {}
104   bool isLinkJob() const override { return true; }
105   bool hasIntegratedCPP() const override { return false; }
106   void ConstructJob(Compilation &C, const JobAction &JA,
107                     const InputInfo &Output, const InputInfoList &Inputs,
108                     const llvm::opt::ArgList &TCArgs,
109                     const char *LinkingOutput) const override;
110 };
111 
112 } // namespace baremetal
113 } // namespace tools
114 
115 } // namespace driver
116 } // namespace clang
117 
118 #endif
119