David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 1 | //===--- Clang.h - Clang Tool and ToolChain Implementations ====-*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 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 |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_Clang_H |
| 10 | #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_Clang_H |
| 11 | |
| 12 | #include "MSVC.h" |
| 13 | #include "clang/Basic/DebugInfoOptions.h" |
| 14 | #include "clang/Driver/Driver.h" |
| 15 | #include "clang/Driver/Tool.h" |
| 16 | #include "clang/Driver/Types.h" |
| 17 | #include "llvm/ADT/Triple.h" |
| 18 | #include "llvm/Option/Option.h" |
| 19 | #include "llvm/Support/raw_ostream.h" |
| 20 | |
| 21 | namespace clang { |
| 22 | class ObjCRuntime; |
| 23 | namespace driver { |
| 24 | |
| 25 | namespace tools { |
| 26 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 27 | /// Clang compiler tool. |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 28 | class LLVM_LIBRARY_VISIBILITY Clang : public Tool { |
| 29 | public: |
| 30 | static const char *getBaseInputName(const llvm::opt::ArgList &Args, |
| 31 | const InputInfo &Input); |
| 32 | static const char *getBaseInputStem(const llvm::opt::ArgList &Args, |
| 33 | const InputInfoList &Inputs); |
| 34 | static const char *getDependencyFileName(const llvm::opt::ArgList &Args, |
| 35 | const InputInfoList &Inputs); |
| 36 | |
| 37 | private: |
| 38 | void AddPreprocessingOptions(Compilation &C, const JobAction &JA, |
| 39 | const Driver &D, const llvm::opt::ArgList &Args, |
| 40 | llvm::opt::ArgStringList &CmdArgs, |
| 41 | const InputInfo &Output, |
| 42 | const InputInfoList &Inputs) const; |
| 43 | |
Saleem Abdulrasool | 6c3ed7b | 2017-09-03 04:47:00 +0000 | [diff] [blame] | 44 | void RenderTargetOptions(const llvm::Triple &EffectiveTriple, |
| 45 | const llvm::opt::ArgList &Args, bool KernelOrKext, |
| 46 | llvm::opt::ArgStringList &CmdArgs) const; |
| 47 | |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 48 | void AddAArch64TargetArgs(const llvm::opt::ArgList &Args, |
| 49 | llvm::opt::ArgStringList &CmdArgs) const; |
| 50 | void AddARMTargetArgs(const llvm::Triple &Triple, |
| 51 | const llvm::opt::ArgList &Args, |
| 52 | llvm::opt::ArgStringList &CmdArgs, |
| 53 | bool KernelOrKext) const; |
| 54 | void AddARM64TargetArgs(const llvm::opt::ArgList &Args, |
| 55 | llvm::opt::ArgStringList &CmdArgs) const; |
| 56 | void AddMIPSTargetArgs(const llvm::opt::ArgList &Args, |
| 57 | llvm::opt::ArgStringList &CmdArgs) const; |
| 58 | void AddPPCTargetArgs(const llvm::opt::ArgList &Args, |
| 59 | llvm::opt::ArgStringList &CmdArgs) const; |
| 60 | void AddR600TargetArgs(const llvm::opt::ArgList &Args, |
| 61 | llvm::opt::ArgStringList &CmdArgs) const; |
Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 62 | void AddRISCVTargetArgs(const llvm::opt::ArgList &Args, |
| 63 | llvm::opt::ArgStringList &CmdArgs) const; |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 64 | void AddSparcTargetArgs(const llvm::opt::ArgList &Args, |
| 65 | llvm::opt::ArgStringList &CmdArgs) const; |
| 66 | void AddSystemZTargetArgs(const llvm::opt::ArgList &Args, |
| 67 | llvm::opt::ArgStringList &CmdArgs) const; |
| 68 | void AddX86TargetArgs(const llvm::opt::ArgList &Args, |
| 69 | llvm::opt::ArgStringList &CmdArgs) const; |
| 70 | void AddHexagonTargetArgs(const llvm::opt::ArgList &Args, |
| 71 | llvm::opt::ArgStringList &CmdArgs) const; |
| 72 | void AddLanaiTargetArgs(const llvm::opt::ArgList &Args, |
| 73 | llvm::opt::ArgStringList &CmdArgs) const; |
| 74 | void AddWebAssemblyTargetArgs(const llvm::opt::ArgList &Args, |
| 75 | llvm::opt::ArgStringList &CmdArgs) const; |
| 76 | |
| 77 | enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile }; |
| 78 | |
| 79 | ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args, |
| 80 | llvm::opt::ArgStringList &cmdArgs, |
| 81 | RewriteKind rewrite) const; |
| 82 | |
| 83 | void AddClangCLArgs(const llvm::opt::ArgList &Args, types::ID InputType, |
| 84 | llvm::opt::ArgStringList &CmdArgs, |
| 85 | codegenoptions::DebugInfoKind *DebugInfoKind, |
| 86 | bool *EmitCodeView) const; |
| 87 | |
| 88 | visualstudio::Compiler *getCLFallback() const; |
| 89 | |
| 90 | mutable std::unique_ptr<visualstudio::Compiler> CLFallback; |
| 91 | |
| 92 | mutable std::unique_ptr<llvm::raw_fd_ostream> CompilationDatabase = nullptr; |
| 93 | void DumpCompilationDatabase(Compilation &C, StringRef Filename, |
| 94 | StringRef Target, |
| 95 | const InputInfo &Output, const InputInfo &Input, |
| 96 | const llvm::opt::ArgList &Args) const; |
| 97 | |
| 98 | public: |
| 99 | Clang(const ToolChain &TC); |
| 100 | ~Clang() override; |
| 101 | |
| 102 | bool hasGoodDiagnostics() const override { return true; } |
| 103 | bool hasIntegratedAssembler() const override { return true; } |
| 104 | bool hasIntegratedCPP() const override { return true; } |
| 105 | bool canEmitIR() const override { return true; } |
| 106 | |
| 107 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 108 | const InputInfo &Output, const InputInfoList &Inputs, |
| 109 | const llvm::opt::ArgList &TCArgs, |
| 110 | const char *LinkingOutput) const override; |
| 111 | }; |
| 112 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 113 | /// Clang integrated assembler tool. |
David L. Jones | f561aba | 2017-03-08 01:02:16 +0000 | [diff] [blame] | 114 | class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool { |
| 115 | public: |
| 116 | ClangAs(const ToolChain &TC) |
| 117 | : Tool("clang::as", "clang integrated assembler", TC, RF_Full) {} |
| 118 | void AddMIPSTargetArgs(const llvm::opt::ArgList &Args, |
| 119 | llvm::opt::ArgStringList &CmdArgs) const; |
| 120 | void AddX86TargetArgs(const llvm::opt::ArgList &Args, |
| 121 | llvm::opt::ArgStringList &CmdArgs) const; |
| 122 | bool hasGoodDiagnostics() const override { return true; } |
| 123 | bool hasIntegratedAssembler() const override { return false; } |
| 124 | bool hasIntegratedCPP() const override { return false; } |
| 125 | |
| 126 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 127 | const InputInfo &Output, const InputInfoList &Inputs, |
| 128 | const llvm::opt::ArgList &TCArgs, |
| 129 | const char *LinkingOutput) const override; |
| 130 | }; |
| 131 | |
| 132 | /// Offload bundler tool. |
| 133 | class LLVM_LIBRARY_VISIBILITY OffloadBundler final : public Tool { |
| 134 | public: |
| 135 | OffloadBundler(const ToolChain &TC) |
| 136 | : Tool("offload bundler", "clang-offload-bundler", TC) {} |
| 137 | |
| 138 | bool hasIntegratedCPP() const override { return false; } |
| 139 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 140 | const InputInfo &Output, const InputInfoList &Inputs, |
| 141 | const llvm::opt::ArgList &TCArgs, |
| 142 | const char *LinkingOutput) const override; |
| 143 | void ConstructJobMultipleOutputs(Compilation &C, const JobAction &JA, |
| 144 | const InputInfoList &Outputs, |
| 145 | const InputInfoList &Inputs, |
| 146 | const llvm::opt::ArgList &TCArgs, |
| 147 | const char *LinkingOutput) const override; |
| 148 | }; |
| 149 | } // end namespace tools |
| 150 | |
| 151 | } // end namespace driver |
| 152 | } // end namespace clang |
| 153 | |
| 154 | #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CLANG_H |