Blender V4.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
6
8
10{
11 DestructInstruction &instruction = procedure_->new_destruct_instruction();
12 instruction.set_variable(&variable);
13 this->link_to_cursors(&instruction);
14 cursors_ = {InstructionCursor{instruction}};
15}
16
18{
19 for (Variable *variable : variables) {
20 this->add_destruct(*variable);
21 }
22}
23
25{
26 ReturnInstruction &instruction = procedure_->new_return_instruction();
27 this->link_to_cursors(&instruction);
28 cursors_ = {};
29 return instruction;
30}
31
33{
34 CallInstruction &instruction = procedure_->new_call_instruction(fn);
35 this->link_to_cursors(&instruction);
36 cursors_ = {InstructionCursor{instruction}};
37 return instruction;
38}
39
41 Span<Variable *> param_variables)
42{
43 CallInstruction &instruction = this->add_call_with_no_variables(fn);
44 instruction.set_params(param_variables);
45 return instruction;
46}
47
49 Span<Variable *> input_and_mutable_variables)
50{
51 Vector<Variable *> output_variables;
52 CallInstruction &instruction = this->add_call_with_no_variables(fn);
53 for (const int param_index : fn.param_indices()) {
54 const ParamType param_type = fn.param_type(param_index);
55 switch (param_type.interface_type()) {
57 case ParamType::Mutable: {
58 Variable *variable = input_and_mutable_variables.first();
59 instruction.set_param_variable(param_index, variable);
60 input_and_mutable_variables = input_and_mutable_variables.drop_front(1);
61 break;
62 }
63 case ParamType::Output: {
64 Variable &variable = procedure_->new_variable(param_type.data_type(),
65 fn.param_name(param_index));
66 instruction.set_param_variable(param_index, &variable);
67 output_variables.append(&variable);
68 break;
69 }
70 }
71 }
72 /* All passed in variables should have been dropped in the loop above. */
73 BLI_assert(input_and_mutable_variables.is_empty());
74 return output_variables;
75}
76
78{
79 BranchInstruction &instruction = procedure_->new_branch_instruction();
80 instruction.set_condition(&condition);
81 this->link_to_cursors(&instruction);
82 /* Clear cursors because this builder ends here. */
83 cursors_.clear();
84
85 Branch branch{*procedure_, *procedure_};
86 branch.branch_true.set_cursor(InstructionCursor{instruction, true});
87 branch.branch_false.set_cursor(InstructionCursor{instruction, false});
88 return branch;
89}
90
92{
93 DummyInstruction &loop_begin = procedure_->new_dummy_instruction();
94 DummyInstruction &loop_end = procedure_->new_dummy_instruction();
95 this->link_to_cursors(&loop_begin);
96 cursors_ = {InstructionCursor{loop_begin}};
97
98 Loop loop;
99 loop.begin = &loop_begin;
100 loop.end = &loop_end;
101
102 return loop;
103}
104
106{
107 this->link_to_cursors(loop.begin);
108 /* Clear cursors because this builder ends here. */
109 cursors_.clear();
110}
111
113{
114 this->link_to_cursors(loop.end);
115 /* Clear cursors because this builder ends here. */
116 cursors_.clear();
117}
118
119} // namespace blender::fn::multi_function
#define BLI_assert(a)
Definition BLI_assert.h:50
constexpr Span drop_front(int64_t n) const
Definition BLI_span.hh:172
constexpr const T & first() const
Definition BLI_span.hh:316
constexpr bool is_empty() const
Definition BLI_span.hh:261
void append(const T &value)
void set_param_variable(int param_index, Variable *variable)
ParamType param_type(int param_index) const
StringRefNull param_name(int param_index) const
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)
CallInstruction & new_call_instruction(const MultiFunction &fn)
Variable & new_variable(DataType data_type, std::string name="")