Coverage Report

Created: 2025-11-16 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/spirv-tools/source/val/instruction.cpp
Line
Count
Source
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
#include "source/val/instruction.h"
16
17
#include <utility>
18
19
#include "source/binary.h"
20
#include "source/util/string_utils.h"
21
22
namespace spvtools {
23
namespace val {
24
25
Instruction::Instruction(const spv_parsed_instruction_t* inst)
26
13.0M
    : words_(inst->words, inst->words + inst->num_words),
27
13.0M
      operands_(inst->operands, inst->operands + inst->num_operands),
28
13.0M
      inst_({words_.data(), inst->num_words, inst->opcode, inst->ext_inst_type,
29
13.0M
             inst->type_id, inst->result_id, operands_.data(),
30
13.0M
             inst->num_operands}) {}
31
32
14.2M
void Instruction::RegisterUse(const Instruction* inst, uint32_t index) {
33
14.2M
  uses_.push_back(std::make_pair(inst, index));
34
14.2M
}
35
36
0
bool operator<(const Instruction& lhs, const Instruction& rhs) {
37
0
  return lhs.id() < rhs.id();
38
0
}
39
0
bool operator<(const Instruction& lhs, uint32_t rhs) { return lhs.id() < rhs; }
40
0
bool operator==(const Instruction& lhs, const Instruction& rhs) {
41
0
  return lhs.id() == rhs.id();
42
0
}
43
0
bool operator==(const Instruction& lhs, uint32_t rhs) {
44
0
  return lhs.id() == rhs;
45
0
}
46
47
template <>
48
155k
std::string Instruction::GetOperandAs<std::string>(size_t index) const {
49
155k
  const spv_parsed_operand_t& o = operands_.at(index);
50
155k
  assert(o.offset + o.num_words <= inst_.num_words);
51
155k
  return spvtools::utils::MakeString(words_.data() + o.offset, o.num_words);
52
155k
}
53
54
}  // namespace val
55
}  // namespace spvtools