| 1 | //===--- Flang.h - Flang Tool and 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 | |
| 9 | #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_FLANG_H |
| 10 | #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_FLANG_H |
| 11 | |
| 12 | #include "clang/Driver/Tool.h" |
| 13 | #include "clang/Driver/Action.h" |
| 14 | #include "clang/Driver/Compilation.h" |
| 15 | #include "clang/Driver/ToolChain.h" |
| 16 | #include "llvm/Option/ArgList.h" |
| 17 | #include "llvm/Support/Compiler.h" |
| 18 | |
| 19 | namespace clang { |
| 20 | namespace driver { |
| 21 | |
| 22 | namespace tools { |
| 23 | |
| 24 | /// Flang compiler tool. |
| 25 | class LLVM_LIBRARY_VISIBILITY Flang : public Tool { |
| 26 | private: |
| 27 | /// Extract fortran dialect options from the driver arguments and add them to |
| 28 | /// the list of arguments for the generated command/job. |
| 29 | /// |
| 30 | /// \param [in] Args The list of input driver arguments |
| 31 | /// \param [out] CmdArgs The list of output command arguments |
| 32 | void addFortranDialectOptions(const llvm::opt::ArgList &Args, |
| 33 | llvm::opt::ArgStringList &CmdArgs) const; |
| 34 | |
| 35 | /// Extract preprocessing options from the driver arguments and add them to |
| 36 | /// the preprocessor command arguments. |
| 37 | /// |
| 38 | /// \param [in] Args The list of input driver arguments |
| 39 | /// \param [out] CmdArgs The list of output command arguments |
| 40 | void addPreprocessingOptions(const llvm::opt::ArgList &Args, |
| 41 | llvm::opt::ArgStringList &CmdArgs) const; |
| 42 | |
| 43 | /// Extract PIC options from the driver arguments and add them to |
| 44 | /// the command arguments. |
| 45 | /// |
| 46 | /// \param [in] Args The list of input driver arguments |
| 47 | /// \param [out] CmdArgs The list of output command arguments |
| 48 | void addPicOptions(const llvm::opt::ArgList &Args, |
| 49 | llvm::opt::ArgStringList &CmdArgs) const; |
| 50 | |
| 51 | /// Extract target options from the driver arguments and add them to |
| 52 | /// the command arguments. |
| 53 | /// |
| 54 | /// \param [in] Args The list of input driver arguments |
| 55 | /// \param [out] CmdArgs The list of output command arguments |
| 56 | void addTargetOptions(const llvm::opt::ArgList &Args, |
| 57 | llvm::opt::ArgStringList &CmdArgs) const; |
| 58 | |
| 59 | /// Add specific options for AArch64 target. |
| 60 | /// |
| 61 | /// \param [in] Args The list of input driver arguments |
| 62 | /// \param [out] CmdArgs The list of output command arguments |
| 63 | void AddAArch64TargetArgs(const llvm::opt::ArgList &Args, |
| 64 | llvm::opt::ArgStringList &CmdArgs) const; |
| 65 | |
| 66 | /// Add specific options for AMDGPU target. |
| 67 | /// |
| 68 | /// \param [in] Args The list of input driver arguments |
| 69 | /// \param [out] CmdArgs The list of output command arguments |
| 70 | void AddAMDGPUTargetArgs(const llvm::opt::ArgList &Args, |
| 71 | llvm::opt::ArgStringList &CmdArgs) const; |
| 72 | |
| 73 | /// Add specific options for LoongArch64 target. |
| 74 | /// |
| 75 | /// \param [in] Args The list of input driver arguments |
| 76 | /// \param [out] CmdArgs The list of output command arguments |
| 77 | void AddLoongArch64TargetArgs(const llvm::opt::ArgList &Args, |
| 78 | llvm::opt::ArgStringList &CmdArgs) const; |
| 79 | |
| 80 | /// Add specific options for RISC-V target. |
| 81 | /// |
| 82 | /// \param [in] Args The list of input driver arguments |
| 83 | /// \param [out] CmdArgs The list of output command arguments |
| 84 | void AddRISCVTargetArgs(const llvm::opt::ArgList &Args, |
| 85 | llvm::opt::ArgStringList &CmdArgs) const; |
| 86 | |
| 87 | /// Add specific options for X86_64 target. |
| 88 | /// |
| 89 | /// \param [in] Args The list of input driver arguments |
| 90 | /// \param [out] CmdArgs The list of output command arguments |
| 91 | void AddX86_64TargetArgs(const llvm::opt::ArgList &Args, |
| 92 | llvm::opt::ArgStringList &CmdArgs) const; |
| 93 | |
| 94 | /// Add specific options for PPC target. |
| 95 | /// |
| 96 | /// \param [in] Args The list of input driver arguments |
| 97 | /// \param [out] CmdArgs The list of output command arguments |
| 98 | void AddPPCTargetArgs(const llvm::opt::ArgList &Args, |
| 99 | llvm::opt::ArgStringList &CmdArgs) const; |
| 100 | |
| 101 | /// Extract offload options from the driver arguments and add them to |
| 102 | /// the command arguments. |
| 103 | /// \param [in] C The current compilation for the driver invocation |
| 104 | /// \param [in] Inputs The input infomration on the current file inputs |
| 105 | /// \param [in] JA The job action |
| 106 | /// \param [in] Args The list of input driver arguments |
| 107 | /// \param [out] CmdArgs The list of output command arguments |
| 108 | void addOffloadOptions(Compilation &C, const InputInfoList &Inputs, |
| 109 | const JobAction &JA, const llvm::opt::ArgList &Args, |
| 110 | llvm::opt::ArgStringList &CmdArgs) const; |
| 111 | |
| 112 | /// Extract options for code generation from the driver arguments and add them |
| 113 | /// to the command arguments. |
| 114 | /// |
| 115 | /// \param [in] Args The list of input driver arguments |
| 116 | /// \param [out] CmdArgs The list of output command arguments |
| 117 | void addCodegenOptions(const llvm::opt::ArgList &Args, |
| 118 | llvm::opt::ArgStringList &CmdArgs) const; |
| 119 | |
| 120 | /// Extract other compilation options from the driver arguments and add them |
| 121 | /// to the command arguments. |
| 122 | /// |
| 123 | /// \param [in] Args The list of input driver arguments |
| 124 | /// \param [out] CmdArgs The list of output command arguments |
| 125 | void addOtherOptions(const llvm::opt::ArgList &Args, |
| 126 | llvm::opt::ArgStringList &CmdArgs) const; |
| 127 | |
| 128 | public: |
| 129 | Flang(const ToolChain &TC); |
| 130 | ~Flang() override; |
| 131 | |
| 132 | bool hasGoodDiagnostics() const override { return true; } |
| 133 | bool hasIntegratedAssembler() const override { return true; } |
| 134 | bool hasIntegratedCPP() const override { return true; } |
| 135 | bool canEmitIR() const override { return true; } |
| 136 | |
| 137 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 138 | const InputInfo &Output, const InputInfoList &Inputs, |
| 139 | const llvm::opt::ArgList &TCArgs, |
| 140 | const char *LinkingOutput) const override; |
| 141 | }; |
| 142 | |
| 143 | } // end namespace tools |
| 144 | |
| 145 | } // end namespace driver |
| 146 | } // end namespace clang |
| 147 | |
| 148 | #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_FLANG_H |
| 149 | |