xref: /aosp_15_r20/external/swiftshader/third_party/SPIRV-Tools/source/instruction.h (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1*03ce13f7SAndroid Build Coastguard Worker // Copyright (c) 2015-2016 The Khronos Group Inc.
2*03ce13f7SAndroid Build Coastguard Worker //
3*03ce13f7SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*03ce13f7SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*03ce13f7SAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*03ce13f7SAndroid Build Coastguard Worker //
7*03ce13f7SAndroid Build Coastguard Worker //     http://www.apache.org/licenses/LICENSE-2.0
8*03ce13f7SAndroid Build Coastguard Worker //
9*03ce13f7SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*03ce13f7SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*03ce13f7SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*03ce13f7SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*03ce13f7SAndroid Build Coastguard Worker // limitations under the License.
14*03ce13f7SAndroid Build Coastguard Worker 
15*03ce13f7SAndroid Build Coastguard Worker #ifndef SOURCE_INSTRUCTION_H_
16*03ce13f7SAndroid Build Coastguard Worker #define SOURCE_INSTRUCTION_H_
17*03ce13f7SAndroid Build Coastguard Worker 
18*03ce13f7SAndroid Build Coastguard Worker #include <cstdint>
19*03ce13f7SAndroid Build Coastguard Worker #include <vector>
20*03ce13f7SAndroid Build Coastguard Worker 
21*03ce13f7SAndroid Build Coastguard Worker #include "source/latest_version_spirv_header.h"
22*03ce13f7SAndroid Build Coastguard Worker #include "spirv-tools/libspirv.h"
23*03ce13f7SAndroid Build Coastguard Worker 
24*03ce13f7SAndroid Build Coastguard Worker // Describes an instruction.
25*03ce13f7SAndroid Build Coastguard Worker struct spv_instruction_t {
26*03ce13f7SAndroid Build Coastguard Worker   // Normally, both opcode and extInstType contain valid data.
27*03ce13f7SAndroid Build Coastguard Worker   // However, when the assembler parses !<number> as the first word in
28*03ce13f7SAndroid Build Coastguard Worker   // an instruction and opcode and extInstType are invalid.
29*03ce13f7SAndroid Build Coastguard Worker   spv::Op opcode;
30*03ce13f7SAndroid Build Coastguard Worker   spv_ext_inst_type_t extInstType;
31*03ce13f7SAndroid Build Coastguard Worker 
32*03ce13f7SAndroid Build Coastguard Worker   // The Id of the result type, if this instruction has one.  Zero otherwise.
33*03ce13f7SAndroid Build Coastguard Worker   uint32_t resultTypeId;
34*03ce13f7SAndroid Build Coastguard Worker 
35*03ce13f7SAndroid Build Coastguard Worker   // The instruction, as a sequence of 32-bit words.
36*03ce13f7SAndroid Build Coastguard Worker   // For a regular instruction the opcode and word count are combined
37*03ce13f7SAndroid Build Coastguard Worker   // in words[0], as described in the SPIR-V spec.
38*03ce13f7SAndroid Build Coastguard Worker   // Otherwise, the first token was !<number>, and that number appears
39*03ce13f7SAndroid Build Coastguard Worker   // in words[0].  Subsequent elements are the result of parsing
40*03ce13f7SAndroid Build Coastguard Worker   // tokens in the alternate parsing mode as described in syntax.md.
41*03ce13f7SAndroid Build Coastguard Worker   std::vector<uint32_t> words;
42*03ce13f7SAndroid Build Coastguard Worker };
43*03ce13f7SAndroid Build Coastguard Worker 
44*03ce13f7SAndroid Build Coastguard Worker // Appends a word to an instruction, without checking for overflow.
spvInstructionAddWord(spv_instruction_t * inst,uint32_t value)45*03ce13f7SAndroid Build Coastguard Worker inline void spvInstructionAddWord(spv_instruction_t* inst, uint32_t value) {
46*03ce13f7SAndroid Build Coastguard Worker   inst->words.push_back(value);
47*03ce13f7SAndroid Build Coastguard Worker }
48*03ce13f7SAndroid Build Coastguard Worker 
49*03ce13f7SAndroid Build Coastguard Worker #endif  // SOURCE_INSTRUCTION_H_
50