blob: 24ab52056ff3e8d9962a762bac276390b29163d8 [file] [log] [blame]
Dejan Mircevskib6fe02f2016-01-07 13:44:22 -05001// Copyright (c) 2015-2016 The Khronos Group Inc.
Lei Zhang972788b2015-11-12 13:48:30 -05002//
David Neto9fc86582016-09-01 15:33:59 -04003// 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
Lei Zhang972788b2015-11-12 13:48:30 -05006//
David Neto9fc86582016-09-01 15:33:59 -04007// http://www.apache.org/licenses/LICENSE-2.0
Lei Zhang972788b2015-11-12 13:48:30 -05008//
David Neto9fc86582016-09-01 15:33:59 -04009// 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.
Lei Zhang972788b2015-11-12 13:48:30 -050014
15#include "table.h"
16
17#include <cstdlib>
18
Dejan Mircevski3d27da42016-03-31 12:16:51 -040019spv_context spvContextCreate(spv_target_env env) {
20 switch (env) {
Dejan Mircevski3d27da42016-03-31 12:16:51 -040021 case SPV_ENV_UNIVERSAL_1_0:
Dejan Mircevski3d27da42016-03-31 12:16:51 -040022 case SPV_ENV_VULKAN_1_0:
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -040023 case SPV_ENV_UNIVERSAL_1_1:
David Netoc2967012016-08-05 18:19:30 -040024 case SPV_ENV_OPENCL_2_1:
25 case SPV_ENV_OPENCL_2_2:
26 case SPV_ENV_OPENGL_4_0:
27 case SPV_ENV_OPENGL_4_1:
28 case SPV_ENV_OPENGL_4_2:
29 case SPV_ENV_OPENGL_4_3:
30 case SPV_ENV_OPENGL_4_5:
Dejan Mircevski3d27da42016-03-31 12:16:51 -040031 break;
32 default:
33 return nullptr;
34 }
35
Lei Zhang972788b2015-11-12 13:48:30 -050036 spv_opcode_table opcode_table;
37 spv_operand_table operand_table;
38 spv_ext_inst_table ext_inst_table;
39
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -040040 spvOpcodeTableGet(&opcode_table, env);
41 spvOperandTableGet(&operand_table, env);
42 spvExtInstTableGet(&ext_inst_table, env);
Lei Zhang972788b2015-11-12 13:48:30 -050043
Lei Zhang755f97f2016-09-02 18:06:18 -040044 return new spv_context_t{env, opcode_table, operand_table, ext_inst_table,
45 nullptr /* a null default consumer */};
Lei Zhang972788b2015-11-12 13:48:30 -050046}
47
Lei Zhang4f293b72016-03-21 16:36:14 -040048void spvContextDestroy(spv_context context) { delete context; }
Lei Zhang755f97f2016-09-02 18:06:18 -040049
50void SetContextMessageConsumer(spv_context context,
51 spvtools::MessageConsumer consumer) {
52 context->consumer = std::move(consumer);
53}