• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-tools/libspirv.h"
18 
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
27 // detect missing opcodes in "SpirvShaderInstructions.inl".
28 // If there are missing opcodes, then some compilers will warn that not all
29 // enum values are handled by the switch case below.
checkForNoMissingOps(spv::Op op)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;
40 #include "SpirvShaderInstructions.inl"
41 #undef DECORATE_OP
42 		case spv::OpMax: return;
43 	}
44 }
45 
46 }  // anonymous namespace
47 
48 namespace sw {
49 
OpcodeName(spv::Op op)50 const char *SpirvShader::OpcodeName(spv::Op op)
51 {
52 	return spvOpcodeString(op);
53 }
54 
IsStatement(spv::Op op)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)
64 #include "SpirvShaderInstructions.inl"
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