extract_source.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2023 Google LLC.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef INCLUDE_SPIRV_TOOLS_EXTRACT_SOURCE_HPP_
  15. #define INCLUDE_SPIRV_TOOLS_EXTRACT_SOURCE_HPP_
  16. #include <stdint.h>
  17. #include <string>
  18. #include <unordered_map>
  19. #include <vector>
  20. // Parse a SPIR-V module, and extracts all HLSL source code from it.
  21. // This function doesn't lift the SPIR-V code, but only relies on debug symbols.
  22. // This means if the compiler didn't include some files, they won't show up.
  23. //
  24. // Returns a map of <filename, source_code> extracted from it.
  25. // - `binary`: a vector containing the whole SPIR-V binary to extract source
  26. // from.
  27. // - `output`: <filename, source_code> mapping, mapping each filename
  28. // (if defined) to its code.
  29. //
  30. // Returns `true` if the extraction succeeded, `false` otherwise.
  31. // `output` value is undefined if `false` is returned.
  32. bool ExtractSourceFromModule(
  33. const std::vector<uint32_t>& binary,
  34. std::unordered_map<std::string, std::string>* output);
  35. #endif // INCLUDE_SPIRV_TOOLS_EXTRACT_SOURCE_HPP_