Blender V5.3
multi_function_procedure_builder.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
12
14{
15 DestructInstruction &instruction = procedure_->new_destruct_instruction();
16 instruction.set_variable(&variable);
17 this->link_to_cursors(&instruction);
18 cursors_ = {InstructionCursor{instruction}};
19}
20
22{
23 for (Variable *variable : variables) {
24 this->add_destruct(*variable);
25 }
26}
27
29{
30 ReturnInstruction &instruction = procedure_->new_return_instruction();
31 this->link_to_cursors(&instruction);
32 cursors_ = {};
33 return instruction;
34}
35
37{
38 CallInstruction &instruction = procedure_->new_call_instruction(fn);
39 this->link_to_cursors(&instruction);
40 cursors_ = {InstructionCursor{instruction}};
41 return instruction;
42}
43
45 Span<Variable *> param_variables)
46{
47 CallInstruction &instruction = this->add_call_with_no_variables(fn);
48 instruction.set_params(param_variables);
49 return instruction;
50}
51
53 Span<Variable *> input_and_mutable_variables)
54{
55 Vector<Variable *> output_variables;
56 CallInstruction &instruction = this->add_call_with_no_variables(fn);
57 for (const int param_index : fn.param_indices()) {
58 const ParamType param_type = fn.param_type(param_index);
59 switch (param_type.interface_type()) {
61 case ParamType::Mutable: {
62 Variable *variable = input_and_mutable_variables.first();
63 instruction.set_param_variable(param_index, variable);
64 input_and_mutable_variables = input_and_mutable_variables.drop_front(1);
65 break;
66 }
67 case ParamType::Output: {
68 Variable &variable = procedure_->new_variable(param_type.data_type(),
69 fn.param_name(param_index));
70 instruction.set_param_variable(param_index, &variable);
71 output_variables.append(&variable);
72 break;
73 }
74 }
75 }
76 /* All passed in variables should have been dropped in the loop above. */
77 BLI_assert(input_and_mutable_variables.is_empty());
78 return output_variables;
79}
80
82{
83 BranchInstruction &instruction = procedure_->new_branch_instruction();
84 instruction.set_condition(&condition);
85 this->link_to_cursors(&instruction);
86 /* Clear cursors because this builder ends here. */
87 cursors_.clear();
88
89 Branch branch{*procedure_, *procedure_};
90 branch.branch_true.set_cursor(InstructionCursor{instruction, true});
91 branch.branch_false.set_cursor(InstructionCursor{instruction, false});
92 return branch;
93}
94
96{
97 DummyInstruction &loop_begin = procedure_->new_dummy_instruction();
98 DummyInstruction &loop_end = procedure_->new_dummy_instruction();
99 this->link_to_cursors(&loop_begin);
100 cursors_ = {InstructionCursor{loop_begin}};
101
102 Loop loop;
103 loop.begin = &loop_begin;
104 loop.end = &loop_end;
105
106 return loop;
107}
108
110{
111 this->link_to_cursors(loop.begin);
112 /* Clear cursors because this builder ends here. */
113 cursors_.clear();
114}
115
117{
118 this->link_to_cursors(loop.end);
119 /* Clear cursors because this builder ends here. */
120 cursors_.clear();
121}
122
123} // namespace blender::fn::multi_function
constexpr Span drop_front(int64_t n) const
Definition BLI_span.hh:175
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr bool is_empty() const
Definition BLI_span.hh:264
void append(const T &value)
void set_param_variable(int param_index, Variable *variable)
Vector< Variable * > add_call(const MultiFunction &fn, Span< Variable * > input_and_mutable_variables={})
CallInstruction & add_call_with_no_variables(const MultiFunction &fn)
CallInstruction & add_call_with_all_variables(const MultiFunction &fn, Span< Variable * > param_variables)
#define condition(cond)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)