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