build_module.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2016 Google Inc.
  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 SOURCE_OPT_BUILD_MODULE_H_
  15. #define SOURCE_OPT_BUILD_MODULE_H_
  16. #include <memory>
  17. #include <string>
  18. #include "source/opt/ir_context.h"
  19. #include "source/opt/module.h"
  20. #include "spirv-tools/libspirv.hpp"
  21. namespace spvtools {
  22. // Builds a Module and returns the owning IRContext from the given SPIR-V
  23. // |binary|. |size| specifies number of words in |binary|. The |binary| will be
  24. // decoded according to the given target |env|. Returns nullptr if errors occur
  25. // and sends the errors to |consumer|. When |extra_line_tracking| is true,
  26. // extra OpLine instructions are injected to better presere line numbers while
  27. // later transforms mutate the module.
  28. std::unique_ptr<opt::IRContext> BuildModule(spv_target_env env,
  29. MessageConsumer consumer,
  30. const uint32_t* binary, size_t size,
  31. bool extra_line_tracking);
  32. // Like above, with extra line tracking turned on.
  33. std::unique_ptr<opt::IRContext> BuildModule(spv_target_env env,
  34. MessageConsumer consumer,
  35. const uint32_t* binary,
  36. size_t size);
  37. // Builds a Module and returns the owning IRContext from the given
  38. // SPIR-V assembly |text|. The |text| will be encoded according to the given
  39. // target |env|. Returns nullptr if errors occur and sends the errors to
  40. // |consumer|.
  41. std::unique_ptr<opt::IRContext> BuildModule(
  42. spv_target_env env, MessageConsumer consumer, const std::string& text,
  43. uint32_t assemble_options = SpirvTools::kDefaultAssembleOption);
  44. } // namespace spvtools
  45. #endif // SOURCE_OPT_BUILD_MODULE_H_