@@ -31,16 +31,6 @@ void TmpVar::dump(std::ostream& os) const {
3131 os << " : " << v_type << " (width " ;
3232 os << v_type->calc_width_on_stack ();
3333 os << " )" ;
34- if (coord > 0 ) {
35- os << " = _" << (coord >> 8 ) << ' .' << (coord & 255 );
36- } else if (coord < 0 ) {
37- int n = (~coord >> 8 ), k = (~coord & 0xff );
38- if (k) {
39- os << " = (_" << n << " .._" << (n + k - 1 ) << " )" ;
40- } else {
41- os << " = ()" ;
42- }
43- }
4434 os << std::endl;
4535}
4636
@@ -51,7 +41,7 @@ void TmpVar::show(std::ostream& os, int omit_idx) const {
5141 return ;
5242 }
5343 }
54- os << ' _' << idx ;
44+ os << ' _' << ir_idx ;
5545}
5646
5747std::ostream& operator <<(std::ostream& os, const TmpVar& var) {
@@ -182,47 +172,6 @@ void VarDescrList::show(std::ostream& os) const {
182172 os << " ]\n " ;
183173}
184174
185- void Op::split_vars (const std::vector<TmpVar>& vars) {
186- split_var_list (left, vars);
187- split_var_list (right, vars);
188- for (auto & op : block0) {
189- op.split_vars (vars);
190- }
191- for (auto & op : block1) {
192- op.split_vars (vars);
193- }
194- }
195-
196- void Op::split_var_list (std::vector<var_idx_t >& var_list, const std::vector<TmpVar>& vars) {
197- int new_size = 0 , changes = 0 ;
198- for (var_idx_t v : var_list) {
199- int c = vars.at (v).coord ;
200- if (c < 0 ) {
201- ++changes;
202- new_size += (~c & 0xff );
203- } else {
204- ++new_size;
205- }
206- }
207- if (!changes) {
208- return ;
209- }
210- std::vector<var_idx_t > new_var_list;
211- new_var_list.reserve (new_size);
212- for (var_idx_t v : var_list) {
213- int c = vars.at (v).coord ;
214- if (c < 0 ) {
215- int n = (~c >> 8 ), k = (~c & 0xff );
216- while (k-- > 0 ) {
217- new_var_list.push_back (n++);
218- }
219- } else {
220- new_var_list.push_back (v);
221- }
222- }
223- var_list = std::move (new_var_list);
224- }
225-
226175void Op::show (std::ostream& os, const std::vector<TmpVar>& vars, std::string pfx, int mode) const {
227176 if (mode & 2 ) {
228177 os << pfx << " [" ;
@@ -444,26 +393,22 @@ void CodeBlob::print(std::ostream& os, int flags) const {
444393 os << " -------- END ---------\n\n " ;
445394}
446395
447- var_idx_t CodeBlob::create_var (TypePtr var_type, const LocalVarData* v_sym, SrcLocation location) {
448- vars.emplace_back (var_cnt, var_type, v_sym, location);
449- return var_cnt++;
450- }
451-
452- bool CodeBlob::import_params (FormalArgList&& arg_list) {
453- if (var_cnt || in_var_cnt) {
454- return false ;
455- }
456- std::vector<var_idx_t > list;
457- for (const auto & par : arg_list) {
458- TypePtr arg_type;
459- const LocalVarData* arg_sym;
460- SrcLocation arg_loc;
461- std::tie (arg_type, arg_sym, arg_loc) = par;
462- list.push_back (create_var (arg_type, arg_sym, arg_loc));
463- }
464- emplace_back (loc, Op::_Import, list);
465- in_var_cnt = var_cnt;
466- return true ;
396+ std::vector<var_idx_t > CodeBlob::create_var (TypePtr var_type, const LocalVarData* v_sym, SrcLocation loc) {
397+ std::vector<var_idx_t > ir_idx;
398+ ir_idx.reserve (var_type->calc_width_on_stack ());
399+ if (const TypeDataTensor* t_tensor = var_type->try_as <TypeDataTensor>()) {
400+ for (TypePtr item : t_tensor->items ) {
401+ std::vector<var_idx_t > nested = create_var (item, v_sym, loc);
402+ ir_idx.insert (ir_idx.end (), nested.begin (), nested.end ());
403+ }
404+ } else if (var_type != TypeDataVoid::create ()) {
405+ tolk_assert (var_type->calc_width_on_stack () == 1 );
406+ vars.emplace_back (var_cnt, var_type, v_sym, loc);
407+ ir_idx.emplace_back (var_cnt);
408+ var_cnt++;
409+ }
410+ tolk_assert (static_cast <int >(ir_idx.size ()) == var_type->calc_width_on_stack ());
411+ return ir_idx;
467412}
468413
469414} // namespace tolk
0 commit comments