| 155 | void module::set_bypass(bool b) { impl->bypass = b; } |
| 156 | |
| 157 | void module::assign(const module& m) |
| 158 | { |
| 159 | // copy the impl |
| 160 | if(not impl) |
| 161 | impl = std::make_unique<module_impl>(); |
| 162 | *impl = *m.impl; |
| 163 | |
| 164 | // clear instructions |
| 165 | if(not impl->instructions.empty()) |
| 166 | { |
| 167 | impl->clear(); |
| 168 | } |
| 169 | |
| 170 | std::unordered_map<instruction_ref, instruction_ref> ins_map; |
| 171 | for(auto ins : iterator_for(m)) |
| 172 | { |
| 173 | instruction_ref copy_ins{}; |
| 174 | if(ins->name() == "@literal") |
| 175 | { |
| 176 | auto l = ins->get_literal(); |
| 177 | copy_ins = impl->insert(impl->instructions.end(), instruction{l}); |
| 178 | } |
| 179 | else if(ins->name() == "@param") |
| 180 | { |
| 181 | auto&& name = any_cast<builtin::param>(ins->get_operator()).parameter; |
| 182 | auto order = any_cast<builtin::param>(ins->get_operator()).order; |
| 183 | auto s = ins->get_shape(); |
| 184 | copy_ins = impl->insert(impl->instructions.end(), |
| 185 | {builtin::param{name, order}, std::move(s), {}}); |
| 186 | impl->nparams++; |
| 187 | } |
| 188 | else if(ins->name() == "@outline") |
| 189 | { |
| 190 | auto s = ins->get_shape(); |
| 191 | copy_ins = impl->insert(impl->instructions.end(), {builtin::outline{s}, s, {}}); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | // if there are sub_module inputs, need to make a copy of the submodule |
| 196 | auto module_args = ins->module_inputs(); |
| 197 | // retrieve its mapped input |
| 198 | auto inputs = ins->inputs(); |
| 199 | std::vector<instruction_ref> copy_inputs(inputs.size()); |
| 200 | std::transform(inputs.begin(), inputs.end(), copy_inputs.begin(), [&](auto i) { |
| 201 | return contains(ins_map, i) ? ins_map[i] : i; |
| 202 | }); |
| 203 | if(ins->name() == "@return") |
| 204 | { |
| 205 | copy_ins = add_return(copy_inputs); |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | copy_ins = add_instruction(ins->get_operator(), copy_inputs, module_args); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | ins_map[ins] = copy_ins; |
| 214 | } |