Coverage Report

Created: 2023-03-01 07:18

/src/spirv-tools/source/instruction.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2015-2016 The Khronos Group Inc.
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
#ifndef SOURCE_INSTRUCTION_H_
16
#define SOURCE_INSTRUCTION_H_
17
18
#include <cstdint>
19
#include <vector>
20
21
#include "source/latest_version_spirv_header.h"
22
#include "spirv-tools/libspirv.h"
23
24
// Describes an instruction.
25
struct spv_instruction_t {
26
  // Normally, both opcode and extInstType contain valid data.
27
  // However, when the assembler parses !<number> as the first word in
28
  // an instruction and opcode and extInstType are invalid.
29
  spv::Op opcode;
30
  spv_ext_inst_type_t extInstType;
31
32
  // The Id of the result type, if this instruction has one.  Zero otherwise.
33
  uint32_t resultTypeId;
34
35
  // The instruction, as a sequence of 32-bit words.
36
  // For a regular instruction the opcode and word count are combined
37
  // in words[0], as described in the SPIR-V spec.
38
  // Otherwise, the first token was !<number>, and that number appears
39
  // in words[0].  Subsequent elements are the result of parsing
40
  // tokens in the alternate parsing mode as described in syntax.md.
41
  std::vector<uint32_t> words;
42
};
43
44
// Appends a word to an instruction, without checking for overflow.
45
0
inline void spvInstructionAddWord(spv_instruction_t* inst, uint32_t value) {
46
0
  inst->words.push_back(value);
47
0
}
48
49
#endif  // SOURCE_INSTRUCTION_H_