FileTestUtils.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //===- FileTestUtils.h ---- Utilities For Running File Tests --------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLVM_CLANG_UNITTESTS_SPIRV_FILETESTUTILS_H
  10. #define LLVM_CLANG_UNITTESTS_SPIRV_FILETESTUTILS_H
  11. #include <string>
  12. #include <vector>
  13. #include "dxc/Support/Global.h"
  14. #include "dxc/Support/WinIncludes.h"
  15. #include "dxc/Support/dxcapi.use.h"
  16. #include "spirv-tools/libspirv.hpp"
  17. #include "llvm/ADT/StringRef.h"
  18. namespace clang {
  19. namespace spirv {
  20. namespace utils {
  21. /// \brief Passes the given SPIR-V binary to SPIR-V tools disassembler. The
  22. /// SPIR-V assembly is returned via 'generatedSpirvAsm' argument.
  23. /// Returns true on success, and false on failure.
  24. bool disassembleSpirvBinary(std::vector<uint32_t> &binary,
  25. std::string *generatedSpirvAsm,
  26. bool generateHeader = false);
  27. /// \brief Runs the SPIR-V Tools validation on the given SPIR-V binary.
  28. /// Returns true if validation is successful; false otherwise.
  29. bool validateSpirvBinary(spv_target_env, std::vector<uint32_t> &binary,
  30. bool beforeHlslLegalization, bool glLayout,
  31. bool dxLayout, bool scalarLayout,
  32. std::string *message = nullptr);
  33. /// \brief Parses the Target Profile and Entry Point from the Run command
  34. /// Returns the target profile, entry point, and the rest via arguments.
  35. /// Returns true on success, and false otherwise.
  36. bool processRunCommandArgs(const llvm::StringRef runCommandLine,
  37. std::string *targetProfile, std::string *entryPoint,
  38. std::vector<std::string> *restArgs);
  39. /// \brief Converts an IDxcBlob into a vector of 32-bit unsigned integers which
  40. /// is returned via the 'binaryWords' argument.
  41. void convertIDxcBlobToUint32(const CComPtr<IDxcBlob> &blob,
  42. std::vector<uint32_t> *binaryWords);
  43. /// \brief Returns the absolute path to the input file of the test.
  44. /// The input file is expected to be located in the directory given by the
  45. /// testOptions::inputDataDir
  46. std::string getAbsPathOfInputDataFile(const llvm::StringRef filename);
  47. /// \brief Passes the HLSL input file to the DXC compiler with SPIR-V CodeGen.
  48. /// Returns the generated SPIR-V binary via 'generatedBinary' argument.
  49. /// Returns true on success, and false on failure. Writes error messages to
  50. /// errorMessages and stderr on failure.
  51. bool runCompilerWithSpirvGeneration(const llvm::StringRef inputFilePath,
  52. const llvm::StringRef entryPoint,
  53. const llvm::StringRef targetProfile,
  54. const std::vector<std::string> &restArgs,
  55. std::vector<uint32_t> *generatedBinary,
  56. std::string *errorMessages);
  57. } // end namespace utils
  58. } // end namespace spirv
  59. } // end namespace clang
  60. #endif