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
25namespace 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|.
31std::unique_ptr<opt::IRContext> BuildModule(spv_target_env env,
32 MessageConsumer consumer,
33 const uint32_t* binary,
34 size_t size);
35
36// Builds an Module and returns the owning IRContext from the given
37// SPIR-V assembly |text|. The |text| will be encoded according to the given
38// target |env|. Returns nullptr if errors occur and sends the errors to
39// |consumer|.
40std::unique_ptr<opt::IRContext> BuildModule(
41 spv_target_env env, MessageConsumer consumer, const std::string& text,
42 uint32_t assemble_options = SpirvTools::kDefaultAssembleOption);
43
44} // namespace spvtools
45
46#endif // SOURCE_OPT_BUILD_MODULE_H_
47