Ben Clayton | 54d16b8 | 2020-02-03 15:32:06 +0000 | [diff] [blame] | 1 | // Copyright 2020 The SwiftShader Authors. All Rights Reserved. |
| 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 | #include "SpirvShader.hpp" |
| 16 | |
Nicolas Capens | 348ba20 | 2021-01-03 01:49:39 -0500 | [diff] [blame] | 17 | #include "spirv-tools/libspirv.h" |
| 18 | |
Ben Clayton | 54d16b8 | 2020-02-03 15:32:06 +0000 | [diff] [blame] | 19 | #include <spirv/unified1/spirv.hpp> |
| 20 | |
| 21 | #define CONCAT(a, b) a##b |
| 22 | #define CONCAT2(a, b) CONCAT(a, b) |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | // checkForNoMissingOps() is an unused function that simply exists to try and |
Ben Clayton | 349b1a3 | 2020-02-08 23:05:36 +0000 | [diff] [blame] | 27 | // detect missing opcodes in "SpirvShaderInstructions.inl". |
Ben Clayton | 54d16b8 | 2020-02-03 15:32:06 +0000 | [diff] [blame] | 28 | // If there are missing opcodes, then some compilers will warn that not all |
| 29 | // enum values are handled by the switch case below. |
| 30 | constexpr void checkForNoMissingOps(spv::Op op) |
| 31 | { |
| 32 | // self-reference to avoid unused-function warnings. |
| 33 | (void)&checkForNoMissingOps; |
| 34 | |
| 35 | switch(op) |
| 36 | { |
| 37 | #define DECORATE_OP(isStatement, op) \ |
| 38 | case spv::op: \ |
| 39 | return; |
Ben Clayton | 349b1a3 | 2020-02-08 23:05:36 +0000 | [diff] [blame] | 40 | #include "SpirvShaderInstructions.inl" |
Ben Clayton | 54d16b8 | 2020-02-03 15:32:06 +0000 | [diff] [blame] | 41 | #undef DECORATE_OP |
| 42 | case spv::OpMax: return; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | } // anonymous namespace |
| 47 | |
| 48 | namespace sw { |
| 49 | |
Nicolas Capens | 348ba20 | 2021-01-03 01:49:39 -0500 | [diff] [blame] | 50 | const char *SpirvShader::OpcodeName(spv::Op op) |
| 51 | { |
| 52 | return spvOpcodeString(op); |
| 53 | } |
| 54 | |
Ben Clayton | 54d16b8 | 2020-02-03 15:32:06 +0000 | [diff] [blame] | 55 | bool SpirvShader::IsStatement(spv::Op op) |
| 56 | { |
| 57 | switch(op) |
| 58 | { |
| 59 | #define IS_STATEMENT_T(op) case spv::op: |
| 60 | #define IS_STATEMENT_F(op) |
| 61 | #define DECORATE_OP(isStatement, op) \ |
| 62 | CONCAT2(IS_STATEMENT_, isStatement) \ |
| 63 | (op) |
Ben Clayton | 349b1a3 | 2020-02-08 23:05:36 +0000 | [diff] [blame] | 64 | #include "SpirvShaderInstructions.inl" |
Ben Clayton | 54d16b8 | 2020-02-03 15:32:06 +0000 | [diff] [blame] | 65 | #undef IS_STATEMENT_T |
| 66 | #undef IS_STATEMENT_F |
| 67 | #undef DECORATE_OP |
| 68 | return true; |
| 69 | |
| 70 | default: |
| 71 | return false; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | } // namespace sw |