1 //===--- SPIRV.cpp - SPIR-V Tool 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 #include "SPIRV.h" 9 #include "CommonArgs.h" 10 #include "clang/Driver/Compilation.h" 11 #include "clang/Driver/Driver.h" 12 #include "clang/Driver/InputInfo.h" 13 #include "clang/Driver/Options.h" 14 15 using namespace clang::driver; 16 using namespace clang::driver::tools; 17 using namespace llvm::opt; 18 19 void SPIRV::constructTranslateCommand(Compilation &C, const Tool &T, 20 const JobAction &JA, 21 const InputInfo &Output, 22 const InputInfo &Input, 23 const llvm::opt::ArgStringList &Args) { 24 llvm::opt::ArgStringList CmdArgs(Args); 25 CmdArgs.push_back(Input.getFilename()); 26 27 if (Input.getType() == types::TY_PP_Asm) 28 CmdArgs.push_back("-to-binary"); 29 if (Output.getType() == types::TY_PP_Asm) 30 CmdArgs.push_back("-spirv-text"); 31 32 CmdArgs.append({"-o", Output.getFilename()}); 33 34 const char *Exec = 35 C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv")); 36 C.addCommand(std::make_unique<Command>(JA, T, ResponseFileSupport::None(), 37 Exec, CmdArgs, Input, Output)); 38 } 39 40 void SPIRV::Translator::ConstructJob(Compilation &C, const JobAction &JA, 41 const InputInfo &Output, 42 const InputInfoList &Inputs, 43 const ArgList &Args, 44 const char *LinkingOutput) const { 45 claimNoWarnArgs(Args); 46 if (Inputs.size() != 1) 47 llvm_unreachable("Invalid number of input files."); 48 constructTranslateCommand(C, *this, JA, Output, Inputs[0], {}); 49 } 50