blob: 18cced148a37afc993797b1bee40476ea082d4bf [file] [log] [blame]
Ben Clayton54d16b82020-02-03 15:32:06 +00001// 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
22namespace {
23
24// checkForNoMissingOps() is an unused function that simply exists to try and
Ben Clayton349b1a32020-02-08 23:05:36 +000025// detect missing opcodes in "SpirvShaderInstructions.inl".
Ben Clayton54d16b82020-02-03 15:32:06 +000026// If there are missing opcodes, then some compilers will warn that not all
27// enum values are handled by the switch case below.
28constexpr 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 Clayton349b1a32020-02-08 23:05:36 +000038#include "SpirvShaderInstructions.inl"
Ben Clayton54d16b82020-02-03 15:32:06 +000039#undef DECORATE_OP
40 case spv::OpMax: return;
41 }
42}
43
44} // anonymous namespace
45
46namespace sw {
47
48bool 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 Clayton349b1a32020-02-08 23:05:36 +000057#include "SpirvShaderInstructions.inl"
Ben Clayton54d16b82020-02-03 15:32:06 +000058#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