xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/BareMetal.h (revision dd41de95a84d979615a2ef11df6850622bf6184e)
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;
27 
28   static bool handlesTarget(const llvm::Triple &Triple);
29 protected:
30   Tool *buildLinker() const override;
31 
32 public:
33   bool useIntegratedAs() const override { return true; }
34   bool isCrossCompiling() const override { return true; }
35   bool isPICDefault() const override { return false; }
36   bool isPIEDefault() const override { return false; }
37   bool isPICDefaultForced() const override { return false; }
38   bool SupportsProfiling() const override { return false; }
39 
40   RuntimeLibType GetDefaultRuntimeLibType() const override {
41     return ToolChain::RLT_CompilerRT;
42   }
43   CXXStdlibType GetDefaultCXXStdlibType() const override {
44     return ToolChain::CST_Libcxx;
45   }
46 
47   const char *getDefaultLinker() const override { return "ld.lld"; }
48 
49   std::string getRuntimesDir() const;
50   void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
51                                  llvm::opt::ArgStringList &CC1Args) const override;
52   void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
53                              llvm::opt::ArgStringList &CC1Args,
54                              Action::OffloadKind DeviceOffloadKind) const override;
55   void AddClangCXXStdlibIncludeArgs(
56       const llvm::opt::ArgList &DriverArgs,
57       llvm::opt::ArgStringList &CC1Args) const override;
58   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
59                            llvm::opt::ArgStringList &CmdArgs) const override;
60   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
61                          llvm::opt::ArgStringList &CmdArgs) const;
62 };
63 
64 } // namespace toolchains
65 
66 namespace tools {
67 namespace baremetal {
68 
69 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
70 public:
71   Linker(const ToolChain &TC) : Tool("baremetal::Linker", "ld.lld", TC) {}
72   bool isLinkJob() const override { return true; }
73   bool hasIntegratedCPP() const override { return false; }
74   void ConstructJob(Compilation &C, const JobAction &JA,
75                     const InputInfo &Output, const InputInfoList &Inputs,
76                     const llvm::opt::ArgList &TCArgs,
77                     const char *LinkingOutput) const override;
78 };
79 
80 } // namespace baremetal
81 } // namespace tools
82 
83 } // namespace driver
84 } // namespace clang
85 
86 #endif
87