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