blob: 02ce0d27730f5fce420e4dcc48a725f12ffa2b46 [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
Nicolas Capens348ba202021-01-03 01:49:39 -050017#include "spirv-tools/libspirv.h"
18
Ben Clayton54d16b82020-02-03 15:32:06 +000019#include <spirv/unified1/spirv.hpp>
20
21#define CONCAT(a, b) a##b
22#define CONCAT2(a, b) CONCAT(a, b)
23
24namespace {
25
26// checkForNoMissingOps() is an unused function that simply exists to try and
Ben Clayton349b1a32020-02-08 23:05:36 +000027// detect missing opcodes in "SpirvShaderInstructions.inl".
Ben Clayton54d16b82020-02-03 15:32:06 +000028// If there are missing opcodes, then some compilers will warn that not all
29// enum values are handled by the switch case below.
30constexpr 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 Clayton349b1a32020-02-08 23:05:36 +000040#include "SpirvShaderInstructions.inl"
Ben Clayton54d16b82020-02-03 15:32:06 +000041#undef DECORATE_OP
42 case spv::OpMax: return;
43 }
44}
45
46} // anonymous namespace
47
48namespace sw {
49
Nicolas Capens348ba202021-01-03 01:49:39 -050050const char *SpirvShader::OpcodeName(spv::Op op)
51{
52 return spvOpcodeString(op);
53}
54
Ben Clayton54d16b82020-02-03 15:32:06 +000055bool 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 Clayton349b1a32020-02-08 23:05:36 +000064#include "SpirvShaderInstructions.inl"
Ben Clayton54d16b82020-02-03 15:32:06 +000065#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