1 // Copyright 2020 The Tint Authors.
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 "src/writer/spirv/function.h"
16
17 namespace tint {
18 namespace writer {
19 namespace spirv {
20
Function()21 Function::Function()
22 : declaration_(Instruction{spv::Op::OpNop, {}}),
23 label_op_(Operand::Int(0)) {}
24
Function(const Instruction & declaration,const Operand & label_op,const InstructionList & params)25 Function::Function(const Instruction& declaration,
26 const Operand& label_op,
27 const InstructionList& params)
28 : declaration_(declaration), label_op_(label_op), params_(params) {}
29
30 Function::Function(const Function& other) = default;
31
32 Function::~Function() = default;
33
iterate(std::function<void (const Instruction &)> cb) const34 void Function::iterate(std::function<void(const Instruction&)> cb) const {
35 cb(declaration_);
36
37 for (const auto& param : params_) {
38 cb(param);
39 }
40
41 cb(Instruction{spv::Op::OpLabel, {label_op_}});
42
43 for (const auto& var : vars_) {
44 cb(var);
45 }
46 for (const auto& inst : instructions_) {
47 cb(inst);
48 }
49
50 cb(Instruction{spv::Op::OpFunctionEnd, {}});
51 }
52
53 } // namespace spirv
54 } // namespace writer
55 } // namespace tint
56