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
25 // detect missing opcodes in "SpirvShaderInstructions.inl".
26 // If there are missing opcodes, then some compilers will warn that not all
27 // enum values are handled by the switch case below.
checkForNoMissingOps(spv::Op op)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;
38 #include "SpirvShaderInstructions.inl"
39 #undef DECORATE_OP
40 case spv::OpMax: return;
41 }
42 }
43
44 } // anonymous namespace
45
46 namespace sw {
47
IsStatement(spv::Op op)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)
57 #include "SpirvShaderInstructions.inl"
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