Dejan Mircevski | b6fe02f | 2016-01-07 13:44:22 -0500 | [diff] [blame] | 1 | // Copyright (c) 2015-2016 The Khronos Group Inc. |
Lei Zhang | 972788b | 2015-11-12 13:48:30 -0500 | [diff] [blame] | 2 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 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 |
Lei Zhang | 972788b | 2015-11-12 13:48:30 -0500 | [diff] [blame] | 6 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Lei Zhang | 972788b | 2015-11-12 13:48:30 -0500 | [diff] [blame] | 8 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 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. |
Lei Zhang | 972788b | 2015-11-12 13:48:30 -0500 | [diff] [blame] | 14 | |
| 15 | #include "table.h" |
| 16 | |
Lei Zhang | dc6e483 | 2016-09-21 17:16:31 -0400 | [diff] [blame] | 17 | #include <utility> |
Lei Zhang | 972788b | 2015-11-12 13:48:30 -0500 | [diff] [blame] | 18 | |
Dejan Mircevski | 3d27da4 | 2016-03-31 12:16:51 -0400 | [diff] [blame] | 19 | spv_context spvContextCreate(spv_target_env env) { |
| 20 | switch (env) { |
Dejan Mircevski | 3d27da4 | 2016-03-31 12:16:51 -0400 | [diff] [blame] | 21 | case SPV_ENV_UNIVERSAL_1_0: |
Dejan Mircevski | 3d27da4 | 2016-03-31 12:16:51 -0400 | [diff] [blame] | 22 | case SPV_ENV_VULKAN_1_0: |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 23 | case SPV_ENV_UNIVERSAL_1_1: |
Pierre Moreau | 12447d8 | 2017-11-30 00:49:23 +0100 | [diff] [blame^] | 24 | 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 Neto | c296701 | 2016-08-05 18:19:30 -0400 | [diff] [blame] | 28 | case SPV_ENV_OPENCL_2_1: |
Pierre Moreau | 12447d8 | 2017-11-30 00:49:23 +0100 | [diff] [blame^] | 29 | case SPV_ENV_OPENCL_EMBEDDED_2_1: |
David Neto | c296701 | 2016-08-05 18:19:30 -0400 | [diff] [blame] | 30 | case SPV_ENV_OPENCL_2_2: |
Pierre Moreau | 12447d8 | 2017-11-30 00:49:23 +0100 | [diff] [blame^] | 31 | case SPV_ENV_OPENCL_EMBEDDED_2_2: |
David Neto | c296701 | 2016-08-05 18:19:30 -0400 | [diff] [blame] | 32 | 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 Neto | dbc2049 | 2017-03-14 12:43:41 -0400 | [diff] [blame] | 37 | case SPV_ENV_UNIVERSAL_1_2: |
Dejan Mircevski | 3d27da4 | 2016-03-31 12:16:51 -0400 | [diff] [blame] | 38 | break; |
| 39 | default: |
| 40 | return nullptr; |
| 41 | } |
| 42 | |
Lei Zhang | 972788b | 2015-11-12 13:48:30 -0500 | [diff] [blame] | 43 | spv_opcode_table opcode_table; |
| 44 | spv_operand_table operand_table; |
| 45 | spv_ext_inst_table ext_inst_table; |
| 46 | |
Dejan Mircevski | cb3c49e | 2016-04-07 14:41:34 -0400 | [diff] [blame] | 47 | spvOpcodeTableGet(&opcode_table, env); |
| 48 | spvOperandTableGet(&operand_table, env); |
| 49 | spvExtInstTableGet(&ext_inst_table, env); |
Lei Zhang | 972788b | 2015-11-12 13:48:30 -0500 | [diff] [blame] | 50 | |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 51 | return new spv_context_t{env, opcode_table, operand_table, ext_inst_table, |
| 52 | nullptr /* a null default consumer */}; |
Lei Zhang | 972788b | 2015-11-12 13:48:30 -0500 | [diff] [blame] | 53 | } |
| 54 | |
Lei Zhang | 4f293b7 | 2016-03-21 16:36:14 -0400 | [diff] [blame] | 55 | void spvContextDestroy(spv_context context) { delete context; } |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 56 | |
David Neto | c299927 | 2017-11-22 15:18:37 -0500 | [diff] [blame] | 57 | void libspirv::SetContextMessageConsumer(spv_context context, |
| 58 | spvtools::MessageConsumer consumer) { |
Lei Zhang | 755f97f | 2016-09-02 18:06:18 -0400 | [diff] [blame] | 59 | context->consumer = std::move(consumer); |
| 60 | } |