/src/spirv-tools/source/val/validate_debug.cpp
Line | Count | Source |
1 | | // Copyright (c) 2018 Google LLC. |
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/spirv_target_env.h" |
16 | | #include "source/val/instruction.h" |
17 | | #include "source/val/validate.h" |
18 | | #include "source/val/validation_state.h" |
19 | | |
20 | | namespace spvtools { |
21 | | namespace val { |
22 | | namespace { |
23 | | |
24 | 9.77k | spv_result_t ValidateMemberName(ValidationState_t& _, const Instruction* inst) { |
25 | 9.77k | const auto type_id = inst->GetOperandAs<uint32_t>(0); |
26 | 9.77k | const auto type = _.FindDef(type_id); |
27 | 9.77k | if (!type || spv::Op::OpTypeStruct != type->opcode()) { |
28 | 16 | return _.diag(SPV_ERROR_INVALID_ID, inst) |
29 | 16 | << "OpMemberName Type <id> " << _.getIdName(type_id) |
30 | 16 | << " is not a struct type."; |
31 | 16 | } |
32 | 9.76k | const auto member_id = inst->GetOperandAs<uint32_t>(1); |
33 | 9.76k | const auto member_count = (uint32_t)(type->words().size() - 2); |
34 | 9.76k | if (member_count <= member_id) { |
35 | 22 | return _.diag(SPV_ERROR_INVALID_ID, inst) |
36 | 22 | << "OpMemberName Member <id> " << _.getIdName(member_id) |
37 | 22 | << " index is larger than Type <id> " << _.getIdName(type->id()) |
38 | 22 | << "s member count."; |
39 | 22 | } |
40 | 9.74k | return SPV_SUCCESS; |
41 | 9.76k | } |
42 | | |
43 | 347 | spv_result_t ValidateLine(ValidationState_t& _, const Instruction* inst) { |
44 | 347 | const auto file_id = inst->GetOperandAs<uint32_t>(0); |
45 | 347 | const auto file = _.FindDef(file_id); |
46 | 347 | if (!file || spv::Op::OpString != file->opcode()) { |
47 | 30 | return _.diag(SPV_ERROR_INVALID_ID, inst) |
48 | 30 | << "OpLine Target <id> " << _.getIdName(file_id) |
49 | 30 | << " is not an OpString."; |
50 | 30 | } |
51 | 317 | return SPV_SUCCESS; |
52 | 347 | } |
53 | | |
54 | | } // namespace |
55 | | |
56 | 13.5M | spv_result_t DebugPass(ValidationState_t& _, const Instruction* inst) { |
57 | 13.5M | switch (inst->opcode()) { |
58 | 9.77k | case spv::Op::OpMemberName: |
59 | 9.77k | if (auto error = ValidateMemberName(_, inst)) return error; |
60 | 9.74k | break; |
61 | 9.74k | case spv::Op::OpLine: |
62 | 347 | if (auto error = ValidateLine(_, inst)) return error; |
63 | 317 | break; |
64 | 13.5M | default: |
65 | 13.5M | break; |
66 | 13.5M | } |
67 | | |
68 | 13.5M | return SPV_SUCCESS; |
69 | 13.5M | } |
70 | | |
71 | | } // namespace val |
72 | | } // namespace spvtools |