blob: 822cefebd7b0926c8e3ab444c9ab255fffa61a40 [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
dan sinclaireda2cfb2018-08-03 15:06:09 -040015#include "source/table.h"
Lei Zhang972788b2015-11-12 13:48:30 -050016
Lei Zhangdc6e4832016-09-21 17:16:31 -040017#include <utility>
Lei Zhang972788b2015-11-12 13:48:30 -050018
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:
Pierre Moreau12447d82017-11-30 00:49:23 +010024 case SPV_ENV_OPENCL_1_2:
25 case SPV_ENV_OPENCL_EMBEDDED_1_2:
26 case SPV_ENV_OPENCL_2_0:
27 case SPV_ENV_OPENCL_EMBEDDED_2_0:
David Netoc2967012016-08-05 18:19:30 -040028 case SPV_ENV_OPENCL_2_1:
Pierre Moreau12447d82017-11-30 00:49:23 +010029 case SPV_ENV_OPENCL_EMBEDDED_2_1:
David Netoc2967012016-08-05 18:19:30 -040030 case SPV_ENV_OPENCL_2_2:
Pierre Moreau12447d82017-11-30 00:49:23 +010031 case SPV_ENV_OPENCL_EMBEDDED_2_2:
David Netoc2967012016-08-05 18:19:30 -040032 case SPV_ENV_OPENGL_4_0:
33 case SPV_ENV_OPENGL_4_1:
34 case SPV_ENV_OPENGL_4_2:
35 case SPV_ENV_OPENGL_4_3:
36 case SPV_ENV_OPENGL_4_5:
David Netodbc20492017-03-14 12:43:41 -040037 case SPV_ENV_UNIVERSAL_1_2:
David Neto00fa3932018-02-09 14:29:02 -050038 case SPV_ENV_UNIVERSAL_1_3:
39 case SPV_ENV_VULKAN_1_1:
David Neto63f57d92019-05-07 12:27:18 -040040 case SPV_ENV_VULKAN_1_1_SPIRV_1_4:
David Neto63f57d92019-05-07 12:27:18 -040041 case SPV_ENV_UNIVERSAL_1_4:
alan-baker5a48c0d2019-09-13 14:59:02 -040042 case SPV_ENV_UNIVERSAL_1_5:
David Netod46a1b02019-08-28 18:49:33 -040043 case SPV_ENV_VULKAN_1_2:
alan-baker7d768812021-12-15 14:38:28 -050044 case SPV_ENV_UNIVERSAL_1_6:
alan-baker6938af72022-01-25 10:36:08 -050045 case SPV_ENV_VULKAN_1_3:
Dejan Mircevski3d27da42016-03-31 12:16:51 -040046 break;
47 default:
48 return nullptr;
49 }
50
Lei Zhang972788b2015-11-12 13:48:30 -050051 spv_opcode_table opcode_table;
52 spv_operand_table operand_table;
53 spv_ext_inst_table ext_inst_table;
54
Dejan Mircevskicb3c49e2016-04-07 14:41:34 -040055 spvOpcodeTableGet(&opcode_table, env);
56 spvOperandTableGet(&operand_table, env);
57 spvExtInstTableGet(&ext_inst_table, env);
Lei Zhang972788b2015-11-12 13:48:30 -050058
Lei Zhang755f97f2016-09-02 18:06:18 -040059 return new spv_context_t{env, opcode_table, operand_table, ext_inst_table,
60 nullptr /* a null default consumer */};
Lei Zhang972788b2015-11-12 13:48:30 -050061}
62
Lei Zhang4f293b72016-03-21 16:36:14 -040063void spvContextDestroy(spv_context context) { delete context; }
Lei Zhang755f97f2016-09-02 18:06:18 -040064
dan sinclair3dad1cd2018-07-07 09:38:00 -040065void spvtools::SetContextMessageConsumer(spv_context context,
David Netoc2999272017-11-22 15:18:37 -050066 spvtools::MessageConsumer consumer) {
Lei Zhang755f97f2016-09-02 18:06:18 -040067 context->consumer = std::move(consumer);
68}